deno_notify
Send desktop notifications on all platforms in Deno.
Supports Windows, macOS, and linux using notify-rust though some features are platform-specific.
Note: More features are in the works and the API may change as a result.
Usage
The mod.ts
entrypoint uses Plug internally so you don’t have to download or open the plugin manually.
You will need to run using the --unstable
and --allow-all
permissions to allow for automatic plugin loading and caching.
import { Notification } from "https://deno.land/x/deno_notify@1.0.0/ts/mod.ts";
// Create a new notification
const notif = new Notification();
// Add a simple message
notif.title('My message');
// Display it
notif.show();
Platform-Specific Features
By default, only cross-platform features are available. In order to enable platform-specific features (e.g. icons), you can pass in booleans flags to specify the supported platforms in the Notification
’s constructor.
// Enable linux-specific-features
const notif = new Notification({ linux: true });
// Notification.icon() is now available
notif.icon('/path/to/icon');
Specifying platforms may also provide different documentation and typings for the Notification
API.
For example, macOS has specific sound names that are available for Notifications; these are reflected in the macOS-specific Notification API.
Strict Platform Checking
The second parameter of the Notification
’s constructor can be used to determine whether the platform-features should be checked at runtime. When true
(default), any platform-specific feature will error if used on a platform that does not support it. When false
, the error will be silently ignored.
Note: Platform checking is performed both at compile time (TypeScript) and at runtime.
// Icons are not supported on macOS
// If notif.icon() is called on a macOS computer, this will error.
const notif = new Notification({ linux: true }, true);
notif.icon('/path/to/icon');
// This will not error; however, no icon will be displayed on macOS.
const notif = new Notification({ linux: true }, false);
notif.icon('/path/to/icon');
TODO
- Integrate my mac-notification-sys changes into notify-rust so I can add more cross-platform features.
- Find a way to test in GH actions for Linux & Windows
- Find out why Windows notifications only appear in action center
Known Issues
- Many platform-specific features are not implemented
- Features like actions, subtitle, hints, etc.
- Custom app icons are only applied if the notification requesting it is the first one being sent on mac
- This means an app icon cannot be changed once set, and cannot be changed even if it wasn’t set in the first one.
- Using a custom app icon on mac sometimes crashes
- From my own experience, this seems to happen with non-default applications.
- See this GitHub issue for more information
Resources & Credits
- Notification system from notify-rust
- Plugin import from deno-plugin-prepare
- Plugin system inspired by deno_webview and deno_sqlite_plugin
- GH Issue to check out later