battery: send notifications via dbus instead of internal service or notify-send

This commit is contained in:
Damocles 2026-04-29 18:18:42 +02:00
parent 88f14b26cd
commit 2acb4e70ad
3 changed files with 21 additions and 31 deletions

View file

@ -1,7 +1,7 @@
pragma Singleton pragma Singleton
import QtQuick import QtQuick
import Quickshell.Services.Notifications import Quickshell.Io
import Quickshell.Services.UPower import Quickshell.Services.UPower
import "." as S import "." as S
@ -62,14 +62,31 @@ QtObject {
if (root.percent < root.critThresh && !root._critSent) { if (root.percent < root.critThresh && !root._critSent) {
root._critSent = true; root._critSent = true;
root._warnSent = true; root._warnSent = true;
S.NotifService.send("Very Low Battery", "Connect to power now!", NotificationUrgency.Critical, "battery-low"); root._sendNotif(2, "battery-low", "Very Low Battery", "Connect to power now!");
} else if (root.percent < root.warnThresh && !root._warnSent) { } else if (root.percent < root.warnThresh && !root._warnSent) {
root._warnSent = true; root._warnSent = true;
S.NotifService.send("Low Battery", "", NotificationUrgency.Normal, "battery-caution"); root._sendNotif(1, "battery-caution", "Low Battery", "");
} }
} }
} }
// Send notification via D-Bus so any active daemon receives it
function _sendNotif(urgency, icon, summary, body) {
_notifProc.command = ["busctl", "--user", "call", "org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", "Notify", "susssasa{sv}i" // signature
, "nova-shell" // app_name
, "0" // replaces_id
, icon // app_icon
, summary // summary
, body // body
, "0" // actions (empty array)
, "1", "urgency", "y", String(urgency) // hints: urgency
, "-1" // expire_timeout
];
_notifProc.running = true;
}
property var _notifProc: Process {}
function fmtTime(secs) { function fmtTime(secs) {
if (!secs || secs <= 0) if (!secs || secs <= 0)
return ""; return "";

View file

@ -48,33 +48,6 @@ QtObject {
dnd = !dnd; 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() { function _changed() {
list = list.slice(); list = list.slice();
} }

View file

@ -84,7 +84,7 @@ shell/modules/WeatherModule.qml: Unqualified access [unqualified]
shell/modules/WindowTitleModule.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: Member "screen" not found on type "QObject" [missing-property]
shell/modules/WorkspacesModule.qml: Unqualified access [unqualified] shell/modules/WorkspacesModule.qml: Unqualified access [unqualified]
shell/services/NotifService.qml: Member "_expireTimer" not found on type "QObject" [missing-property] shell/services/BatteryService.qml: Unqualified access [unqualified]
shell/services/BluetoothService.qml: Unqualified access [unqualified] 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: 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] shell/services/LockService.qml: Unqualified access [unqualified]