Repository navigation
Expand file tree
/
Copy pathService.qml
More file actions
67 lines (65 loc) · 2.15 KB
/
Copy pathService.qml
File metadata and controls
67 lines (65 loc) · 2.15 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
64
65
66
67
import QtQuick
import Quickshell
import Quickshell.Io
import "Model.js" as Model
Item {
id: root
property var settings: ({})
property var providers: []
property var go: null
property var recentDays: []
property bool refreshing: false
property string lastError: ""
property string output: ""
property date lastUpdated: new Date(0)
readonly property string collectorScript: decodeURIComponent(String(Qt.resolvedUrl("collector.sh")).replace(/^file:\/\//, ""))
readonly property int refreshIntervalSec: intSetting("refreshIntervalSec", 300, 60, 3600)
function setting(name, fallback) {
var value = settings ? settings[name] : undefined
return value === undefined || value === null ? fallback : value
}
function intSetting(name, fallback, minimum, maximum) {
var value = parseInt(String(setting(name, fallback)), 10)
if (!isFinite(value)) value = fallback
return Math.max(minimum, Math.min(maximum, value))
}
function refresh() {
if (refreshing || collector.running) return
refreshing = true
lastError = ""
collector.command = ["bash", root.collectorScript]
collector.running = true
}
Timer {
interval: root.refreshIntervalSec * 1000
repeat: true
running: true
triggeredOnStart: true
onTriggered: root.refresh()
}
Process {
id: collector
command: []
stdout: StdioCollector {
id: collectorOutput
waitForEnd: true
onStreamFinished: root.output = text
}
stderr: StdioCollector { id: collectorStderr; waitForEnd: true }
onExited: function(exitCode) {
root.refreshing = false
if (exitCode !== 0) {
var detail = String(collectorStderr.text || "").replace(/\s+/g, " ").trim()
root.lastError = detail ? detail.slice(0, 180) : ("Collector failed (exit " + exitCode + ")")
return
}
var parsed = Model.parseCollector(collectorOutput.text || "")
if (!parsed.ok) { root.lastError = parsed.error; return }
root.providers = parsed.data.providers
root.go = parsed.data.go
root.recentDays = parsed.data.recentDays
root.lastError = parsed.data.error
root.lastUpdated = new Date()
}
}
}