mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
Time: detect time jumps to fix nightlight/darkmode logic (#1599)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user