Notification
This part of the runtime provides access to native system notifications with support for interactive elements like action buttons and text input fields.
InitializeNotifications
Initializes the notification system. It should be called during app startup.
Go: InitializeNotifications(ctx context.Context) error
JavaScript: InitializeNotifications(): Promise<void>
Returns: Error if initialization fails
Example:
err := runtime.InitializeNotifications(ctx)
if err != nil {
log.Fatal(err)
}
await runtime.InitializeNotifications();
IsNotificationAvailable
Checks if notifications are supported on the current platform.
Go: IsNotificationAvailable(ctx context.Context) bool
JavaScript: IsNotificationAvailable(): Promise<boolean>
Returns: true if notifications are supported, false otherwise
Example:
if !runtime.IsNotificationAvailable(ctx) {
log.Println("Notifications not available on this platform")
}
const available = await runtime.IsNotificationAvailable();
if (!available) {
console.log("Notifications not available on this platform");
}
RequestNotificationAuthorization
Requests permission to display notifications (macOS only). On Windows and Linux, this always returns true.
Go: RequestNotificationAuthorization(ctx context.Context) (bool, error)
JavaScript: RequestNotificationAuthorization(): Promise<boolean>
Returns: Authorization status and error
Example:
authorized, err := runtime.RequestNotificationAuthorization(ctx)
const authorized = await runtime.RequestNotificationAuthorization();
CheckNotificationAuthorization
Checks the current notification authorization status (macOS only). On Windows and Linux, this always returns true.
Go: CheckNotificationAuthorization(ctx context.Context) (bool, error)
JavaScript: CheckNotificationAuthorization(): Promise<boolean>
Returns: Authorization status and error
Example:
authorized, err := runtime.CheckNotificationAuthorization(ctx)
const authorized = await runtime.CheckNotificationAuthorization();
CleanupNotifications
Cleans up notification resources and releases any held connections. This should be called when shutting down the application, particularly on Linux where it closes the D-Bus connection.
Go: CleanupNotifications(ctx context.Context)
JavaScript: CleanupNotifications(): Promise<void>
Example:
runtime.CleanupNotifications(ctx)
await runtime.CleanupNotifications();