Skip to content

Commit 37dfdba

Browse files
committed
feat: show ProcessMonitor loading errors
Normally missing qml modules like `QtWebSockets` are caught during widget initialization, but I am dynamically loading components depending on whether the optional C++ plugin is installed or not, and this way just throws a warning when the widget is added to a panel or when plasma starts. Now these errors are shown on the widget. refs: #29
1 parent fee06ba commit 37dfdba

5 files changed

Lines changed: 46 additions & 37 deletions

File tree

package/contents/ui/Cava.qml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ Item {
2626
property bool idle
2727
property bool idleCheck
2828
property int idleTimer
29-
property bool hasError: error !== ""
30-
property string error
31-
property bool usingFallback: process.usingFallback
32-
property bool running: process.running
29+
readonly property bool hasError: error !== ""
30+
readonly property string error: process.stderr
31+
readonly property list<string> loadingErrors: process.loadingErrors
32+
readonly property bool loadingFailed: process.loadingFailed
33+
readonly property bool usingFallback: process.usingFallback
34+
readonly property bool running: process.running
3335
readonly property string cavaCommand: process.command
3436
readonly property string cavaConfig: {
3537
let config = `[general]
@@ -105,7 +107,7 @@ EOF
105107
idleTimer.restart();
106108
}
107109
}
108-
onStderrChanged: root.error = process.stderr
110+
onLoadingErrorsChanged: root.error = process.loadingErrors.join("\n")
109111
}
110112

111113
Timer {

package/contents/ui/CompactRepresentation.qml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Item {
8686
waveFillColorsCfg: root.waveFillColorsCfg
8787
values: cava.values
8888
debugMode: Plasmoid.configuration.debugMode
89-
visible: !cava.hasError && !cava.idle
89+
visible: !cava.hasError && !cava.idle && !cava.loadingFailed
9090
}
9191
Kirigami.Icon {
9292
anchors.centerIn: parent
@@ -96,7 +96,7 @@ Item {
9696
active: mouseArea.containsMouse
9797
isMask: true
9898
color: Kirigami.Theme.negativeTextColor
99-
visible: cava.hasError
99+
visible: cava.hasError || cava.loadingFailed
100100
}
101101

102102
MouseArea {

package/contents/ui/FullRepresentation.qml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ ColumnLayout {
5353
if (cava.error) {
5454
msg += `Error: ${cava.error}\n`;
5555
}
56+
if (!cava.running && cava.loadingFailed) {
57+
msg += `Error: ${cava.loadingErrors.join('\n')}\n`;
58+
}
5659
if (cava.running) {
5760
msg += `CAVA is running\n`;
5861
} else {

package/contents/ui/components/ProcessMonitor.qml

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,54 @@ Item {
44
id: root
55

66
property string command: ""
7-
property string stdout: ""
8-
property string stderr: ""
9-
property bool useFallback: false
10-
property bool usingFallback: loader.source.toString() === "ProcessMonitorFallback.qml"
11-
property bool running: false
7+
readonly property string stdout: process.stdout ?? ""
8+
readonly property string stderr: process.stderr ?? ""
9+
readonly property bool forceFallback: false
10+
readonly property bool running: process.running ?? false
11+
property bool usingFallback: false
12+
property var process: null
13+
property bool loadingFailed: false
14+
property list<string> loadingErrors
1215

1316
function restart() {
14-
if (loader.status === Loader.Ready) {
15-
loader.item.restart();
17+
if (process !== null) {
18+
process.restart();
1619
}
1720
}
1821

1922
function stop() {
20-
if (loader.status === Loader.Ready) {
21-
loader.item.stop();
23+
if (process !== null) {
24+
process.stop();
2225
}
2326
}
2427

2528
onCommandChanged: {
26-
if (loader.status === Loader.Ready) {
27-
loader.item.command = root.command;
29+
if (process !== null) {
30+
process.command = root.command;
2831
}
2932
}
3033

31-
Loader {
32-
id: loader
33-
34-
source: root.useFallback ? "ProcessMonitorFallback.qml" : "ProcessMonitorPrimary.qml"
35-
onStatusChanged: {
36-
if (status === Loader.Error) {
37-
loader.source = "ProcessMonitorFallback.qml";
34+
Component.onCompleted: {
35+
let component = null;
36+
const sources = ["ProcessMonitorFallback.qml"];
37+
if (!root.forceFallback) {
38+
sources.unshift("ProcessMonitorPrimary.qml");
39+
}
40+
for (let source of sources) {
41+
component = Qt.createComponent(source);
42+
if (component.status === Component.Ready) {
43+
process = component.createObject(root);
44+
process.command = root.command;
45+
break;
46+
} else {
47+
console.warn(component.errorString());
48+
root.loadingErrors.push(component.errorString());
3849
}
3950
}
40-
onLoaded: {
41-
loader.item.command = root.command;
42-
loader.item.stdoutChanged.connect(() => {
43-
root.stdout = loader.item.stdout;
44-
});
45-
loader.item.stderrChanged.connect(() => {
46-
root.stderr = loader.item.stderr;
47-
});
48-
loader.item.runningChanged.connect(() => {
49-
root.running = loader.item.running;
50-
});
51+
52+
if (process === null) {
53+
root.loadingFailed = true;
5154
}
55+
root.usingFallback = component.url.toString().includes("ProcessMonitorFallback.qml");
5256
}
5357
}

package/contents/ui/main.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PlasmoidItem {
3838
if (Plasmoid.status === PlasmaCore.Types.RequiresAttentionStatus) {
3939
return;
4040
}
41-
Plasmoid.status = (hideWhenIdle && cava.idle || !cava.running) && !Plasmoid.expanded && !editMode && !cava.hasError ? PlasmaCore.Types.HiddenStatus : PlasmaCore.Types.ActiveStatus;
41+
Plasmoid.status = hideWhenIdle && (cava.idle || !cava.running) && !Plasmoid.expanded && !editMode && !cava.hasError ? PlasmaCore.Types.HiddenStatus : PlasmaCore.Types.ActiveStatus;
4242
}
4343
onExpandedChanged: {
4444
Utils.delay(1000, updateStatus, main);

0 commit comments

Comments
 (0)