This directory contains the implementation of the Web Notification API for JSAR Runtime.
src/client/dom/notification.hpp- Notification class header with permission enums and optionssrc/client/dom/notification.cpp- Notification class implementation
src/client/script_bindings/notification.hpp- V8 wrapper class headersrc/client/script_bindings/notification.cpp- V8 wrapper implementation
tests/client/notification_tests.cpp- C++ unit tests using Catch2tests/fixtures/notification-example.js- JavaScript usage example
const notification = new Notification(title, options);Notification.permission- Returns the current permission state ("default", "granted", or "denied")
Notification.requestPermission()- Requests permission to show notifications (stub implementation)
title- The title of the notificationbody- The body text of the notificationdir- Text direction ("auto", "ltr", or "rtl")lang- Language codetag- Notification tag for groupingicon- Icon URLbadge- Badge URLsound- Sound URLrenotify- Whether to notify again if replacing an existing notificationrequireInteraction- Whether the notification requires user interaction to dismisssilent- Whether the notification should be silentdata- Custom data (currently returns null)
onshow- Fired when the notification is displayedonclick- Fired when the notification is clickedonclose- Fired when the notification is closedonerror- Fired when an error occurs
close()- Closes the notification programmatically
- Full C++ Notification class with all standard properties
- JavaScript bindings for constructor and all properties/methods
- Static permission API (stub implementation)
- Event handler properties (storage, not yet dispatching)
- Unit tests for C++ implementation
- Platform-specific notification display:
- macOS: NSUserNotification API
- Windows: Toast Notification API
- Linux: libnotify
- XR: JSAR internal 3D UI
- Event dispatching (show, click, close, error events)
- Promise-based
requestPermission()(currently synchronous stub) - Data property support (currently returns null)
- Persistent permission storage
- Notification action buttons
- Vibration patterns
See tests/fixtures/notification-example.js for a complete JavaScript example.
Basic usage:
// Check permission
console.log(Notification.permission); // "default"
// Request permission (stub - auto-grants)
Notification.requestPermission();
// Create notification
const notification = new Notification('Hello!', {
body: 'This is a test notification',
icon: '/icon.png'
});
// Handle events
notification.onclick = () => {
console.log('Clicked!');
notification.close();
};