5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-21 11:29:29 +08:00

update example

This commit is contained in:
Zach Botterman 2025-03-13 23:33:17 -07:00
parent 833d8ec7dc
commit e4ec06a9c8
2 changed files with 28 additions and 42 deletions

View File

@ -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<boolean> & { 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<void> & { 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<void> & { 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<void> & { 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<void> & { 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<void> & { 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<void> & { 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<void> & { 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<boolean> & { 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<void> & { 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<void> & { cancel(): void }}
*/

View File

@ -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",