new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Electron · API · all subjects

notifications

12 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Main process notifications using Electron Notification module

Main process notifications are displayed using Electron's Notification module. Notification objects created with this module do not appear unless their show() instance method is called.

Renderer process notifications using web Notifications API

Notifications can be displayed directly from the renderer process with the web Notifications API.

Windows notification requirements with AppUserModelID and ToastActivatorCLSID

For notifications on Windows, an Electron app needs to have a Start Menu shortcut with an AppUserModelID and a corresponding ToastActivatorCLSID. Electron attempts to automate this work. When Electron is used with Squirrel.Windows, shortcuts will automatically be set correctly. In production, Electron will detect Squirrel and automatically call app.setAppUserModelId() with the correct value. During development, you may need to call app.setAppUserModelId() yourself.

macOS notification requirements - code signing

For notifications on macOS, an application must be code-signed in order for notification events to emit correctly. This requirement stems from the underlying UNNotification API provided by Apple. Unsigned binaries will emit a 'failed' event when notification APIs are called.

macOS notification size limit

Notifications on macOS are limited to 256 bytes in size and will be truncated if you exceed that limit.

Linux notifications using libnotify

On Linux, notifications are sent using libnotify, which can show notifications on any desktop environment that follows the Desktop Notifications Specification, including Cinnamon, Enlightenment, Unity, GNOME, and KDE.

Main process notification example

const { Notification } = require('electron') const NOTIFICATION_TITLE = 'Basic Notification' const NOTIFICATION_BODY = 'Notification from the Main process' new Notification({ title: NOTIFICATION_TITLE, body: NOTIFICATION_BODY }).show()

Renderer process notification example with click handler

const NOTIFICATION_TITLE = 'Title' const NOTIFICATION_BODY = 'Notification from the Renderer process. Click to log to console.' const CLICK_MESSAGE = 'Notification clicked' new Notification(NOTIFICATION_TITLE, { body: NOTIFICATION_BODY }).onclick = () => console.log(CLICK_MESSAGE)

Windows advanced notifications with electron-windows-notifications

Windows allows for advanced notifications with custom templates, images, and other flexible elements. To send those notifications from the main process, you can use the userland module electron-windows-notifications, which uses native Node addons to send ToastNotification and TileNotification objects.

Windows interactive notifications with electron-windows-interactive-notifications

While notifications including buttons work with electron-windows-notifications, handling replies requires the use of electron-windows-interactive-notifications, which helps with registering the required COM components and calling your Electron app with the entered user data.

Query Windows notification state with windows-notification-state module

To detect whether or not you're allowed to send a notification on Windows, use the userland module windows-notification-state. This module allows you to determine ahead of time whether or not Windows will silently throw the notification away.

Query macOS notification state with macos-notification-state module

To detect whether or not you're allowed to send a notification on macOS, use the userland module macos-notification-state. This module allows you to detect ahead of time whether or not the notification will be displayed.

Give your agent this brain