Repository navigation
Expand file tree
/
Copy pathLocalAnalyticsReader.qml
More file actions
63 lines (60 loc) · 1.81 KB
/
Copy pathLocalAnalyticsReader.qml
File metadata and controls
63 lines (60 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import QtQuick
import Quickshell.Io
// Bounded JSON subprocess reader. No dashboard/global-service dependencies.
Item {
id: reader
required property string providerId
required property string scriptPath
property var commandArguments: [providerId]
property bool retainOnFailure: false
property int timeoutMs: 45000
property var result: null
readonly property bool running: process.running
property string buffer: ""
property bool timedOut: false
signal completed()
visible: false
function refresh() {
if (process.running)
return;
buffer = "";
timedOut = false;
process.command = ["bash", scriptPath].concat(commandArguments);
process.running = true;
deadline.restart();
}
Process {
id: process
stdout: SplitParser {
splitMarker: ""
onRead: chunk => reader.buffer += chunk
}
onExited: code => {
deadline.stop();
try {
if (code === 0 && !reader.timedOut && reader.buffer.length > 0) {
const parsed = JSON.parse(reader.buffer);
reader.result = parsed && !parsed.error ? parsed : null;
} else if (!reader.retainOnFailure) {
reader.result = null;
}
} catch (error) {
if (!reader.retainOnFailure)
reader.result = null;
}
reader.buffer = "";
reader.completed();
}
}
Timer {
id: deadline
interval: reader.timeoutMs
onTriggered: {
reader.timedOut = true;
process.running = false;
reader.buffer = "";
if (!reader.retainOnFailure)
reader.result = null;
}
}
}