mirror of
https://github.com/arthur-pbty/arthur-os.git
synced 2026-08-05 20:28:25 +02:00
65 lines
1.2 KiB
QML
65 lines
1.2 KiB
QML
import QtQuick
|
|
import Quickshell.Io
|
|
import qs.Ui
|
|
|
|
BarIndicator {
|
|
id: root
|
|
|
|
property bool nightlight: false
|
|
|
|
active: nightlight
|
|
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() {
|
|
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()
|
|
}
|
|
|
|
Timer {
|
|
interval: 5000
|
|
running: true
|
|
repeat: true
|
|
onTriggered: root.refresh()
|
|
}
|
|
|
|
onPressed: function() { root.toggle() }
|
|
}
|