Skip to content

Commit 3d374bd

Browse files
committed
feat: 更新 Wails 依赖并添加通知功能支持
升级 Wails 框架至 v2.12.0 并更新相关依赖。 新增前端通知 API,包括初始化、发送、管理通知及类别等功能。
1 parent fa215c7 commit 3d374bd

4 files changed

Lines changed: 151 additions & 7 deletions

File tree

frontend/wailsjs/runtime/runtime.d.ts

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,85 @@ export function OnFileDropOff() :void
246246
export function CanResolveFilePaths(): boolean;
247247

248248
// Resolves file paths for an array of files
249-
export function ResolveFilePaths(files: File[]): void
249+
export function ResolveFilePaths(files: File[]): void
250+
251+
// Notification types
252+
export interface NotificationOptions {
253+
id: string;
254+
title: string;
255+
subtitle?: string; // macOS and Linux only
256+
body?: string;
257+
categoryId?: string;
258+
data?: { [key: string]: any };
259+
}
260+
261+
export interface NotificationAction {
262+
id?: string;
263+
title?: string;
264+
destructive?: boolean; // macOS-specific
265+
}
266+
267+
export interface NotificationCategory {
268+
id?: string;
269+
actions?: NotificationAction[];
270+
hasReplyField?: boolean;
271+
replyPlaceholder?: string;
272+
replyButtonTitle?: string;
273+
}
274+
275+
// [InitializeNotifications](https://wails.io/docs/reference/runtime/notification#initializenotifications)
276+
// Initializes the notification service for the application.
277+
// This must be called before sending any notifications.
278+
export function InitializeNotifications(): Promise<void>;
279+
280+
// [CleanupNotifications](https://wails.io/docs/reference/runtime/notification#cleanupnotifications)
281+
// Cleans up notification resources and releases any held connections.
282+
export function CleanupNotifications(): Promise<void>;
283+
284+
// [IsNotificationAvailable](https://wails.io/docs/reference/runtime/notification#isnotificationavailable)
285+
// Checks if notifications are available on the current platform.
286+
export function IsNotificationAvailable(): Promise<boolean>;
287+
288+
// [RequestNotificationAuthorization](https://wails.io/docs/reference/runtime/notification#requestnotificationauthorization)
289+
// Requests notification authorization from the user (macOS only).
290+
export function RequestNotificationAuthorization(): Promise<boolean>;
291+
292+
// [CheckNotificationAuthorization](https://wails.io/docs/reference/runtime/notification#checknotificationauthorization)
293+
// Checks the current notification authorization status (macOS only).
294+
export function CheckNotificationAuthorization(): Promise<boolean>;
295+
296+
// [SendNotification](https://wails.io/docs/reference/runtime/notification#sendnotification)
297+
// Sends a basic notification with the given options.
298+
export function SendNotification(options: NotificationOptions): Promise<void>;
299+
300+
// [SendNotificationWithActions](https://wails.io/docs/reference/runtime/notification#sendnotificationwithactions)
301+
// Sends a notification with action buttons. Requires a registered category.
302+
export function SendNotificationWithActions(options: NotificationOptions): Promise<void>;
303+
304+
// [RegisterNotificationCategory](https://wails.io/docs/reference/runtime/notification#registernotificationcategory)
305+
// Registers a notification category that can be used with SendNotificationWithActions.
306+
export function RegisterNotificationCategory(category: NotificationCategory): Promise<void>;
307+
308+
// [RemoveNotificationCategory](https://wails.io/docs/reference/runtime/notification#removenotificationcategory)
309+
// Removes a previously registered notification category.
310+
export function RemoveNotificationCategory(categoryId: string): Promise<void>;
311+
312+
// [RemoveAllPendingNotifications](https://wails.io/docs/reference/runtime/notification#removeallpendingnotifications)
313+
// Removes all pending notifications from the notification center.
314+
export function RemoveAllPendingNotifications(): Promise<void>;
315+
316+
// [RemovePendingNotification](https://wails.io/docs/reference/runtime/notification#removependingnotification)
317+
// Removes a specific pending notification by its identifier.
318+
export function RemovePendingNotification(identifier: string): Promise<void>;
319+
320+
// [RemoveAllDeliveredNotifications](https://wails.io/docs/reference/runtime/notification#removealldeliverednotifications)
321+
// Removes all delivered notifications from the notification center.
322+
export function RemoveAllDeliveredNotifications(): Promise<void>;
323+
324+
// [RemoveDeliveredNotification](https://wails.io/docs/reference/runtime/notification#removedeliverednotification)
325+
// Removes a specific delivered notification by its identifier.
326+
export function RemoveDeliveredNotification(identifier: string): Promise<void>;
327+
328+
// [RemoveNotification](https://wails.io/docs/reference/runtime/notification#removenotification)
329+
// Removes a notification by its identifier (cross-platform convenience function).
330+
export function RemoveNotification(identifier: string): Promise<void>;

frontend/wailsjs/runtime/runtime.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export function EventsOff(eventName, ...additionalEventNames) {
4848
return window.runtime.EventsOff(eventName, ...additionalEventNames);
4949
}
5050

51+
export function EventsOffAll() {
52+
return window.runtime.EventsOffAll();
53+
}
54+
5155
export function EventsOnce(eventName, callback) {
5256
return EventsOnMultiple(eventName, callback, 1);
5357
}
@@ -235,4 +239,60 @@ export function CanResolveFilePaths() {
235239

236240
export function ResolveFilePaths(files) {
237241
return window.runtime.ResolveFilePaths(files);
242+
}
243+
244+
export function InitializeNotifications() {
245+
return window.runtime.InitializeNotifications();
246+
}
247+
248+
export function CleanupNotifications() {
249+
return window.runtime.CleanupNotifications();
250+
}
251+
252+
export function IsNotificationAvailable() {
253+
return window.runtime.IsNotificationAvailable();
254+
}
255+
256+
export function RequestNotificationAuthorization() {
257+
return window.runtime.RequestNotificationAuthorization();
258+
}
259+
260+
export function CheckNotificationAuthorization() {
261+
return window.runtime.CheckNotificationAuthorization();
262+
}
263+
264+
export function SendNotification(options) {
265+
return window.runtime.SendNotification(options);
266+
}
267+
268+
export function SendNotificationWithActions(options) {
269+
return window.runtime.SendNotificationWithActions(options);
270+
}
271+
272+
export function RegisterNotificationCategory(category) {
273+
return window.runtime.RegisterNotificationCategory(category);
274+
}
275+
276+
export function RemoveNotificationCategory(categoryId) {
277+
return window.runtime.RemoveNotificationCategory(categoryId);
278+
}
279+
280+
export function RemoveAllPendingNotifications() {
281+
return window.runtime.RemoveAllPendingNotifications();
282+
}
283+
284+
export function RemovePendingNotification(identifier) {
285+
return window.runtime.RemovePendingNotification(identifier);
286+
}
287+
288+
export function RemoveAllDeliveredNotifications() {
289+
return window.runtime.RemoveAllDeliveredNotifications();
290+
}
291+
292+
export function RemoveDeliveredNotification(identifier) {
293+
return window.runtime.RemoveDeliveredNotification(identifier);
294+
}
295+
296+
export function RemoveNotification(identifier) {
297+
return window.runtime.RemoveNotification(identifier);
238298
}

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ require (
1717
github.com/json-iterator/go v1.1.12
1818
github.com/mattn/go-colorable v0.1.14
1919
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
20-
github.com/wailsapp/wails/v2 v2.10.2
20+
github.com/wailsapp/wails/v2 v2.12.0
2121
golang.org/x/sync v0.12.0
2222
gorm.io/driver/sqlite v1.6.0
2323
gorm.io/gorm v1.31.1
2424
)
2525

2626
require (
27+
git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3 // indirect
2728
github.com/andybalholm/cascadia v1.3.2 // indirect
2829
github.com/bep/debounce v1.2.1 // indirect
2930
github.com/cespare/xxhash/v2 v2.3.0 // indirect
@@ -58,7 +59,7 @@ require (
5859
github.com/valyala/bytebufferpool v1.0.0 // indirect
5960
github.com/valyala/fasttemplate v1.2.2 // indirect
6061
github.com/vincent-petithory/dataurl v1.0.0 // indirect
61-
github.com/wailsapp/go-webview2 v1.0.19 // indirect
62+
github.com/wailsapp/go-webview2 v1.0.22 // indirect
6263
github.com/wailsapp/mimetype v1.4.1 // indirect
6364
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
6465
go.opentelemetry.io/otel v1.35.0 // indirect

go.sum

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3 h1:N3IGoHHp9pb6mj1cbXbuaSXV/UMKwmbKLf53nQmtqMA=
2+
git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3/go.mod h1:QtOLZGz8olr4qH2vWK0QH0w0O4T9fEIjMuWpKUsH7nc=
13
github.com/JoshVarga/svgparser v0.0.0-20200804023048-5eaba627a7d1 h1:RAQocNl+YQYGPt5yh4SR5zFUIHKrXnLhjIGhHO4Vwnc=
24
github.com/JoshVarga/svgparser v0.0.0-20200804023048-5eaba627a7d1/go.mod h1:tMmgUTWcco9d1ZmK7zjxuTv7XWZhyutXIsgu0uJ3gDw=
35
github.com/PuerkitoBio/goquery v1.9.2 h1:4/wZksC3KgkQw7SQgkKotmKljk0M6V8TUvA8Wb4yPeE=
@@ -116,12 +118,12 @@ github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+
116118
github.com/vincent-petithory/dataurl v0.0.0-20191104211930-d1553a71de50/go.mod h1:FHafX5vmDzyP+1CQATJn7WFKc9CvnvxyvZy6I1MrG/U=
117119
github.com/vincent-petithory/dataurl v1.0.0 h1:cXw+kPto8NLuJtlMsI152irrVw9fRDX8AbShPRpg2CI=
118120
github.com/vincent-petithory/dataurl v1.0.0/go.mod h1:FHafX5vmDzyP+1CQATJn7WFKc9CvnvxyvZy6I1MrG/U=
119-
github.com/wailsapp/go-webview2 v1.0.19 h1:7U3QcDj1PrBPaxJNCui2k1SkWml+Q5kvFUFyTImA6NU=
120-
github.com/wailsapp/go-webview2 v1.0.19/go.mod h1:qJmWAmAmaniuKGZPWwne+uor3AHMB5PFhqiK0Bbj8kc=
121+
github.com/wailsapp/go-webview2 v1.0.22 h1:YT61F5lj+GGaat5OB96Aa3b4QA+mybD0Ggq6NZijQ58=
122+
github.com/wailsapp/go-webview2 v1.0.22/go.mod h1:qJmWAmAmaniuKGZPWwne+uor3AHMB5PFhqiK0Bbj8kc=
121123
github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=
122124
github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o=
123-
github.com/wailsapp/wails/v2 v2.10.2 h1:29U+c5PI4K4hbx8yFbFvwpCuvqK9VgNv8WGobIlKlXk=
124-
github.com/wailsapp/wails/v2 v2.10.2/go.mod h1:XuN4IUOPpzBrHUkEd7sCU5ln4T/p1wQedfxP7fKik+4=
125+
github.com/wailsapp/wails/v2 v2.12.0 h1:BHO/kLNWFHYjCzucxbzAYZWUjub1Tvb4cSguQozHn5c=
126+
github.com/wailsapp/wails/v2 v2.12.0/go.mod h1:mo1bzK1DEJrobt7YrBjgxvb5Sihb1mhAY09hppbibQg=
125127
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
126128
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
127129
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=

0 commit comments

Comments
 (0)