extract IdleInhibitService singleton from IdleInhibitorModule
This commit is contained in:
parent
de35cf016c
commit
07dfbb1337
3 changed files with 39 additions and 27 deletions
|
|
@ -1,51 +1,31 @@
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Io
|
|
||||||
import "." as M
|
import "." as M
|
||||||
import "../services" as S
|
import "../services" as S
|
||||||
|
|
||||||
M.BarIcon {
|
M.BarIcon {
|
||||||
id: root
|
id: root
|
||||||
color: root.active ? S.Theme.base09 : root.accentColor
|
color: S.IdleInhibitService.active ? S.Theme.base09 : root.accentColor
|
||||||
tooltip: {
|
tooltip: {
|
||||||
const parts = ["Idle inhibition: " + (root.active ? "active" : "inactive")];
|
const parts = ["Idle inhibition: " + (S.IdleInhibitService.active ? "active" : "inactive")];
|
||||||
if (root._inhibitors)
|
if (S.IdleInhibitService.inhibitors)
|
||||||
parts.push(root._inhibitors);
|
parts.push(S.IdleInhibitService.inhibitors);
|
||||||
return parts.join("\n");
|
return parts.join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
property bool active: false
|
icon: S.IdleInhibitService.active ? "\uF06E" : "\uF070"
|
||||||
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() : ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
interval: 5000
|
interval: 5000
|
||||||
running: root._hovered
|
running: root._hovered
|
||||||
repeat: true
|
repeat: true
|
||||||
triggeredOnStart: true
|
triggeredOnStart: true
|
||||||
onTriggered: listProc.running = true
|
onTriggered: S.IdleInhibitService.refreshInhibitors()
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: root.active = !root.active
|
onClicked: S.IdleInhibitService.toggle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
31
shell/services/IdleInhibitService.qml
Normal file
31
shell/services/IdleInhibitService.qml
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
pragma Singleton
|
||||||
|
|
||||||
|
import QtQuick
|
||||||
|
import Quickshell.Io
|
||||||
|
|
||||||
|
QtObject {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
property bool active: false
|
||||||
|
property string inhibitors: ""
|
||||||
|
|
||||||
|
function toggle() {
|
||||||
|
active = !active;
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshInhibitors() {
|
||||||
|
_listProc.running = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
property Process _inhibitor: Process {
|
||||||
|
command: ["systemd-inhibit", "--what=idle", "--who=nova-shell", "--why=user", "sleep", "infinity"]
|
||||||
|
running: root.active
|
||||||
|
}
|
||||||
|
|
||||||
|
property Process _listProc: Process {
|
||||||
|
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() : ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,3 +11,4 @@ singleton BacklightService 1.0 BacklightService.qml
|
||||||
singleton MprisService 1.0 MprisService.qml
|
singleton MprisService 1.0 MprisService.qml
|
||||||
singleton NetworkService 1.0 NetworkService.qml
|
singleton NetworkService 1.0 NetworkService.qml
|
||||||
singleton BluetoothService 1.0 BluetoothService.qml
|
singleton BluetoothService 1.0 BluetoothService.qml
|
||||||
|
singleton IdleInhibitService 1.0 IdleInhibitService.qml
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue