summaryrefslogtreecommitdiff
path: root/accounts/gkleen@sif/shell/quickshell/Services/Worktime.qml
diff options
context:
space:
mode:
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell/Services/Worktime.qml')
-rw-r--r--accounts/gkleen@sif/shell/quickshell/Services/Worktime.qml75
1 files changed, 75 insertions, 0 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell/Services/Worktime.qml b/accounts/gkleen@sif/shell/quickshell/Services/Worktime.qml
new file mode 100644
index 00000000..fdb45aa0
--- /dev/null
+++ b/accounts/gkleen@sif/shell/quickshell/Services/Worktime.qml
@@ -0,0 +1,75 @@
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 component CommandState : Scope {
24 id: commandState
25
26 required property string command
27 property var state: null
28
29 property bool strikeout: !strikeoutTimer.running
30 property alias running: process.running
31 property alias updating: updateTimer.running
32
33 Process {
34 id: process
35 running: true
36 command: [ @worktime@, commandState.command, "--waybar" ]
37 stdout: StdioCollector {
38 id: processCollector
39 onStreamFinished: {
40 try {
41 commandState.state = JSON.parse(processCollector.text);
42 strikeoutTimer.restart();
43 } catch (e) {
44 console.warn("Worktime: Failed to parse output:", processCollector.text, e);
45 }
46 }
47 }
48 }
49
50 Timer {
51 id: updateTimer
52 running: commandState.state?.class == "running" || commandState.state?.class == "over"
53 interval: 60000
54 repeat: true
55 onTriggered: process.running = true
56 }
57
58 Timer {
59 id: strikeoutTimer
60 running: false
61 interval: 5 * updateTimer.interval
62 repeat: false
63 }
64 }
65
66 Timer {
67 running: Boolean(timeState.state) && Boolean(todayState.state) && timeState.strikeout && todayState.strikeout
68 interval: 1000
69 repeat: false
70 onTriggered: {
71 timeState.state = null;
72 todayState.state = null;
73 }
74 }
75}