Notifications (window.Electron.notifications)
Real OS notifications (Notification Center on macOS, Action Center on Windows, libnotify on Linux) — not the web Notification API, so these work even when the window isn't focused. Source: src/main/notifications.ts, channel prefix notifications:*. Always on, no config needed.
Use this instead of the web API for macOS reply fields and action buttons, Linux urgency levels, or a click/close event round-trip that isn't at the mercy of whether the page still has focus. Every event is broadcast to all open windows, not just the one that created the notification — a notification can legitimately be clicked long after its owning window closed.
Methods
| Method | Returns | Notes |
|---|---|---|
isSupported() |
Promise<boolean> |
|
show(options: ShowNotificationOptions) |
Promise<string> |
Shows immediately, resolves the notification's id (for close()/event matching). Throws VALIDATION if title is missing. |
close(id: string) |
Promise<void> |
No-op if id is no longer active. |
on(callback: (event: NotificationEvent) => void) |
() => void (unsubscribe) |
Fires for every notification's show/click/close/reply/action/failed events. |
ShowNotificationOptions
| Field | Type | Notes |
|---|---|---|
title |
string |
Required. |
body |
string |
|
subtitle |
string |
macOS only — shown under the title. |
silent |
boolean |
Suppress the notification sound. Default false. |
hasReply |
boolean |
macOS only — shows a text-reply field. |
replyPlaceholder |
string |
macOS only. |
actions |
Array<{ type: 'button'; text: string }> |
macOS only — extra action buttons. |
urgency |
'normal' | 'critical' | 'low' |
Linux only. |
NotificationEvent
{ id, type: 'show' | 'click' | 'close' | 'reply' | 'action' | 'failed', data? } — data is the typed reply text for 'reply', or the action button index for 'action'.
Example
const id = await window.Electron.notifications.show({ title: 'Export finished' });
const unsubscribe = window.Electron.notifications.on((event) => {
if (event.id === id && event.type === 'click') showExportFolder();
});
.safe
Partial. isSupported, show, close are wrapped — window.Electron.safe.notifications.* resolves { ok: true, data } / { ok: false, error } instead of throwing. on() is the same function on both surfaces (event subscription, never throws).