mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-09 04:37:30 +02:00
Light Switch Hotfixes v2 (#42774)
Should fix: #42627 Issue: Suntimes not updating within the day if the mode changes to SunsetToSunrise Fix: Update suntimes in the service if the mode is changed to Sun mode. Other: small bug fixes (brackets, etc)
This commit is contained in:
@@ -16,6 +16,8 @@ SERVICE_STATUS g_ServiceStatus = {};
|
|||||||
SERVICE_STATUS_HANDLE g_StatusHandle = nullptr;
|
SERVICE_STATUS_HANDLE g_StatusHandle = nullptr;
|
||||||
HANDLE g_ServiceStopEvent = nullptr;
|
HANDLE g_ServiceStopEvent = nullptr;
|
||||||
static int g_lastUpdatedDay = -1;
|
static int g_lastUpdatedDay = -1;
|
||||||
|
static ScheduleMode prevMode = ScheduleMode::Off;
|
||||||
|
static std::wstring prevLat, prevLon;
|
||||||
|
|
||||||
VOID WINAPI ServiceMain(DWORD argc, LPTSTR* argv);
|
VOID WINAPI ServiceMain(DWORD argc, LPTSTR* argv);
|
||||||
VOID WINAPI ServiceCtrlHandler(DWORD dwCtrl);
|
VOID WINAPI ServiceCtrlHandler(DWORD dwCtrl);
|
||||||
@@ -185,20 +187,28 @@ DWORD WINAPI ServiceWorkerThread(LPVOID lpParam)
|
|||||||
if (isLightActive)
|
if (isLightActive)
|
||||||
{
|
{
|
||||||
if (settings.changeSystem && !isSystemCurrentlyLight)
|
if (settings.changeSystem && !isSystemCurrentlyLight)
|
||||||
|
{
|
||||||
SetSystemTheme(true);
|
SetSystemTheme(true);
|
||||||
Logger::info(L"[LightSwitchService] Changing system theme to light mode.");
|
Logger::info(L"[LightSwitchService] Changing system theme to light mode.");
|
||||||
|
}
|
||||||
if (settings.changeApps && !isAppsCurrentlyLight)
|
if (settings.changeApps && !isAppsCurrentlyLight)
|
||||||
|
{
|
||||||
SetAppsTheme(true);
|
SetAppsTheme(true);
|
||||||
Logger::info(L"[LightSwitchService] Changing apps theme to light mode.");
|
Logger::info(L"[LightSwitchService] Changing apps theme to light mode.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (settings.changeSystem && isSystemCurrentlyLight)
|
if (settings.changeSystem && isSystemCurrentlyLight)
|
||||||
|
{
|
||||||
SetSystemTheme(false);
|
SetSystemTheme(false);
|
||||||
Logger::info(L"[LightSwitchService] Changing system theme to dark mode.");
|
Logger::info(L"[LightSwitchService] Changing system theme to dark mode.");
|
||||||
|
}
|
||||||
if (settings.changeApps && isAppsCurrentlyLight)
|
if (settings.changeApps && isAppsCurrentlyLight)
|
||||||
|
{
|
||||||
SetAppsTheme(false);
|
SetAppsTheme(false);
|
||||||
Logger::info(L"[LightSwitchService] Changing apps theme to light mode.");
|
Logger::info(L"[LightSwitchService] Changing apps theme to dark mode.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -228,6 +238,23 @@ DWORD WINAPI ServiceWorkerThread(LPVOID lpParam)
|
|||||||
LightSwitchSettings::instance().LoadSettings();
|
LightSwitchSettings::instance().LoadSettings();
|
||||||
const auto& settings = LightSwitchSettings::instance().settings();
|
const auto& settings = LightSwitchSettings::instance().settings();
|
||||||
|
|
||||||
|
// Check for changes in schedule mode or coordinates
|
||||||
|
bool modeChangedToSunset = (prevMode != settings.scheduleMode &&
|
||||||
|
settings.scheduleMode == ScheduleMode::SunsetToSunrise);
|
||||||
|
bool coordsChanged = (prevLat != settings.latitude || prevLon != settings.longitude);
|
||||||
|
|
||||||
|
if ((modeChangedToSunset || coordsChanged) && settings.scheduleMode == ScheduleMode::SunsetToSunrise)
|
||||||
|
{
|
||||||
|
Logger::info(L"[LightSwitchService] Mode or coordinates changed, recalculating sun times.");
|
||||||
|
update_sun_times(settings);
|
||||||
|
SYSTEMTIME st;
|
||||||
|
GetLocalTime(&st);
|
||||||
|
g_lastUpdatedDay = st.wDay;
|
||||||
|
prevMode = settings.scheduleMode;
|
||||||
|
prevLat = settings.latitude;
|
||||||
|
prevLon = settings.longitude;
|
||||||
|
}
|
||||||
|
|
||||||
// If schedule is off, idle but keep watching settings and manual override
|
// If schedule is off, idle but keep watching settings and manual override
|
||||||
if (settings.scheduleMode == ScheduleMode::Off)
|
if (settings.scheduleMode == ScheduleMode::Off)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user