diff --git a/Commons/Time.qml b/Commons/Time.qml index c95a197b6..69a24695f 100644 --- a/Commons/Time.qml +++ b/Commons/Time.qml @@ -11,6 +11,12 @@ Singleton { // Current date property var now: new Date() + // Unix timestamp of the last update + property real _lastUpdateTs: Date.now() + + // Signal emitted when a significant time jump is detected (e.g. system resume) + signal resumed + // Returns a Unix Timestamp (in seconds) readonly property int timestamp: { return Math.floor(root.now / 1000); @@ -34,6 +40,15 @@ Singleton { triggeredOnStart: false onTriggered: { var newTime = new Date(); + var currentTs = newTime.getTime(); + + // Detect time jump (e.g. system resume) - threshold: 5 seconds + if (currentTs - root._lastUpdateTs > 5000) { + Logger.i("Time", "Time jump detected (" + Math.round((currentTs - root._lastUpdateTs) / 1000) + "s) - likely system resume"); + root.resumed(); + } + root._lastUpdateTs = currentTs; + root.now = newTime; // Update timer if running diff --git a/Services/Location/DarkModeService.qml b/Services/Location/DarkModeService.qml index 3e465fa9d..271126a9f 100644 --- a/Services/Location/DarkModeService.qml +++ b/Services/Location/DarkModeService.qml @@ -43,7 +43,15 @@ Singleton { Connections { target: Settings.data.colorSchemes function onSchedulingModeChanged() { - root.init(); + root.update(); + } + } + + Connections { + target: Time + function onResumed() { + Logger.i("DarkModeService", "System resumed - re-evaluating dark mode"); + root.update(); } } @@ -51,24 +59,22 @@ Singleton { id: timer onTriggered: { Settings.data.colorSchemes.darkMode = root.nextDarkModeState; - if (LocationService.data.weather !== null) { - const changes = root.collectWeatherChanges(LocationService.data.weather); - root.scheduleNextMode(changes); - } + root.update(); } } function init() { Logger.i("DarkModeService", "Service started"); + root.update(); + } + function update() { if (Settings.data.colorSchemes.schedulingMode == "manual") { const changes = collectManualChanges(); initComplete = true; applyCurrentMode(changes); scheduleNextMode(changes); - } - - if (Settings.data.colorSchemes.schedulingMode == "location" && LocationService.data.weather) { + } else if (Settings.data.colorSchemes.schedulingMode == "location" && LocationService.data.weather) { const changes = collectWeatherChanges(LocationService.data.weather); initComplete = true; applyCurrentMode(changes); diff --git a/Services/Location/NightLightService.qml b/Services/Location/NightLightService.qml index 59a8744a7..9d6cc020f 100644 --- a/Services/Location/NightLightService.qml +++ b/Services/Location/NightLightService.qml @@ -85,11 +85,19 @@ Singleton { target: LocationService function onCoordinatesReadyChanged() { if (LocationService.coordinatesReady) { - apply(); + root.apply(); } } } + Connections { + target: Time + function onResumed() { + Logger.i("NightLight", "System resumed - re-applying night light"); + root.apply(); + } + } + // Foreground process runner Process { id: runner