Something went wrong. Try again.
Something went wrong. Try again.
8.6 kB 276 lines
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277pragma ComponentBehavior: Bound
import "../components"import ".."import QtQuickimport Quickshell.Widgets
ClippingRectangle { id: root
required property var barWindow property var ipc: null property bool moduleVisible: true property int interval: 10000 property string moduleName: "systemd-failed-units" property var systemUnits: [] property var userUnits: [] property string errorText: "" property string actionError: "" readonly property int systemCount: systemUnits.length readonly property int userCount: userUnits.length readonly property int totalCount: systemCount + userCount readonly property bool tooltipVisible: mouse.containsMouse
function refresh() { if (!moduleVisible || refreshRunner.running) return;
refreshRunner.run(); }
function runRestart() { if (actionRunner.running) return; actionError = ""; actionRunner.run(["restart"]); }
function applyOutput(output) { try { const data = JSON.parse(output); if (!data || typeof data.error !== "string" || !(data.systemUnits === null || Array.isArray(data.systemUnits)) || !(data.userUnits === null || Array.isArray(data.userUnits)) || ((data.systemUnits === null || data.userUnits === null) && !data.error)) throw new Error("Invalid service response"); if (Array.isArray(data.systemUnits)) systemUnits = data.systemUnits; if (Array.isArray(data.userUnits)) userUnits = data.userUnits; errorText = String(data.error || ""); } catch (error) { errorText = "Unable to read failed systemd services"; } }
implicitWidth: compactContent.implicitWidth + 20 implicitHeight: 34 radius: 8 color: mouse.containsMouse ? theme.surface2 : theme.alpha(theme.surface0, 0.28) border.color: theme.alpha(theme.red, 0.72) border.width: 1 contentUnderBorder: true visible: moduleVisible && (totalCount > 0 || errorText.length > 0 || actionError.length > 0)
Theme { id: theme }
Row { id: compactContent
anchors.centerIn: parent spacing: 6
Text { anchors.verticalCenter: parent.verticalCenter color: theme.red font.family: theme.fontFamily font.pixelSize: theme.barFontPixelSize text: "" textFormat: Text.PlainText }
Text { anchors.verticalCenter: parent.verticalCenter color: theme.red font.family: theme.fontFamily font.pixelSize: theme.barFontPixelSize text: root.totalCount > 0 ? String(root.totalCount) : "err" textFormat: Text.PlainText } }
BarPopup { id: tooltipWindow
barWindow: root.barWindow anchorItem: root shown: root.tooltipVisible implicitWidth: 360 implicitHeight: Math.min(480, detailsColumn.implicitHeight + 28)
PopupSurface { anchors.fill: parent clip: true
Flickable { anchors.fill: parent anchors.margins: 14 contentWidth: width contentHeight: detailsColumn.implicitHeight clip: true
Column { id: detailsColumn
width: parent.width spacing: 10
Row { width: parent.width spacing: 8
Text { anchors.verticalCenter: parent.verticalCenter color: theme.red font.family: theme.fontFamily font.pixelSize: theme.barFontPixelSize + 3 text: "" }
Column { width: parent.width - 30 spacing: 2
Text { width: parent.width color: theme.text font.family: theme.fontFamily font.pixelSize: theme.tooltipFontPixelSize + 1 font.bold: true text: root.errorText ? "Service check failed" : `${root.totalCount} failed systemd service${root.totalCount === 1 ? "" : "s"}` }
Text { width: parent.width color: theme.subtext0 font.family: theme.fontFamily font.pixelSize: theme.tooltipFontPixelSize text: "Left-click to restart, right-click to refresh" } } }
Text { width: parent.width visible: root.errorText.length > 0 || root.actionError.length > 0 text: [root.errorText, root.actionError].filter(value => value.length > 0).join("\n") color: theme.red font.family: theme.fontFamily font.pixelSize: theme.tooltipFontPixelSize wrapMode: Text.Wrap textFormat: Text.PlainText }
UnitSection { width: parent.width visible: root.systemCount > 0 title: `System services (${root.systemCount})` units: root.systemUnits }
UnitSection { width: parent.width visible: root.userCount > 0 title: `User services (${root.userCount})` units: root.userUnits } } } } }
component UnitSection: Column { id: sectionRoot
required property string title required property var units
spacing: 4
Text { width: parent.width color: theme.red font.family: theme.fontFamily font.pixelSize: theme.tooltipFontPixelSize font.bold: true text: sectionRoot.title }
Repeater { model: sectionRoot.units
Text { required property string modelData
width: sectionRoot.width color: theme.text elide: Text.ElideRight font.family: theme.fontFamily font.pixelSize: theme.tooltipFontPixelSize text: modelData textFormat: Text.PlainText } } }
MouseArea { id: mouse
anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton hoverEnabled: true z: 10 onClicked: event => { if (event.button === Qt.LeftButton) root.runRestart(); else if (event.button === Qt.RightButton) root.refresh(); } onContainsMouseChanged: { if (containsMouse) root.refresh(); } }
Timer { interval: root.interval running: root.moduleVisible && root.interval > 0 repeat: true onTriggered: root.refresh() }
HelperProcess { id: refreshRunner helper: "systemd-failed-units" onOutput: text => root.applyOutput(text) }
HelperProcess { id: actionRunner helper: "systemd-failed-units" onExited: exitCode => { root.actionError = exitCode === 0 ? "" : actionRunner.errorText.trim() || "Service restart failed"; root.refresh(); } }
Connections { function onRefreshRequested(name) { if (name === root.moduleName || name === "all") root.refresh(); }
target: root.ipc }
Component.onCompleted: refresh() onModuleVisibleChanged: { if (moduleVisible) refresh(); else { systemUnits = []; userUnits = []; errorText = ""; } }}