-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRulesWidget.qml
More file actions
54 lines (46 loc) · 1.63 KB
/
Copy pathRulesWidget.qml
File metadata and controls
54 lines (46 loc) · 1.63 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
import QtQuick
import Quickshell
import qs.Commons
import qs.Ui
// Status chip for the Context Rules engine: lit while any rule is
// asserting actions, dimmed while the engine is disabled. Click toggles
// the engine. All state lives in the always-loaded service; the widget is
// a thin reactive view over it.
BarWidget {
id: root
moduleName: "community.context-rules"
property var engine: null
property int resolveAttempts: 0
readonly property var asserted: engine && engine.asserted ? engine.asserted : []
readonly property bool engineEnabled: engine ? engine.engineEnabled === true : false
implicitWidth: engine ? button.implicitWidth : 0
implicitHeight: engine ? button.implicitHeight : 0
visible: engine !== null
function resolveEngine() {
var host = bar && bar.shell && typeof bar.shell.serviceFor === "function" ? bar.shell : null
if (host) engine = host.serviceFor("community.context-rules")
}
Component.onCompleted: resolveEngine()
Timer {
interval: 1000
repeat: true
running: root.engine === null && root.resolveAttempts < 30
onTriggered: {
root.resolveAttempts++
root.resolveEngine()
}
}
BarIconButton {
id: button
bar: root.bar
text: ""
active: root.asserted.length > 0
dimmed: !root.engineEnabled
tooltipText: !root.engineEnabled
? "Context rules paused — click to resume"
: (root.asserted.length > 0
? "Context rules active: " + root.asserted.join(", ") + " — click to pause"
: "Context rules watching — click to pause")
onPressed: if (root.engine) root.engine.setEngineEnabled(!root.engineEnabled)
}
}