From 2c4aab9d872e493292ef66982d05ae87e97dfcb6 Mon Sep 17 00:00:00 2001 From: Jaylyn Barbee <51131738+Jaylyn-Barbee@users.noreply.github.com> Date: Wed, 22 Oct 2025 14:59:36 -0400 Subject: [PATCH] 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) --- .../LightSwitchService/LightSwitchService.cpp | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/modules/LightSwitch/LightSwitchService/LightSwitchService.cpp b/src/modules/LightSwitch/LightSwitchService/LightSwitchService.cpp index 69fe38248f..7ebe4a67eb 100644 --- a/src/modules/LightSwitch/LightSwitchService/LightSwitchService.cpp +++ b/src/modules/LightSwitch/LightSwitchService/LightSwitchService.cpp @@ -16,6 +16,8 @@ SERVICE_STATUS g_ServiceStatus = {}; SERVICE_STATUS_HANDLE g_StatusHandle = nullptr; HANDLE g_ServiceStopEvent = nullptr; static int g_lastUpdatedDay = -1; +static ScheduleMode prevMode = ScheduleMode::Off; +static std::wstring prevLat, prevLon; VOID WINAPI ServiceMain(DWORD argc, LPTSTR* argv); VOID WINAPI ServiceCtrlHandler(DWORD dwCtrl); @@ -185,20 +187,28 @@ DWORD WINAPI ServiceWorkerThread(LPVOID lpParam) if (isLightActive) { if (settings.changeSystem && !isSystemCurrentlyLight) + { SetSystemTheme(true); Logger::info(L"[LightSwitchService] Changing system theme to light mode."); + } if (settings.changeApps && !isAppsCurrentlyLight) + { SetAppsTheme(true); Logger::info(L"[LightSwitchService] Changing apps theme to light mode."); + } } else { if (settings.changeSystem && isSystemCurrentlyLight) + { SetSystemTheme(false); Logger::info(L"[LightSwitchService] Changing system theme to dark mode."); + } if (settings.changeApps && isAppsCurrentlyLight) + { 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(); 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 (settings.scheduleMode == ScheduleMode::Off) {