Skip to content

Commit 3d70a7b

Browse files
fix(desktop): keep notifications after an idle-exit notification daemon quits
AI-assisted; verified with the tests and tools listed above.
1 parent 3d2f505 commit 3d70a7b

2 files changed

Lines changed: 13 additions & 50 deletions

File tree

‎apps/desktop/src/electron/LinuxNotificationService.test.ts‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,18 @@ it("keeps notifications off after activation fails and probes again on the next
9898
service.stop();
9999
});
100100

101-
it("withdraws notifications when the notification service exits or the bus fails", async () => {
101+
it("keeps notifications after an idle-exit daemon quits and withdraws them when the bus fails", async () => {
102102
const bus = new FakeBus();
103103
const service = watch(bus);
104-
expect(bus.calls[0]).toMatchObject({
105-
member: "AddMatch",
106-
body: [expect.stringContaining("arg0='org.freedesktop.Notifications'")],
107-
});
108104

109105
await bus.answer(0, 1);
110106
expect(service.available()).toBe(true);
111107

112-
bus.nameOwnerChanged(":1.42", ":1.43");
113-
expect(service.available()).toBe(true);
114-
115-
bus.nameOwnerChanged(":1.43", "");
116-
expect(service.available()).toBe(false);
117-
expect(bus.probes).toHaveLength(2);
118-
119-
await bus.answer(1, 1);
108+
// Idle-exit daemons such as mate-notification-daemon drop their name after 30 idle seconds
109+
// and are reactivated quickly by the next notification.
110+
bus.nameOwnerChanged(":1.42", "");
120111
expect(service.available()).toBe(true);
112+
expect(bus.probes).toHaveLength(1);
121113

122114
bus.emit("error", new Error("connection reset"));
123115
expect(service.available()).toBe(false);

‎apps/desktop/src/electron/LinuxNotificationService.ts‎

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import { Message, MessageType, sessionBus, type MessageBus } from "dbus-next";
1+
import { Message, sessionBus, type MessageBus } from "dbus-next";
22

33
const DBUS = "org.freedesktop.DBus";
4-
const DBUS_PATH = "/org/freedesktop/DBus";
54
const NOTIFICATIONS = "org.freedesktop.Notifications";
65

76
/**
87
* Tracks whether the desktop notification service answers on the session bus. Electron shows
98
* notifications through libnotify on its main thread, which blocks until the bus gives up
10-
* activating a service that never claims its name, so callers must only notify while this has
11-
* seen the service running.
9+
* activating a service that never claims its name, so callers must only notify once this has
10+
* seen the service start.
1211
*/
1312
export function watchLinuxNotificationService(bus: MessageBus = sessionBus()) {
1413
let available = false;
@@ -25,7 +24,7 @@ export function watchLinuxNotificationService(bus: MessageBus = sessionBus()) {
2524
.call(
2625
new Message({
2726
destination: DBUS,
28-
path: DBUS_PATH,
27+
path: "/org/freedesktop/DBus",
2928
interface: DBUS,
3029
member: "StartServiceByName",
3130
signature: "su",
@@ -34,38 +33,11 @@ export function watchLinuxNotificationService(bus: MessageBus = sessionBus()) {
3433
)
3534
.then(settle(true), settle(false));
3635
};
37-
// The next notification would reactivate a daemon that exited, so losing it withdraws
38-
// availability until a fresh probe sees the service running again.
39-
const onMessage = (message: Message) => {
40-
if (
41-
message.type === MessageType.SIGNAL &&
42-
message.interface === DBUS &&
43-
message.member === "NameOwnerChanged" &&
44-
message.body[0] === NOTIFICATIONS &&
45-
message.body[2] === ""
46-
)
47-
available = false;
48-
};
49-
const onError = () => {
36+
// Once started, the service stays activatable: idle-exit daemons such as MATE's quit and are
37+
// restarted quickly on the next notification, so only a failing bus withdraws availability.
38+
bus.on("error", () => {
5039
available = false;
51-
};
52-
53-
bus.on("error", onError);
54-
bus.on("message", onMessage);
55-
bus
56-
.call(
57-
new Message({
58-
destination: DBUS,
59-
path: DBUS_PATH,
60-
interface: DBUS,
61-
member: "AddMatch",
62-
signature: "s",
63-
body: [
64-
`type='signal',sender='${DBUS}',interface='${DBUS}',member='NameOwnerChanged',arg0='${NOTIFICATIONS}'`,
65-
],
66-
}),
67-
)
68-
.catch(() => undefined);
40+
});
6941
probe();
7042

7143
return {
@@ -75,7 +47,6 @@ export function watchLinuxNotificationService(bus: MessageBus = sessionBus()) {
7547
},
7648
stop: () => {
7749
closed = true;
78-
bus.removeListener("message", onMessage);
7950
bus.disconnect();
8051
},
8152
};

0 commit comments

Comments
 (0)