Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow executing custom scripts before theme switch #788

Open
aaronliu0130 opened this issue Oct 16, 2023 · 2 comments
Open

Allow executing custom scripts before theme switch #788

aaronliu0130 opened this issue Oct 16, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@aaronliu0130
Copy link

aaronliu0130 commented Oct 16, 2023

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 aaronliu0130 added the enhancement New feature or request label Oct 16, 2023
@Spiritreader
Copy link
Member

Spiritreader commented Oct 23, 2023

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:

cm.RunPostSync(componentsToUpdate, e);

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.

@aaronliu0130
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants