make night light auto still function after manual toggle (#2030)

This commit is contained in:
end-4
2025-09-28 11:33:58 +02:00
parent 28c37c08d2
commit e97f819a5c
+22 -8
View File
@@ -12,7 +12,6 @@ import Quickshell.Io
*/ */
Singleton { Singleton {
id: root id: root
property var manualActive
property string from: Config.options?.light?.night?.from ?? "19:00" property string from: Config.options?.light?.night?.from ?? "19:00"
property string to: Config.options?.light?.night?.to ?? "06:30" property string to: Config.options?.light?.night?.to ?? "06:30"
property bool automatic: Config.options?.light?.night?.automatic && (Config?.ready ?? true) property bool automatic: Config.options?.light?.night?.automatic && (Config?.ready ?? true)
@@ -29,6 +28,9 @@ Singleton {
property int clockHour: DateTime.clock.hours property int clockHour: DateTime.clock.hours
property int clockMinute: DateTime.clock.minutes property int clockMinute: DateTime.clock.minutes
property var manualActive
property int manualActiveHour
property int manualActiveMinute
onClockMinuteChanged: reEvaluate() onClockMinuteChanged: reEvaluate()
onAutomaticChanged: { onAutomaticChanged: {
@@ -36,17 +38,26 @@ Singleton {
root.firstEvaluation = true; root.firstEvaluation = true;
reEvaluate(); reEvaluate();
} }
function inBetween(t, from, to) {
if (from < to) {
return (t >= from && t <= to);
} else {
// Wrapped around midnight
return (t >= from || t <= to);
}
}
function reEvaluate() { function reEvaluate() {
const t = clockHour * 60 + clockMinute; const t = clockHour * 60 + clockMinute;
const from = fromHour * 60 + fromMinute; const from = fromHour * 60 + fromMinute;
const to = toHour * 60 + toMinute; const to = toHour * 60 + toMinute;
const manualActive = manualActiveHour * 60 + manualActiveMinute;
if (from < to) { if (root.manualActive !== undefined && (inBetween(from, manualActive, t) || inBetween(to, manualActive, t))) {
root.shouldBeOn = t >= from && t <= to; root.manualActive = undefined;
} else {
// Wrapped around midnight
root.shouldBeOn = t >= from || t <= to;
} }
root.shouldBeOn = inBetween(t, from, to);
if (firstEvaluation) { if (firstEvaluation) {
firstEvaluation = false; firstEvaluation = false;
root.ensureState(); root.ensureState();
@@ -94,15 +105,18 @@ Singleton {
if (output.length == 0 || output.startsWith("Couldn't")) if (output.length == 0 || output.startsWith("Couldn't"))
root.active = false; root.active = false;
else else
root.active = (output != "6500"); root.active = (output != "6500"); // 6500 is the default when off
// console.log("[Hyprsunset] Fetched state:", output, "->", root.active); // console.log("[Hyprsunset] Fetched state:", output, "->", root.active);
} }
} }
} }
function toggle() { function toggle() {
if (root.manualActive === undefined) if (root.manualActive === undefined) {
root.manualActive = root.active; root.manualActive = root.active;
root.manualActiveHour = root.clockHour;
root.manualActiveMinute = root.clockMinute;
}
root.manualActive = !root.manualActive; root.manualActive = !root.manualActive;
if (root.manualActive) { if (root.manualActive) {