From 88f14b26cddb22e72fc1f1b79541a84d54c5f825 Mon Sep 17 00:00:00 2001 From: Damocles Date: Wed, 29 Apr 2026 18:13:14 +0200 Subject: [PATCH] battery: use internal notification service instead of shelling out to notify-send --- shell/services/BatteryService.qml | 11 +++-------- shell/services/NotifService.qml | 27 +++++++++++++++++++++++++++ test/qmllint-baseline.txt | 2 +- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/shell/services/BatteryService.qml b/shell/services/BatteryService.qml index 2794f09..4154674 100644 --- a/shell/services/BatteryService.qml +++ b/shell/services/BatteryService.qml @@ -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 ""; diff --git a/shell/services/NotifService.qml b/shell/services/NotifService.qml index e3dde41..773ad7d 100644 --- a/shell/services/NotifService.qml +++ b/shell/services/NotifService.qml @@ -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(); } diff --git a/test/qmllint-baseline.txt b/test/qmllint-baseline.txt index ff9ca29..e5b7733 100644 --- a/test/qmllint-baseline.txt +++ b/test/qmllint-baseline.txt @@ -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]