[Light Switch] Hotfixes (#42434)

<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request
Adds new "Off" mode for the schedule mode options which disable the
schedule.
Adds explicit function to disable light switch by default.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

Closes: 
- #42402 
New behavior: "Off" mode added. when off, the regular service loop stops
and all actions are event driven to either resume the loop or listen for
hotkey.
- #42386
New behavior: Disabled explicitly by default
- #42389
New behavior: When switching from dark to light mode the system theme
will remove the accent color.
- #42513
New behavior: Manual mode no longer gets reset. It was being overridden
by the sun calculations that were invertedly running when in manual
mode.

Todo:
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx @alvinashcraft we will need to add this new mode
to the documentation.

## Validation Steps Performed
- Removed all default settings and tested new logic. Light Switch is set
to off by default.
- Updated UI and tested new "Off" mode, logs indicate mode switched and
ticker stopped. Polling resumes on mode change. (need to check that the
shortcut still works)

---------

Co-authored-by: Niels Laute <niels.laute@live.nl>
Co-authored-by: Gordon Lam <73506701+yeelam-gordon@users.noreply.github.com>
This commit is contained in:
Jaylyn Barbee
2025-10-20 18:57:03 -04:00
committed by GitHub
parent f28d009131
commit f45d54abdf
12 changed files with 584 additions and 339 deletions

View File

@@ -1,8 +1,32 @@
#include <windows.h>
#include <logger/logger_settings.h>
#include <logger/logger.h>
#include <utils/logger_helper.h>
#include "ThemeHelper.h"
// Controls changing the themes.
static void ResetColorPrevalence()
{
HKEY hKey;
if (RegOpenKeyEx(HKEY_CURRENT_USER,
L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
0,
KEY_SET_VALUE,
&hKey) == ERROR_SUCCESS)
{
DWORD value = 0; // back to default value
RegSetValueEx(hKey, L"ColorPrevalence", 0, REG_DWORD, reinterpret_cast<const BYTE*>(&value), sizeof(value));
RegCloseKey(hKey);
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, reinterpret_cast<LPARAM>(L"ImmersiveColorSet"), SMTO_ABORTIFHUNG, 5000, nullptr);
SendMessageTimeout(HWND_BROADCAST, WM_THEMECHANGED, 0, 0, SMTO_ABORTIFHUNG, 5000, nullptr);
SendMessageTimeout(HWND_BROADCAST, WM_DWMCOLORIZATIONCOLORCHANGED, 0, 0, SMTO_ABORTIFHUNG, 5000, nullptr);
}
}
void SetAppsTheme(bool mode)
{
HKEY hKey;
@@ -35,6 +59,12 @@ void SetSystemTheme(bool mode)
RegSetValueEx(hKey, L"SystemUsesLightTheme", 0, REG_DWORD, reinterpret_cast<const BYTE*>(&value), sizeof(value));
RegCloseKey(hKey);
if (mode) // if are changing to light mode
{
ResetColorPrevalence();
Logger::info(L"[LightSwitchService] Reset ColorPrevalence to default when switching to light mode.");
}
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, reinterpret_cast<LPARAM>(L"ImmersiveColorSet"), SMTO_ABORTIFHUNG, 5000, nullptr);
SendMessageTimeout(HWND_BROADCAST, WM_THEMECHANGED, 0, 0, SMTO_ABORTIFHUNG, 5000, nullptr);