summaryrefslogtreecommitdiff
path: root/accounts/gkleen@skadhi/shell/quickshell/Services/Worktime.qml
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2026-09-23 21:08:35 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2026-09-23 21:08:35 +0200
commitae9a80c1f012686c1f65fce7ce76fdd1b77b0b71 (patch)
tree141f738276cf84c6b7e5633c2bd5f2b44e9b0b75 /accounts/gkleen@skadhi/shell/quickshell/Services/Worktime.qml
parent6a763272038e637a8a03dd9059d43a1ff44921dd (diff)
downloadnixos-ae9a80c1f012686c1f65fce7ce76fdd1b77b0b71.tar
nixos-ae9a80c1f012686c1f65fce7ce76fdd1b77b0b71.tar.gz
nixos-ae9a80c1f012686c1f65fce7ce76fdd1b77b0b71.tar.bz2
nixos-ae9a80c1f012686c1f65fce7ce76fdd1b77b0b71.tar.xz
nixos-ae9a80c1f012686c1f65fce7ce76fdd1b77b0b71.zip
...
Diffstat (limited to 'accounts/gkleen@skadhi/shell/quickshell/Services/Worktime.qml')
-rw-r--r--accounts/gkleen@skadhi/shell/quickshell/Services/Worktime.qml84
1 files changed, 84 insertions, 0 deletions
diff --git a/accounts/gkleen@skadhi/shell/quickshell/Services/Worktime.qml b/accounts/gkleen@skadhi/shell/quickshell/Services/Worktime.qml
new file mode 100644
index 00000000..d98378f1
--- /dev/null
+++ b/accounts/gkleen@skadhi/shell/quickshell/Services/Worktime.qml
@@ -0,0 +1,84 @@
1pragma Singleton
2
3import QtQuick
4import Quickshell
5import Quickshell.Io
6import QtQml
7
8Singleton {
9 id: root
10
11 property alias time: timeState
12 property alias today: todayState
13
14 CommandState {
15 id: timeState
16 command: "time"
17 }
18 CommandState {
19 id: todayState
20 command: "today"
21 }
22
23 IpcHandler {
24 target: "Worktime"
25
26 function refresh(): void {
27 time.running = true;
28 today.running = true;
29 }
30 }
31
32 component CommandState : Scope {
33 id: commandState
34
35 required property string command
36 property var state: null
37
38 property bool strikeout: !strikeoutTimer.running
39 property alias running: process.running
40 property alias updating: updateTimer.running
41
42 Process {
43 id: process
44 running: true
45 command: [ @worktime@, commandState.command, "--waybar" ]
46 stdout: StdioCollector {
47 id: processCollector
48 onStreamFinished: {
49 try {
50 commandState.state = JSON.parse(processCollector.text);
51 strikeoutTimer.restart();
52 } catch (e) {
53 console.warn("Worktime: Failed to parse output:", processCollector.text, e);
54 }
55 }
56 }
57 }
58
59 Timer {
60 id: updateTimer
61 running: commandState.state?.class == "running" || commandState.state?.class == "over"
62 interval: 60000
63 repeat: true
64 onTriggered: process.running = true
65 }
66
67 Timer {
68 id: strikeoutTimer
69 running: false
70 interval: 5 * updateTimer.interval
71 repeat: false
72 }
73 }
74
75 Timer {
76 running: Boolean(timeState.state) && Boolean(todayState.state) && timeState.strikeout && todayState.strikeout
77 interval: 1000
78 repeat: false
79 onTriggered: {
80 timeState.state = null;
81 todayState.state = null;
82 }
83 }
84}