1- import { Message , MessageType , sessionBus , type MessageBus } from "dbus-next" ;
1+ import { Message , sessionBus , type MessageBus } from "dbus-next" ;
22
33const DBUS = "org.freedesktop.DBus" ;
4- const DBUS_PATH = "/org/freedesktop/DBus" ;
54const 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 */
1312export 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