battery: use internal notification service instead of shelling out to notify-send
This commit is contained in:
parent
bc2d54c07a
commit
88f14b26cd
3 changed files with 31 additions and 9 deletions
|
|
@ -1,8 +1,7 @@
|
|||
pragma Singleton
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import Quickshell.Services.Notifications
|
||||
import Quickshell.Services.UPower
|
||||
import "." as S
|
||||
|
||||
|
|
@ -63,18 +62,14 @@ QtObject {
|
|||
if (root.percent < root.critThresh && !root._critSent) {
|
||||
root._critSent = true;
|
||||
root._warnSent = true;
|
||||
_notifProc.command = ["notify-send", "--urgency=critical", "--icon=battery-low", "--category=device", "Very Low Battery", "Connect to power now!"];
|
||||
_notifProc.running = true;
|
||||
S.NotifService.send("Very Low Battery", "Connect to power now!", NotificationUrgency.Critical, "battery-low");
|
||||
} else if (root.percent < root.warnThresh && !root._warnSent) {
|
||||
root._warnSent = true;
|
||||
_notifProc.command = ["notify-send", "--icon=battery-caution", "--category=device", "Low Battery"];
|
||||
_notifProc.running = true;
|
||||
S.NotifService.send("Low Battery", "", NotificationUrgency.Normal, "battery-caution");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
property var _notifProc: Process {}
|
||||
|
||||
function fmtTime(secs) {
|
||||
if (!secs || secs <= 0)
|
||||
return "";
|
||||
|
|
|
|||
|
|
@ -48,6 +48,33 @@ QtObject {
|
|||
dnd = !dnd;
|
||||
}
|
||||
|
||||
// Internal notifications - no D-Bus roundtrip needed
|
||||
property int _nextInternalId: -1
|
||||
|
||||
function send(summary, body, urgency, appIcon) {
|
||||
const id = _nextInternalId--;
|
||||
const item = _itemComp.createObject(root, {
|
||||
id: id,
|
||||
summary: summary,
|
||||
body: body || "",
|
||||
appName: "nova-shell",
|
||||
appIcon: appIcon || "",
|
||||
image: "",
|
||||
hints: {},
|
||||
urgency: urgency ?? NotificationUrgency.Normal,
|
||||
actions: [],
|
||||
time: Date.now(),
|
||||
popup: true
|
||||
});
|
||||
|
||||
_byId[id] = item;
|
||||
list = [item, ...list];
|
||||
|
||||
const timeout = Modules.notifications.timeout || 3000;
|
||||
item._expireTimer.interval = urgency === NotificationUrgency.Critical ? timeout * 3 : timeout;
|
||||
item._expireTimer.running = true;
|
||||
}
|
||||
|
||||
function _changed() {
|
||||
list = list.slice();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ shell/modules/WeatherModule.qml: Unqualified access [unqualified]
|
|||
shell/modules/WindowTitleModule.qml: Unqualified access [unqualified]
|
||||
shell/modules/WorkspacesModule.qml: Member "screen" not found on type "QObject" [missing-property]
|
||||
shell/modules/WorkspacesModule.qml: Unqualified access [unqualified]
|
||||
shell/services/BatteryService.qml: Unqualified access [unqualified]
|
||||
shell/services/NotifService.qml: Member "_expireTimer" not found on type "QObject" [missing-property]
|
||||
shell/services/BluetoothService.qml: Unqualified access [unqualified]
|
||||
shell/services/LockService.qml: Type QProcess::ExitStatus of parameter exitStatus in signal called exited was not found, but is required to compile onExited. Did you add all imports and dependencies? [signal-handler-parameters]
|
||||
shell/services/LockService.qml: Unqualified access [unqualified]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue