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 · Tutorial · all subjects

device-access

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

setPermissionCheckHandler for HID

The ses.setPermissionCheckHandler(handler) API can be used to disable HID access for specific origins.

setDevicePermissionHandler for HID

The ses.setDevicePermissionHandler(handler) API can be used to provide default permissioning to HID devices without first calling for permission via navigator.hid.requestDevice. Electron stores granted device permission through the lifetime of the corresponding WebContents by default, but longer-term storage can be implemented by developers storing permissions manually.

Web Bluetooth API device selection

To use the Web Bluetooth API in Electron, developers must handle the 'select-bluetooth-device' event on the webContents associated with the device request.

Bluetooth pairing handler on Windows and Linux

The ses.setBluetoothPairingHandler(handler) API can be used to handle pairing to bluetooth devices on Windows or Linux when additional validation such as a PIN is needed.

WebHID API device selection

The 'select-hid-device' event on the Session can be used to select a HID device when a call to navigator.hid.requestDevice is made.

WebHID device added and removed events

The 'hid-device-added' and 'hid-device-removed' events on the Session can be used to handle devices being plugged in or unplugged when handling the 'select-hid-device' event. These events only fire until the callback from 'select-hid-device' is called and are not intended to be used as a generic HID device listener.

HID blocklist override

Electron uses the same blocklist as Chromium for HID devices by default. To override this behavior, set the 'disable-hid-blocklist' flag using app.commandLine.appendSwitch('disable-hid-blocklist').

Web Serial API device selection

To use the Web Serial API in Electron, developers must handle the 'select-serial-port' event on the Session associated with the serial port request.

Serial port added and removed events

The 'serial-port-added' and 'serial-port-removed' events on the Session can be used to handle devices being plugged in or unplugged when handling the 'select-serial-port' event. These events only fire until the callback from 'select-serial-port' is called and are not intended to be used as a generic serial port listener.

setDevicePermissionHandler for serial

The ses.setDevicePermissionHandler(handler) API can be used to provide default permissioning to serial devices without first calling for permission via navigator.serial.requestPort. Electron stores granted device permission through the lifetime of the corresponding WebContents by default, but longer-term storage can be implemented by developers storing permissions manually.

setPermissionCheckHandler for serial

The ses.setPermissionCheckHandler(handler) API can be used to disable serial access for specific origins.

Serial blocklist override

Electron uses the same blocklist as Chromium for serial devices by default. To override this behavior, set the 'disable-serial-blocklist' flag using app.commandLine.appendSwitch('disable-serial-blocklist').

WebUSB API device selection

The 'select-usb-device' event on the Session can be used to select a USB device when a call to navigator.usb.requestDevice is made.

USB device added and removed events

The 'usb-device-added' and 'usb-device-removed' events on the Session can be used to handle devices being plugged in or unplugged when handling the 'select-usb-device' event. These events only fire until the callback from 'select-usb-device' is called and are not intended to be used as a generic USB device listener.

USB device revoked event

The 'usb-device-revoked' event on the Session can be used to respond when device.forget() is called on a USB device.

setDevicePermissionHandler for USB

The ses.setDevicePermissionHandler(handler) API can be used to provide default permissioning to USB devices without first calling for permission via navigator.usb.requestDevice. Electron stores granted device permission through the lifetime of the corresponding WebContents by default, but longer-term storage can be implemented by developers storing permissions manually.

setPermissionCheckHandler for USB

The ses.setPermissionCheckHandler(handler) API can be used to disable USB access for specific origins.

setUSBProtectedClassesHandler

The ses.setUSBProtectedClassesHandler(handler) API can be used to allow usage of protected USB classes that are not available by default.

USB blocklist override

Electron uses the same blocklist as Chromium for USB devices by default. To override this behavior, set the 'disable-usb-blocklist' flag using app.commandLine.appendSwitch('disable-usb-blocklist').

Main process notifications use Electron Notification module

Notifications displayed from the main process use Electron's Notification module. Notification objects created with this module do not appear unless their show() instance method is called.

Renderer process notifications use web Notifications API

Notifications can be displayed directly from the renderer process using the web Notifications API, which is part of the browser's standard APIs.

Main process notification example code

This example shows how to create and display a notification from the main process: 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 code

This example shows how to create a notification from the renderer process with an onclick 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 notifications require Start Menu shortcut with AppUserModelID

For notifications on Windows, an Electron app needs a Start Menu shortcut with an AppUserModelID and a corresponding ToastActivatorCLSID. Electron attempts to automate this when used with Squirrel.Windows. During development, you may need to call app.setAppUserModelId() manually.

Squirrel.Windows automatically sets up notification prerequisites

When Electron is used with Squirrel.Windows (such as with electron-winstaller), shortcuts are automatically set correctly. In production, Electron detects Squirrel was used and automatically calls app.setAppUserModelId() with the correct value.

macOS notifications require code signing

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

macOS notifications limited to 256 bytes

Notifications on macOS are limited to 256 bytes in size and will be truncated if exceeded.

Linux notifications use 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.

Advanced Windows notifications with electron-windows-notifications

Windows supports advanced notifications with custom templates, images, and flexible elements. The userland module electron-windows-notifications uses native Node addons to send ToastNotification and TileNotification objects.

Interactive Windows notifications require electron-windows-interactive-notifications

For notifications with buttons and reply handling on Windows, use the electron-windows-interactive-notifications module, which helps register required COM components and calls the Electron app with entered user data.

Use windows-notification-state to query notification permissions

On Windows, use the windows-notification-state userland module to detect ahead of time whether the OS will allow sending a notification or will silently discard it.

Use macos-notification-state to query notification permissions

On macOS, use the macos-notification-state userland module to detect ahead of time whether the notification will be displayed.

Give your agent this brain