nova-shell/shell/services/SystemdService.qml

42 lines
1.2 KiB
QML

pragma Singleton
import QtQuick
import NovaStats as NS
// Thin wrapper around NS.SystemdService: drives the poll Timer and parses the
// JSON-encoded machine tree into a JS array for QML consumers.
QtObject {
id: root
readonly property string hostname: NS.SystemdService.hostname
readonly property int failedCount: NS.SystemdService.failedCount
// [{ name, isLocal, marker, systemState, runningCount, totalCount,
// failedUnits: [...], runningUnits: [...] }, ...]
readonly property var machines: {
try {
return JSON.parse(NS.SystemdService.machinesJson);
} catch (e) {
return [];
}
}
function restartUnit(name, scope, host, machine) {
NS.SystemdService.restartUnit(name, scope ?? "system", host ?? "", machine ?? "");
}
function refresh() {
NS.SystemdService.poll();
}
property Timer _pollTimer: Timer {
interval: {
const ms = NS.ModulesService.systemdInterval;
return ms > 0 ? ms : 15000;
}
running: NS.ModulesService.systemdEnable
repeat: true
triggeredOnStart: false
onTriggered: NS.SystemdService.poll()
}
}