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

Add blue light detection for theme switch

Open inxomnyaa opened this issue 2 years ago • 5 comments

http://stackoverflow.com/questions/43340619/ddg#43953978

It would be cool to have a mode to detect if the blue light filter is running, as alternative to the time based / location based mode

inxomnyaa avatar Sep 09 '21 19:09 inxomnyaa

oh wow! thanks. But it would be probably hard to implement. :D

Armin2208 avatar Sep 09 '21 22:09 Armin2208

oh wow! thanks. But it would be probably hard to implement. :D

It is potentially possible using WMI registry monitoring, in case we investigate this further.

However something very important to note: If this can really be used to detect night/day depending on Windows Night Light, it would require a completely new mode that runs the service without the main timers, because the underlying theme switch trigger is now an event!

Spiritreader avatar Sep 10 '21 00:09 Spiritreader

Working on it on a fork https://github.com/thebigsmileXD/Windows-Auto-Night-Mode/

inxomnyaa avatar Sep 10 '21 00:09 inxomnyaa

Just a fair bit of info for you:

Armin was very correct in estimating this to be a lot of work if done right.

This cannot be implemented using a timer, because this would mean that there's a check for a registry key update every 60 seconds, which is something we chose to avoid in ADM. This is done to minimize footprint and external calls as much as possible. States are only tracked in memory and synchronized once when features are enabled in the config.

We need a new switch source that is not the timer. So essentially, what is necessary is to use a change event listener on the regkey. As far as I'm aware, this event handler needs to use WMIC queries. When the TimedSwitch module is disabled, the offset feature would need to be reimplemented to work with the new source. For this, a new mechanism has to be created that is able to correctly postpone a theme switch if it was triggered by windows night light. Once that is done, postpone compatibility has to be ensured with all modules, for example the GPU monitoring module.

Finally, there has to be some sort of management class which is able to switch between sources (timer based, event based without restarting the service)

As for the event handler, we already have one in place for a different purpose, but that one is compatible with the timer based theme switching. You can take a look here to see how that works: https://github.com/AutoDarkMode/Windows-Auto-Night-Mode/blob/ad980e807dce9cb36878cad118f0d080b6e8d5df/AutoDarkModeSvc/Handlers/PowerEventHandler.cs#L67

All while doing that on a fork of the very dev-active beta-5 branch which currently undergoes heavy restructuring. As such, this needs to be designed previously to implementation, as there are a lot of changes and very likely new interfaces to the code.

There's a good chance I forgot some stuff, but yeah, a quite ambitious project.

Spiritreader avatar Sep 10 '21 07:09 Spiritreader

The Auto Dark Mode Version X codebase is now final/stable and has been merged into master (see https://github.com/AutoDarkMode/Windows-Auto-Night-Mode/pull/252) This version will release on Oct 5th.

If you're still interested in getting this implemented in a future release by doing it "the right way", feel free to reach out. I'll gladly provide more details explanation on how the inner structure works.

Spiritreader avatar Oct 04 '21 14:10 Spiritreader

Is there still interest for this feature @thebigsmileXD (or anyone else who wants this as a matter of fact)? If so, we now have everything ready to get this working.

Spiritreader avatar Oct 05 '22 10:10 Spiritreader

Closing in favor of #489, thanks again for the contribution, helped a lot in getting this to work!

Spiritreader avatar Oct 06 '22 20:10 Spiritreader