Skip to content

Implement 'All On' and 'All Off' buttons#12

Merged
kurotu merged 1 commit intokurotu:masterfrom
aurycat:all-power-buttons
Jun 28, 2025
Merged

Implement 'All On' and 'All Off' buttons#12
kurotu merged 1 commit intokurotu:masterfrom
aurycat:all-power-buttons

Conversation

@aurycat
Copy link
Copy Markdown
Contributor

@aurycat aurycat commented Jun 21, 2025

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_AllOff and Shell_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!

@kurotu
Copy link
Copy Markdown
Owner

kurotu commented Jun 21, 2025

Much appreciated! I'll take a look.

The workflow is failing, but it's not from your changes.

@aurycat
Copy link
Copy Markdown
Contributor Author

aurycat commented Jun 21, 2025

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 upload-artifact and download-artifact thingos from v2 to v4 and everything seemed to work fine. I'm not that familiar with GitHub workflow tho ^^'

@kurotu
Copy link
Copy Markdown
Owner

kurotu commented Jun 28, 2025

Sorry for late. Functionality looks good. I'll adjust labels and layouts later.

@kurotu kurotu merged commit 23bc1ac into kurotu:master Jun 28, 2025
1 of 2 checks passed
@aurycat
Copy link
Copy Markdown
Contributor Author

aurycat commented Jun 28, 2025

(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 PowerAllCommandParameter instead of manually adding/removing lighthouses from the object is nice. Like I said, I'm not very familiar with WPF, so I didn't know that was an option. Plus not having the other PowerOnCommon/SleepCommand/StandbyCommand return Tasks made waiting for them to finish harder, and I was trying to avoid modifying your existing code! But it looks like you changed that in your version, which is helpful.

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.

@aurycat aurycat deleted the all-power-buttons branch June 28, 2025 21:32
@kurotu
Copy link
Copy Markdown
Owner

kurotu commented Jun 29, 2025

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.
Possibly it would be good if we made an togglable option for the simultaneous way.

@aurycat
Copy link
Copy Markdown
Contributor Author

aurycat commented Jul 5, 2025

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants