onNotificationClick
Category: Events
Namespace: web.events.onNotificationClick
Description
Fires when the user clicks on a Windows system tray notification that was shown via web.system.notification. The callback receives the name string that was passed when the notification was created, allowing you to identify which notification was clicked and respond accordingly.
Syntax
web.events.onNotificationClick = function(notificationName) {
// notificationName matches the 'name' passed to web.system.notification()
};
Parameters
The callback receives one argument:
- notificationName
string— Thenamevalue that was passed toweb.system.notification()when the notification was shown
Returns
Nothing. This is an event handler assignment, not a function call.
Examples
Basic usage
document.addEventListener('DOMContentLoaded', () => {
web.events.onNotificationClick = function(notificationName) {
console.log('Notification clicked:', notificationName);
};
});
Handle specific notifications
document.addEventListener('DOMContentLoaded', () => {
web.events.onNotificationClick = function(notificationName) {
if (notificationName === 'download-complete') {
// Open the downloads folder
web.shell.showInExplorer({ filePath: 'C:\\Downloads' });
} else if (notificationName === 'update-available') {
showUpdateDialog();
}
};
// Show a notification
await web.system.notification({
name: 'download-complete',
title: 'Download Complete',
message: 'Your file is ready'
});
});
Set handler once at startup
// Register handler ONCE at startup — not inside the notification call
document.addEventListener('DOMContentLoaded', () => {
web.events.onNotificationClick = function(name) {
if (name === 'save-done') {
highlightSaveStatus();
}
};
});
// Later, anywhere in your app:
async function saveFile() {
await web.files.writeTextFile({ filePath, contents });
await web.system.notification({
name: 'save-done',
title: 'Saved',
message: 'Your file has been saved'
});
}
Use Cases
- Navigate to a relevant view when a background task notification is clicked
- Open the file or folder mentioned in the notification
- Dismiss or refresh UI state after a notification is acknowledged
- Trigger follow-up actions (e.g. "open update installer" after an update notification)
Notes
- Register the handler once at startup (inside
DOMContentLoaded) — not each time you show a notification - The
notificationNamepassed to the callback exactly matches thenamefield you passed toweb.system.notification() - Only one handler can be assigned at a time — reassigning replaces the previous handler
- See
web.system.notificationfor showing notifications