Files
arthur-os/shell/plugins/bar/indicators/NightLight.qml
T

66 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() {
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()
}
Timer {
interval: 5000
running: true
repeat: true
onTriggered: root.refresh()
}
onPressed: function() { root.toggle() }
}