Windows-Auto-Night-Mode icon indicating copy to clipboard operation
Windows-Auto-Night-Mode copied to clipboard

Allow executing custom scripts before theme switch

Open aaronliu0130 opened this issue 2 years ago • 3 comments

Describe the enhancement or feature you'd like Allow some sort of setting, either in the scripts spec or the UI, to finish executing custom scripts before theme change

Describe alternatives you've considered Disable theme switching and turn that into a script with a delay

Additional context I'm trying to use AutoDarkMode in conjunction with an .msstyles theme (specifically, Rectify11's). Currently AutoDarkMode seems like it toggles both the .msstyles theme (through my script) and the normal theme at once, causing long delays and as if no .msstyles change at all has occurred.

aaronliu0130 avatar Oct 16 '23 19:10 aaronliu0130

The default option of custom scripts actually is to run before a theme switch occurs.

The script component uses the default hook position, which is PostSync

You can see that here: https://github.com/AutoDarkMode/Windows-Auto-Night-Mode/blob/cf7a0fefd8b51edc8d4868acd3abe06880113362/AutoDarkModeSvc/Core/ThemeManager.cs#L259

The issues you're most likely running into are probably these two:

  1. Scripts in ADM run asynchronously. They will be launched, but ADM will not wait for them to finish execution before proceeding. So if you have a long running operation, you will experience the behavior your described.

  2. Applying .msstyles is also asynchronous. The method that Rectify11 is using is most likely also non-blocking, resulting in the script to return even though the underlying switch is still ongoing.


As for 1), with scripts it's currently not possible to hook into ADM's switch in a blocking way except for making all scripts run synchronously (which would be a bad idea).

The quickest way of fixing this that I'm seeing would be by making the HandleSwitch method of the ScriptSwitch component synchronous. Then, with a new configurable option for scripts to run in a blocking manner (disabled by default), the scripts that should run synchronously will be run on the component handler thread, whereas the others still run on a script handler thread.

With the amount of time I have at my disposal at the moment, I am unable to work on this. However I'm noting this down for future references or if someone wants to have a go.

Spiritreader avatar Oct 23 '23 20:10 Spiritreader

Hmm, such a configuration would sound good. Rectify11 ships normal msstyles that are applied with SecureUXThemeTOol.

aaronliu0130 avatar Oct 23 '23 20:10 aaronliu0130