From e4ec06a9c86461963585d3d035b0828614c2f313 Mon Sep 17 00:00:00 2001 From: Zach Botterman Date: Thu, 13 Mar 2025 23:33:17 -0700 Subject: [PATCH] update example --- .../v3/pkg/services/notifications/service.js | 58 +++++++------------ v3/examples/notifications/frontend/main.js | 12 ++-- 2 files changed, 28 insertions(+), 42 deletions(-) diff --git a/v3/examples/notifications/frontend/bindings/github.com/wailsapp/wails/v3/pkg/services/notifications/service.js b/v3/examples/notifications/frontend/bindings/github.com/wailsapp/wails/v3/pkg/services/notifications/service.js index 85e54340f..40c55b4a9 100644 --- a/v3/examples/notifications/frontend/bindings/github.com/wailsapp/wails/v3/pkg/services/notifications/service.js +++ b/v3/examples/notifications/frontend/bindings/github.com/wailsapp/wails/v3/pkg/services/notifications/service.js @@ -16,8 +16,7 @@ import {Call as $Call, Create as $Create} from "@wailsio/runtime"; import * as $models from "./models.js"; /** - * CheckNotificationAuthorization is a Windows stub that always returns true. - * (user authorization is macOS-specific) + * CheckNotificationAuthorization checks current notification permission status. * @returns {Promise & { cancel(): void }} */ export function CheckNotificationAuthorization() { @@ -25,17 +24,6 @@ export function CheckNotificationAuthorization() { return $resultPromise; } -/** - * OnNotificationResponse registers a callback function that will be called when - * a notification response is received from the user - * @param {any} callback - * @returns {Promise & { cancel(): void }} - */ -export function OnNotificationResponse(callback) { - let $resultPromise = /** @type {any} */($Call.ByID(2829398511, callback)); - return $resultPromise; -} - /** * RegisterNotificationCategory registers a new NotificationCategory to be used with SendNotificationWithActions. * Registering a category with the same name as a previously registered NotificationCategory will override it. @@ -48,8 +36,7 @@ export function RegisterNotificationCategory(category) { } /** - * RemoveAllDeliveredNotifications is a Windows stub that always returns nil. - * (macOS-specific) + * RemoveAllDeliveredNotifications removes all delivered notifications. * @returns {Promise & { cancel(): void }} */ export function RemoveAllDeliveredNotifications() { @@ -58,8 +45,7 @@ export function RemoveAllDeliveredNotifications() { } /** - * RemoveAllPendingNotifications is a Windows stub that always returns nil. - * (macOS-specific) + * RemoveAllPendingNotifications removes all pending notifications. * @returns {Promise & { cancel(): void }} */ export function RemoveAllPendingNotifications() { @@ -68,18 +54,22 @@ export function RemoveAllPendingNotifications() { } /** - * RemoveDeliveredNotification is a Windows stub that always returns nil. - * (macOS-specific) - * @param {string} $0 + * RemoveDeliveredNotification removes a delivered notification matching the unique identifier. + * @param {string} identifier * @returns {Promise & { cancel(): void }} */ -export function RemoveDeliveredNotification($0) { - let $resultPromise = /** @type {any} */($Call.ByID(149440045, $0)); +export function RemoveDeliveredNotification(identifier) { + let $resultPromise = /** @type {any} */($Call.ByID(149440045, identifier)); return $resultPromise; } /** - * RemoveNotification is a Windows stub that always returns nil. + * RemoveNotification is a macOS stub that always returns nil. + * Use one of the following instead: + * RemoveAllPendingNotifications + * RemovePendingNotification + * RemoveAllDeliveredNotifications + * RemoveDeliveredNotification * (Linux-specific) * @param {string} identifier * @returns {Promise & { cancel(): void }} @@ -90,7 +80,7 @@ export function RemoveNotification(identifier) { } /** - * RemoveNotificationCategory removes a previously registered NotificationCategory. + * RemoveNotificationCategory remove a previously registered NotificationCategory. * @param {string} categoryId * @returns {Promise & { cancel(): void }} */ @@ -100,29 +90,26 @@ export function RemoveNotificationCategory(categoryId) { } /** - * RemovePendingNotification is a Windows stub that always returns nil. - * (macOS-specific) - * @param {string} $0 + * RemovePendingNotification removes a pending notification matching the unique identifier. + * @param {string} identifier * @returns {Promise & { cancel(): void }} */ -export function RemovePendingNotification($0) { - let $resultPromise = /** @type {any} */($Call.ByID(3872412470, $0)); +export function RemovePendingNotification(identifier) { + let $resultPromise = /** @type {any} */($Call.ByID(3872412470, identifier)); return $resultPromise; } /** - * RequestUserNotificationAuthorization is a Windows stub that always returns true, nil. - * (user authorization is macOS-specific) + * RequestNotificationAuthorization requests permission for notifications. * @returns {Promise & { cancel(): void }} */ -export function RequestUserNotificationAuthorization() { - let $resultPromise = /** @type {any} */($Call.ByID(3412125712)); +export function RequestNotificationAuthorization() { + let $resultPromise = /** @type {any} */($Call.ByID(729898933)); return $resultPromise; } /** - * SendNotification sends a basic notification with a name, title, and body. All other options are ignored on Windows. - * (subtitle and category id are only available on macOS) + * SendNotification sends a basic notification with a unique identifier, title, subtitle, and body. * @param {$models.NotificationOptions} options * @returns {Promise & { cancel(): void }} */ @@ -135,7 +122,6 @@ export function SendNotification(options) { * SendNotificationWithActions sends a notification with additional actions and inputs. * A NotificationCategory must be registered with RegisterNotificationCategory first. The `CategoryID` must match the registered category. * If a NotificationCategory is not registered a basic notification will be sent. - * (subtitle and category id are only available on macOS) * @param {$models.NotificationOptions} options * @returns {Promise & { cancel(): void }} */ diff --git a/v3/examples/notifications/frontend/main.js b/v3/examples/notifications/frontend/main.js index 718a9fb4f..2c6d234d4 100644 --- a/v3/examples/notifications/frontend/main.js +++ b/v3/examples/notifications/frontend/main.js @@ -1,12 +1,12 @@ -import * as Notifications from "./bindings/github.com/wailsapp/wails/v3/pkg/services/notifications/service"; +import * as Notifications from "./bindings/github.com/wailsapp/wails/v3/pkg/services/notifications"; import { Events } from "@wailsio/runtime"; const notificationsElement = document.getElementById('notifications'); window.sendNotification = async () => { - const granted = await Notifications.RequestUserNotificationAuthorization(); + const granted = await Notifications.Service.RequestNotificationAuthorization(); if (granted) { - await Notifications.SendNotification({ + await Notifications.Service.SendNotification({ id: crypto.randomUUID(), title: "Title", body: "Body!", @@ -20,9 +20,9 @@ window.sendNotification = async () => { } window.sendComplexNotification = async () => { - const granted = await Notifications.RequestUserNotificationAuthorization(); + const granted = await Notifications.Service.RequestNotificationAuthorization(); if (granted) { - await Notifications.RegisterNotificationCategory({ + await Notifications.Service.RegisterNotificationCategory({ id: "FRONTEND_NOTIF", actions: [ { id: "VIEW_ACTION", title: "View" }, @@ -33,7 +33,7 @@ window.sendComplexNotification = async () => { replyPlaceholder: "Reply to frontend...", }); - await Notifications.SendNotificationWithActions({ + await Notifications.Service.SendNotificationWithActions({ id: crypto.randomUUID(), title: "Complex Frontend Notification", subtitle: "From: Jane Doe",