♾️ Toasted Notifier ♾️
Toasted Notifier is a forked version of node-notifier which has been updated with various changes. It allows for you to display push notifications within your application for Windows, Linux, and macOS.
This library is packaged with ntfy-desktop
About
Toasted Notifier allows you to send cross platform native notifications using Node.js, and works well with Electron.
This node package toasted-notifier contains a combination of supported notification vendors, which allows a user on any operating system to use this package in their application. The following list shows all of the notification vendors this package supports, which operating system it is for, and the filename for where the code belonging to that notification system can be found in this package:
| Notification API | Operating System | File | View Docs |
|---|---|---|---|
| WindowToaster | Windows 8, 10, and 11 |
notifiers\toaster.js |
view |
| WindowsBalloon | Windows XP / 7 |
notifiers\balloon.js |
view |
| NotifySend | Linux |
notifiers\notifysend.js |
view |
| NotificationCenter | macOS / OS X |
notifiers\notificationcenter.js |
view |
| Growl | macOS / OS X, Windows |
notifiers\growl.js |
view |
When you include toasted-notifier in your node project, the API will automatically detect what operating system you are running your application on. Depending on the operating system, Toasted Notifier will call the correct notification package that it will use to show your coded notifications. The following outlines how the package acts and what it takes into consideration:
- NotificationCenter: macOS
- This package will be used if you are running on macOS >= 10.8 or newer.
- If running on an older version of macOS, Growl will be used instead.
- Messages sent using
terminal-notify
- NotifySend: Linux / Unix
- Notifications will be shown using
notify-osdorlibnotify-bin; which must be installed on your Linux system. - Ubuntu should have one of these packages by default
- Notifications will be shown using
- WindowToaster: Microsoft Windows 8, 9, 10, 11+
- WindowsBalloon: Windows XP, 7
- Growl as fallback if Windows Balloon notifications cannot be called
- Growl takes precedence over Windows balloons
- Growl: macOS, Windows
- This notification system is called if none of the requirements for the other notification vendors are met
What is ntfy-toast
This node package toasted-notifier utilizes a custom built library known as ntfy-toast in order to show notifications on a user's system.
When you add this node package to your application and send a notification, data will be sent from this node package toasted-notifier over to ntfy-toast with the details about what the notification should say to the user. Think of toasted-notifier as a wrapper that handles the communication between your app, and the notification app itself. toasted-notifier will do all of the talking between your app and ntfy-toast each time a notification is triggered to be sent.
ntfy-toast is based on SnoreToast, but has been updated with numerous new features.
Features
- Notification support for Windows XP - 11, Linux, and MacOS.
- Windows custom appID support for branding
- Persistent notifications keep a message on-screen until the user dismisses it
- No change in code if coming over from node-notifier
- Customize sounds and icons
Install
Simply install it using:
npm install --save toasted-notifier
Usage
Information and examples for implementing notifications:
[!NOTE] We have provided numerous written examples that you can view by going to the example folder of our repo:
Cross-Platform Advanced Usage
If you wish to ensure that your node application supports all operating systems, (Windows, Linux, Mac), you can use the following javascript as an example to build your notifications around:
const toasted = require('toasted-notifier');
const path = require('path');
toasted.notify(
{
title: 'Notification Title',
message: 'This is a message',
icon: path.join(__dirname, 'example_1.png'), // Absolute path (doesn't work on balloons)
sound: true, // Only Notification Center or Windows Toasters
wait: true // Wait on callback until user interacts, does not apply to Windows Toasters as they always wait or notify-send as it does not support the wait option
},
( error, response, metadata ) =>
{
// Response is response from notification
// Metadata contains activationType, activationAt, deliveredAt
}
);
toasted.on('click', function (obj, options, event) {
// Triggers if `wait: true` and user clicks notification
});
toasted.on('timeout', function (obj, options) {
// Triggers if `wait: true` and notification closes
});
Fine-grained Control
If you want super fine-grained control for each vendor; you can call them individually. This allows you to tune specific options for the different vendors.
See below for documentation on each notification vendor.
/*
create option structure
*/
const options =
{
withFallback: true, // try Windows Toast and Growl first?
customPath: undefined // relative / absolute path if you want to use your own fork
};
/*
send notification to users running macOS 10.8 or newer
*/
const NotificationCenter = require('toasted-notifier/notifiers/notificationcenter');
new NotificationCenter(options).notify();
/*
send notification to users running Linux
*/
const NotifySend = require('toasted-notifier/notifiers/notifysend');
new NotifySend(options).notify();
/*
send notification to users running Windows 8, 10, 11
*/
const WindowsToaster = require('toasted-notifier/notifiers/toaster');
new WindowsToaster(options).notify();
/*
send notification to users running Windows XP or 7
*/
const WindowsBalloon = require('toasted-notifier/notifiers/balloon');
new WindowsBalloon(options).notify();
/*
send notification to users running Windows or macOS
this is the fallback used if the above notification vendors aren't available.
*/
const Growl = require('toasted-notifier/notifiers/growl');
new Growl(options).notify();
If you're using several vendors:
// NOTE: Technically, this takes longer to require
const tn = require('toasted-notifier');
new tn.NotificationCenter(options).notify();
new tn.NotifySend(options).notify();
new tn.WindowsToaster(options).notify(options);
new tn.WindowsBalloon(options).notify(options);
new tn.Growl(options).notify(options);
Specific Vendor Documentation
To see information about each specific vendor and operating system, select one below:
The following different types of notifications are listed below:
| Notification API | Operating System | File | View Docs |
|---|---|---|---|
| WindowToaster | Windows 8, 10, and 11 |
notifiers\toaster.js |
view |
| WindowsBalloon | Windows XP / 7 |
notifiers\balloon.js |
view |
| NotifySend | Linux |
notifiers\notifysend.js |
view |
| NotificationCenter | macOS / OS X |
notifiers\notificationcenter.js |
view |
| Growl | macOS / OS X |
notifiers\growl.js |
view |
NotificationCenter
- A Node.js wrapper for terminal-notify (with fallback).
- Code available at:
node_modules\toasted-notifier\notifiers\notificationcenter.js - Requires macOS version 10.8 or higher; otherwise the fallback is Growl. If growl is not installed, an error will be returned in the callback.
Since toasted-notifier wraps around terminal-notifier, you can do anything terminal-notifier can by passing properties to the method.
- if
terminal-notifiersays-message, you can do{message: 'Foo'} - if
terminal-notifiersays-list ALL, you can do{list: 'ALL'}
Notification is the primary focus of this module, so listing and activating do work, but they aren't documented.
const NotificationCenter = require('toasted-notifier').NotificationCenter;
const toasted = new NotificationCenter(
{
withFallback: false, // Use Growl Fallback if <= 10.8
customPath: undefined // Relative/Absolute path to binary if you want to use your own fork of terminal-notifier
});
toasted.notify(
{
title: undefined,
subtitle: undefined,
message: undefined,
sound: false, // Case Sensitive string for location of sound file, or use one of macOS' native sounds (see below)
icon: 'Terminal Icon', // Absolute Path to Triggering Icon
contentImage: undefined, // Absolute Path to Attached Image (Content Image)
open: undefined, // URL to open on Click
wait: false, // Wait for User Action against Notification or times out. Same as timeout = 5 seconds
// New in latest version. See `example/macInput.js` for usage
timeout: 5, // Takes precedence over wait if both are defined.
closeLabel: undefined, // String. Label for cancel button
actions: undefined, // String | Array<String>. Action label or list of labels in case of dropdown
dropdownLabel: undefined, // String. Label to be used if multiple actions
reply: false // Boolean. If notification should take input. Value passed as third argument in callback and event emitter.
},
( error, response, metadata ) =>
{
console.log( response, metadata );
}
);
[!NOTE] The wait option is shorthand for
timeout: 5. This just sets a timeout for 5 seconds. It does not make the notification stick until the user interacts with it.macOS Notifications:
icon,contentImage, and all forms ofreply/actionsrequire macOS 10.9.
Default timeout is 10 to ensure that the application closes properly. To remove the timeout and have notifications instantly close (does not support actions), set timeout: false. If you are using an action: declaration; it is recommended to set the timeout to a high value to ensure the user has time to respond to the notification.
[!NOTE] Exception: If
reply: trueis defined, set timeout to a high value, or to nothing at all.
Sounds
When specifying a sound, you have the following options:
- Basso
- Blow
- Bottle
- Frog
- Funk
- Glass
- Hero
- Morse
- Ping
- Pop
- Purr
- Sosumi
- Submarine
- Tink
If sound: true, Bottle is the default sound.
See Also:
Custom Path
customPath takes a string which can be either a relative or absolute path to the binary of your fork/custom version of terminal-notifier.
Example: ./vendor/mac.noindex/terminal-notifier.app/Contents/MacOS/terminal-notifier
Spotlight
terminal-notifier.app is located in the mac.noindex folder to prevent Spotlight from indexing the app. You can find it in:
toasted-notifier\vendor\mac.noindex\terminal-notifier.app
WindowsToaster
- A Node.js wrapper for Windows 8, 10, and 11 notifications.
- Code available at:
node_modules\toasted-notifier\notifiers\toaster.js
Note: There are limitations for images in native Windows 8 notifications:
- Image must be a
PNGimage - Image must be smaller than
1024×1024px - Image must be less than
200kb - Image must be specified using an
absolute path
These limitations are due to the Toast notification system. A good tip is to use something like path.join or path.delimiter to keep your paths cross-platform.
Notifications Not Working
If you do not see notifications from Toasted-Notifier, click windows Start and locate:
Locate NtfyToast, or your customPath / appID program in the list.
[!NOTE] ntfy-toast is the library used by this node package
toasted-notifierfor Windows notifications
Enable both permissions for banner and sound: