Move Night Light onto a first-party nightlight service
Same treatment as Stay Awake: the indicator polled the toggle CLI over a Process with a timer to paper over the race after clicking, and the CLI ended by asking the shell to refresh every indicator over IPC. A new omarchy.nightlight service owns hyprsunset instead - it probes the temperature on startup, applies changes itself for in-shell toggles, and answers on the nightlight IPC target. The indicator becomes a plain binding. The CLI still drives hyprctl directly so keybindings, the menu, and ssh work without the shell, but now just nudges the service to re-probe since hyprsunset has no state file to watch. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
61b7cd1c12
commit
ba91bad3a4
@@ -1,57 +1,19 @@
|
||||
import QtQuick
|
||||
import Quickshell.Io
|
||||
import qs.Ui
|
||||
|
||||
BarIndicator {
|
||||
id: root
|
||||
|
||||
property bool nightlight: false
|
||||
readonly property var nightlightService: bar?.shell?.firstPartyServiceFor("omarchy.nightlight")
|
||||
|
||||
active: nightlight
|
||||
active: nightlightService ? nightlightService.enabled : false
|
||||
activeText: ""
|
||||
inactiveText: ""
|
||||
activeTooltipText: "Day Light"
|
||||
inactiveTooltipText: "Night Light"
|
||||
|
||||
function refresh() {
|
||||
if (!statusProc.running) statusProc.running = true
|
||||
}
|
||||
|
||||
function update(raw) {
|
||||
var data = extractData(raw)
|
||||
nightlight = data && data.enabled === true
|
||||
}
|
||||
|
||||
function toggle() {
|
||||
nightlight = !nightlight
|
||||
if (root.bar) root.bar.run("omarchy-toggle-nightlight")
|
||||
refreshTimer.restart()
|
||||
}
|
||||
|
||||
Component.onCompleted: refresh()
|
||||
|
||||
Connections {
|
||||
target: root.indicatorHost
|
||||
ignoreUnknownSignals: true
|
||||
function onRefreshRequested() { root.refresh() }
|
||||
}
|
||||
|
||||
Process {
|
||||
id: statusProc
|
||||
command: ["omarchy-toggle-nightlight", "--status"]
|
||||
stdout: StdioCollector {
|
||||
waitForEnd: true
|
||||
onStreamFinished: root.update(text)
|
||||
}
|
||||
onExited: function(exitCode) {
|
||||
if (exitCode !== 0) root.nightlight = false
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: refreshTimer
|
||||
interval: 1500
|
||||
onTriggered: root.refresh()
|
||||
if (root.nightlightService) root.nightlightService.setNightlight(!root.active)
|
||||
}
|
||||
|
||||
onPressed: function() { root.toggle() }
|
||||
|
||||
Reference in New Issue
Block a user