Skip to content

Commit 2c4aab9

Browse files
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)
1 parent 52ce33d commit 2c4aab9

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

‎src/modules/LightSwitch/LightSwitchService/LightSwitchService.cpp‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ SERVICE_STATUS g_ServiceStatus = {};
1616
SERVICE_STATUS_HANDLE g_StatusHandle = nullptr;
1717
HANDLE g_ServiceStopEvent = nullptr;
1818
static int g_lastUpdatedDay = -1;
19+
static ScheduleMode prevMode = ScheduleMode::Off;
20+
static std::wstring prevLat, prevLon;
1921

2022
VOID WINAPI ServiceMain(DWORD argc, LPTSTR* argv);
2123
VOID WINAPI ServiceCtrlHandler(DWORD dwCtrl);
@@ -185,20 +187,28 @@ DWORD WINAPI ServiceWorkerThread(LPVOID lpParam)
185187
if (isLightActive)
186188
{
187189
if (settings.changeSystem && !isSystemCurrentlyLight)
190+
{
188191
SetSystemTheme(true);
189192
Logger::info(L"[LightSwitchService] Changing system theme to light mode.");
193+
}
190194
if (settings.changeApps && !isAppsCurrentlyLight)
195+
{
191196
SetAppsTheme(true);
192197
Logger::info(L"[LightSwitchService] Changing apps theme to light mode.");
198+
}
193199
}
194200
else
195201
{
196202
if (settings.changeSystem && isSystemCurrentlyLight)
203+
{
197204
SetSystemTheme(false);
198205
Logger::info(L"[LightSwitchService] Changing system theme to dark mode.");
206+
}
199207
if (settings.changeApps && isAppsCurrentlyLight)
208+
{
200209
SetAppsTheme(false);
201-
Logger::info(L"[LightSwitchService] Changing apps theme to light mode.");
210+
Logger::info(L"[LightSwitchService] Changing apps theme to dark mode.");
211+
}
202212
}
203213
};
204214

@@ -228,6 +238,23 @@ DWORD WINAPI ServiceWorkerThread(LPVOID lpParam)
228238
LightSwitchSettings::instance().LoadSettings();
229239
const auto& settings = LightSwitchSettings::instance().settings();
230240

241+
// Check for changes in schedule mode or coordinates
242+
bool modeChangedToSunset = (prevMode != settings.scheduleMode &&
243+
settings.scheduleMode == ScheduleMode::SunsetToSunrise);
244+
bool coordsChanged = (prevLat != settings.latitude || prevLon != settings.longitude);
245+
246+
if ((modeChangedToSunset || coordsChanged) && settings.scheduleMode == ScheduleMode::SunsetToSunrise)
247+
{
248+
Logger::info(L"[LightSwitchService] Mode or coordinates changed, recalculating sun times.");
249+
update_sun_times(settings);
250+
SYSTEMTIME st;
251+
GetLocalTime(&st);
252+
g_lastUpdatedDay = st.wDay;
253+
prevMode = settings.scheduleMode;
254+
prevLat = settings.latitude;
255+
prevLon = settings.longitude;
256+
}
257+
231258
// If schedule is off, idle but keep watching settings and manual override
232259
if (settings.scheduleMode == ScheduleMode::Off)
233260
{

0 commit comments

Comments
 (0)