Implement 'All On' and 'All Off' buttons#12
Conversation
|
Much appreciated! I'll take a look. The workflow is failing, but it's not from your changes. |
Yeah I tested out running the workflows in my fork, and I found I just needed to update the |
|
Sorry for late. Functionality looks good. I'll adjust labels and layouts later. |
|
(Oops. Reposting this comment from the correct account!) Clever improvements to the power-all code after merging! Binding the device list from the viewmodel to the execute One thing I intended that was lost in your changes is for all the basestations to power on and off simultaneously. It only saves a few seconds, but I just thought it was very satisfying to have them all power on or off at the exact same time 😄 With your other improvements, it looks like it would be pretty trivial to add that behavior back though, if you want! Something like this: diff --git a/OVRLighthouseManager/Helpers/LighthouseCommands.cs b/OVRLighthouseManager/Helpers/LighthouseCommands.cs
index e9ed81f..b38f8aa 100644
--- a/OVRLighthouseManager/Helpers/LighthouseCommands.cs
+++ b/OVRLighthouseManager/Helpers/LighthouseCommands.cs
@@ -220,30 +220,33 @@ public class PowerAllCommand : AsyncCommandBase
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
var settings = App.GetService<ILighthouseSettingsService>();
+ var tasks = new List<Task>();
foreach (var lighthouse in param.Lighthouses.Where(l => l.IsManaged))
{
switch (Operation)
{
case PowerAllCommandOperation.PowerOn:
var powerOn = new PowerOnCommand();
- await powerOn.ExecuteAsync(lighthouse);
+ tasks.Add(powerOn.ExecuteAsync(lighthouse));
break;
case PowerAllCommandOperation.PowerDown:
if (settings.PowerDownMode == PowerDownMode.Sleep || lighthouse.Lighthouse.Version == LighthouseVersion.V1)
{
var sleep = new SleepCommand();
- await sleep.ExecuteAsync(lighthouse);
+ tasks.Add(sleep.ExecuteAsync(lighthouse));
}
else
{
var standby = new StandbyCommand();
- await standby.ExecuteAsync(lighthouse);
+ tasks.Add(standby.ExecuteAsync(lighthouse));
}
break;
default:
continue;
}
}
+
+ await Task.WhenAll(tasks);
}
finally
{Or use Linq to map from Lighthouses to Tasks, instead of making a List. |
|
Thanks a lot. However some people had instable behavior with the simultaneous way in past versions, so I changed to use await for each command. |
Ohh, that's fair! |
Sometimes it's convenient to turn all (managed) base stations on or off with a single button press. E.g. occasionally my power flickers and causes all base stations to turn on, and I want to turn them all back off easily.
I added "All On" and "All Off" buttons. When the "All On" button is clicked, it sends the power-on command to all managed base stations. When the "All Off" button is clicked, it sends the selected power-down mode command (either standby or sleep) to all managed base stations. After clicking a button, both buttons are disabled with loading spinners until the commands all complete.
I tested it on my own 2.0 base stations, and my friend's 1.0 base stations. I tested that the new buttons don't affect unmanaged base stations.
There are new strings in the text resources,
Shell_Main_PowerAll_AllOffandShell_Main_PowerAll_AllOn, but I didn't add anything for the Japanese translation since I don't know Japanese. Feel free to add that in, or tell me what it should say and I can add it.Last thing -- I'm not very familiar with WPF (or the MVVM paradigm of programming in general), so apologizes if I did anything silly. I tried to match my style of coding to how your code is. Let me know if you have issues with my code and I can try to fix it!