Application-defined context data that can be attached to notifications.
A fully-hydrated form of NotificationOptions.
After creating a notification, the service will return an object of this type. This will be the given options object, with any unspecified fields filled-in with default values.
This object should be treated as immutable. Modifying its state will not have any effect on the notification or the state of the service.
Event fired for interactions with notification UI elements. It is important to note that applications will only receive these events if they indicate to the service that they want to receive these events. See Actions for a full example of how actions are defined, and how an application can listen to and handle them.
This can be fired due to interaction with notification buttons, or the notification itself. Later versions of the
service will add additional control types. All actions, for all control types, will be returned to the application
via the same notification-action
event type.
The event object will contain the application-defined metadata that allowed this action to be raised, and details on what triggered this action and which control the user interacted with.
This type includes a generic type argument, should applications wish to define their own interface for action results. See NotificationActionResult for details.
The control whose interaction resulted in this action being raised. Will only be present when trigger is ActionTrigger.CONTROL.
Future versions of the service will add additional controls beyond buttons, and interactions with these new
control types will also come through this one event type. For best forward-compatibility, applications should
always check the type
property of this control, and not assume that the type will always be 'button'
.
This field is marked optional as future versions of the service will also include alternate methods of raising
notification-action
events that do not originate from a button or other control.
When present, the object here will always be strictly equal to one of the control definitions within
notification
. This means indexOf
checks and other equality checks can be performed on this field if
required, such as:
function onNotificationAction(event: NotificationActionEvent): void {
if (event.control && event.control.type === 'button') {
const butttonIndex = event.notification.buttons.indexOf(event.control);
// Handle button click
// . . .
}
}
The notification that created this action
Application-defined metadata that this event is passing back to the application.
A notification-action
event is only fired for an interaction with a notification if the
notification options included an action result for that interaction.
See the comment on the NotificationActionEvent type for an example of buttons that do and don't raise actions.
Indicates what triggered this action.
Note that the programmatic
trigger is not yet implemented.
Event fired whenever the notification has been closed.
This event is fired regardless of how the notification was closed - i.e.: via a call to clear
/clearAll
, or by a
user clicking either the notification itself, the notification's close button, or a button on the notification.
The notification that has just been closed.
This object will match what is returned from the create
call when the notification was first created.
Event fired whenever a new notification has been created.
The notification that has just been created.
This object will match what is returned from the create
call.
Adds a listener, see definitions of individual event interfaces for details on each event.
The event being subscribed to
The callback function to add
Adds a listener, see definitions of individual event interfaces for details on each event.
The event being subscribed to
The callback function to add
Adds a listener, see definitions of individual event interfaces for details on each event.
The event being subscribed to
The callback function to add
Clears a specific notification from the Notification Center.
Returns true if the notification was successfully cleared. Returns false if the notification was not cleared, without errors.
import {clear} from 'openfin-notifications';
clear('uniqueNotificationId');
ID of the notification to clear.
Clears all Notifications which were created by the calling application, including child windows.
Returns the number of successfully cleared Notifications.
import {clearAll} from 'openfin-notifications';
clearAll();
Creates a new notification.
The notification will appear in the Notification Center and as a toast if the Center is not visible.
If a notification is created with an id
of an already existing notification, the existing notification will be recreated with the new content.
import {create} from 'openfin-notifications';
create({
id: 'uniqueNotificationId',
title: 'Notification Title',
body: 'Text to display within the notification body',
category: 'Sample Notifications',
icon: 'https://openfin.co/favicon.ico'
});
Notification configuration options.
Retrieves all Notifications which were created by the calling application, including child windows.
import {getAll} from 'openfin-notifications'
getAll().then((notifications: Notification[]) => {
console.log(`Service has ${notifications.length} notifications for this app:`, notifications);
});
There is deliberately no mechanism provided for fetching notifications that were created by a different application.
Removes a listener previously added with addEventListener.
Has no effect if eventType
isn't a valid event, or listener
isn't a callback registered against eventType
.
The event being unsubscribed from
The callback function to remove, must be strictly-equal (===
equivilance) to a listener previously passed to addEventListener to have an effect
Removes a listener previously added with addEventListener.
Has no effect if eventType
isn't a valid event, or listener
isn't a callback registered against eventType
.
The event being unsubscribed from
The callback function to remove, must be strictly-equal (===
equivilance) to a listener previously passed to addEventListener to have an effect
Removes a listener previously added with addEventListener.
Has no effect if eventType
isn't a valid event, or listener
isn't a callback registered against eventType
.
The event being unsubscribed from
The callback function to remove, must be strictly-equal (===
equivilance) to a listener previously passed to addEventListener to have an effect
Toggles the visibility of the Notification Center.
import {toggleNotificationCenter} from 'openfin-notifications';
toggleNotificationCenter();