extract IdleInhibitService singleton from IdleInhibitorModule

This commit is contained in:
Damocles 2026-04-18 10:39:37 +02:00
parent de35cf016c
commit 07dfbb1337
3 changed files with 39 additions and 27 deletions

View file

@ -1,51 +1,31 @@
import QtQuick
import Quickshell
import Quickshell.Io
import "." as M
import "../services" as S
M.BarIcon {
id: root
color: root.active ? S.Theme.base09 : root.accentColor
color: S.IdleInhibitService.active ? S.Theme.base09 : root.accentColor
tooltip: {
const parts = ["Idle inhibition: " + (root.active ? "active" : "inactive")];
if (root._inhibitors)
parts.push(root._inhibitors);
const parts = ["Idle inhibition: " + (S.IdleInhibitService.active ? "active" : "inactive")];
if (S.IdleInhibitService.inhibitors)
parts.push(S.IdleInhibitService.inhibitors);
return parts.join("\n");
}
property bool active: false
property string _inhibitors: ""
icon: root.active ? "\uF06E" : "\uF070"
Process {
id: inhibitor
command: ["systemd-inhibit", "--what=idle", "--who=nova-shell", "--why=user", "sleep", "infinity"]
running: root.active
}
// Poll current inhibitors
Process {
id: listProc
running: true
command: ["sh", "-c", "systemd-inhibit --list 2>/dev/null | grep -i idle | awk '{print $NF}' | sort -u | tr '\\n' ', ' | sed 's/, $//'"]
stdout: StdioCollector {
onStreamFinished: root._inhibitors = text.trim() ? "Blocked by: " + text.trim() : ""
}
}
icon: S.IdleInhibitService.active ? "\uF06E" : "\uF070"
Timer {
interval: 5000
running: root._hovered
repeat: true
triggeredOnStart: true
onTriggered: listProc.running = true
onTriggered: S.IdleInhibitService.refreshInhibitors()
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: root.active = !root.active
onClicked: S.IdleInhibitService.toggle()
}
}