A DBus-based NodeJS library for desktop notifications.
Use the DBus interface org.freedesktop.Notifications
to create notifications instead of using notify-send
, making it possible to provide full-featured support for desktop notifications on Linux (or any DBus-enabled system) and conform to the Desktop Notifications Specification.
Implementation Specification Version: 1.2
Using npm: npm install node-dbus-notifier --save
or
Using yarn: yarn add node-dbus-notifier
Make sure your current system supports DBus and has a provider that conforms to the Desktop Notifications Specification before using it.
const { Notify } = require('node-dbus-notifier');
const notify = new Notify({
appName: 'My App',
summary: 'This is summary',
body: 'This is body',
timeout: 3000,
});
notify.show()
.then((result) => {
console.log(`notify is closed: ${JSON.stringify(result)}`);
});
const { Notify } = require('node-dbus-notifier');
const notify = new Notify({
appName: 'My App',
appIcon: 'application-javascript', // The availability of icons depends on the current system icon set.
summary: 'This is summary',
body: 'This is body',
timeout: 3000,
});
notify.addAction('Click Me', () => {
console.log('Click Click');
});
notify.show();
const { Notify } = require('node-dbus-notifier');
const notify = new Notify({
appName: 'My App',
summary: 'This is summary',
body: 'This is body',
hints: {
imagePath: '/path/to/image',
},
timeout: 3000,
});
notify.show();
See the DBus protocol of the Desktop Notifications Specification for more information.
The node-dbus-notifier creates a DBus session by default when the first notification is displayed and disconnects the DBus session when there are no notifications; if the session is not disconnected, the app will not exit properly.
If an external DBus session or interface is set, it will not auto disconnect the DBus session.
inline-reply
: Add inline reply input box to the notification, the first parameter of the callback function is the submitted message.
-
constructor(config: Partial<NotifyConfig>)
: Initialize a notification, accepting the same parameters asorg.freedesktop.Notifications.Notify
, except foractions
(usingaddAction()
).hints
does not support attributes marked as "Deprecated". -
addAction(text: string, callback: () => void): string
: Add an action to the notification with random action key, return action key. -
addAction(text: string, key: string, callback: () => void): string
: Add an action to notification with custom action key, return action key. -
close(): void
: Useorg.freedesktop.Notifications.CloseNotification
actively close notification. -
removeAction(key: string): boolean
: Use action key remove an added action -
removeDefaultAction(): boolean
: Alias forremoveAction("default")
. -
setDefaultAction(callback: () => void): void
: Alias foraddAction("", "default", callback)
. (The 'Default' action trigger is the click notification.) -
show()
: Useorg.freedesktop.Notifications.Notify
to display the notification and mark the Promise as resolved when the notification is dismissed. -
event: close
: Notification is closed -
event: show
: Notification is displayed -
static supportedCapabilities(): Promise<string[]>
: The capabilities supported by the notification server.
autoDisconnectSessionBus
: If set tofalse
, the internal DBus session will not be automatically disconnected. Defaults totrue
, if there is no notification, the internal DBus session will be automatically disconnected.
Disconnect the internal DBus session.
You shouldn't use it anywhere unless you set Config.autoDisconnectSessionBus
to false
or need to exit the app immediately.
Get DBus interface org.freedesktop.Notifications
.
If the interface is set from outside, it will return the external interface.
if you want to do something
Set DBus interface org.freedesktop.Notifications
.
Set up an org.freedesktop.Notifications
interface externally if you want to share an existing DBus interface.
If no arguments are passed, the internal interface will be reused.
Get DBus Session.
If the session is set from outside, it will return the external session.
if you want to do something
Set DBus session.
Set up an DBus session externally if you want to share an existing DBus session.
If no arguments are passed, the internal session will be reused.
I don't recommend you use
getInterface()
orgetSessionBus()
anywhere, they are actually created more for internal code and exporting them is just for special cases.
Thanks to dbusjs/node-dbus-next for the DBus session support.
Thanks to JetBrains for providing the JetBrains IDEs open source license.