nova-shell/shell/services/WeatherService.qml

42 lines
1 KiB
QML

pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
import "." as S
QtObject {
id: root
property string icon: ""
property string tooltip: ""
readonly property bool available: icon !== ""
property Process _proc: Process {
running: S.Modules.weather.enable
command: ["wttrbar"].concat(S.Modules.weather.args)
stdout: StdioCollector {
onStreamFinished: {
try {
const data = JSON.parse(text);
root.icon = data.text ?? "";
root.tooltip = data.tooltip ?? "";
} catch (e) {
root.icon = "";
root.tooltip = "";
}
}
}
}
property Timer _poll: Timer {
interval: S.Modules.weather.interval || 3600000
running: S.Modules.weather.enable
repeat: true
onTriggered: root._proc.running = true
}
function refresh() {
_proc.running = true;
}
}