Better night light toggle

This commit is contained in:
David Heinemeier Hansson
2026-05-16 15:40:43 +02:00
parent bdf8daa0a1
commit ab2fb2b85f
@@ -39,6 +39,7 @@ Item {
property bool idleInhibited: false property bool idleInhibited: false
property bool nightLightActive: false property bool nightLightActive: false
property bool nightLightAvailable: false property bool nightLightAvailable: false
property bool nightLightPending: false
property string themeName: "" property string themeName: ""
property string backgroundName: "" property string backgroundName: ""
@@ -52,7 +53,7 @@ Item {
function refresh() { function refresh() {
if (!brightnessProc.running) brightnessProc.running = true if (!brightnessProc.running) brightnessProc.running = true
if (!idleProc.running) idleProc.running = true if (!idleProc.running) idleProc.running = true
if (!nightLightProc.running) nightLightProc.running = true if (!nightLightPending && !nightLightProc.running) nightLightProc.running = true
if (!themeProc.running) themeProc.running = true if (!themeProc.running) themeProc.running = true
if (!backgroundProc.running) backgroundProc.running = true if (!backgroundProc.running) backgroundProc.running = true
} }
@@ -110,12 +111,22 @@ Item {
return return
} }
root.nightLightAvailable = true root.nightLightAvailable = true
if (root.nightLightPending) return
var temp = parseInt(state, 10) var temp = parseInt(state, 10)
root.nightLightActive = !isNaN(temp) && temp < 6000 root.nightLightActive = !isNaN(temp) && temp < 6000
} }
} }
} }
Process {
id: nightLightToggleProc
command: ["omarchy-toggle-nightlight"]
onExited: {
root.nightLightPending = false
if (!nightLightProc.running) nightLightProc.running = true
}
}
Process { Process {
id: themeProc id: themeProc
command: ["omarchy-theme-current"] command: ["omarchy-theme-current"]
@@ -201,9 +212,10 @@ Item {
opacity: root.nightLightAvailable ? 1 : 0.4 opacity: root.nightLightAvailable ? 1 : 0.4
enabled: root.nightLightAvailable enabled: root.nightLightAvailable
onClicked: { onClicked: {
if (nightLightToggleProc.running) return
root.nightLightActive = !root.nightLightActive root.nightLightActive = !root.nightLightActive
root.run("omarchy-toggle-nightlight") root.nightLightPending = true
nightLightProc.running = true nightLightToggleProc.running = true
} }
} }