diff --git a/packages/shared/IpcChannel.ts b/packages/shared/IpcChannel.ts index 4da92a9fd2..7ba4164969 100644 --- a/packages/shared/IpcChannel.ts +++ b/packages/shared/IpcChannel.ts @@ -21,8 +21,8 @@ export enum IpcChannel { App_InstallUvBinary = 'app:install-uv-binary', App_InstallBunBinary = 'app:install-bun-binary', - App_Notification = 'app:notification', - App_OnNotificationClick = 'app:on-notification-click', + Notification_Send = 'notification:send', + Notification_OnClick = 'notification:on-click', Webview_SetOpenLinkExternal = 'webview:set-open-link-external', diff --git a/src/main/ipc.ts b/src/main/ipc.ts index 1241871ffa..45e9d7b72d 100644 --- a/src/main/ipc.ts +++ b/src/main/ipc.ts @@ -204,10 +204,10 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) { }) // notification - ipcMain.handle(IpcChannel.App_Notification, async (_, notification: Notification) => { + ipcMain.handle(IpcChannel.Notification_Send, async (_, notification: Notification) => { await notificationService.sendNotification(notification) }) - ipcMain.handle(IpcChannel.App_OnNotificationClick, (_, notification: Notification) => { + ipcMain.handle(IpcChannel.Notification_OnClick, (_, notification: Notification) => { mainWindow.webContents.send('notification-click', notification) }) diff --git a/src/preload/index.ts b/src/preload/index.ts index 6201bb9c2c..5159f29097 100644 --- a/src/preload/index.ts +++ b/src/preload/index.ts @@ -27,16 +27,7 @@ const api = { getCacheSize: () => ipcRenderer.invoke(IpcChannel.App_GetCacheSize), clearCache: () => ipcRenderer.invoke(IpcChannel.App_ClearCache), notification: { - send: (notification: Notification) => ipcRenderer.invoke(IpcChannel.App_Notification, notification), - onClick: (callback: () => void) => { - const listener = () => { - callback() - } - ipcRenderer.on(IpcChannel.App_OnNotificationClick, listener) - return () => { - ipcRenderer.off(IpcChannel.App_OnNotificationClick, listener) - } - } + send: (notification: Notification) => ipcRenderer.invoke(IpcChannel.Notification_Send, notification) }, system: { getDeviceType: () => ipcRenderer.invoke(IpcChannel.System_GetDeviceType), diff --git a/src/renderer/src/services/NotificationService.ts b/src/renderer/src/services/NotificationService.ts index 2f001f524c..cb77cf7d6b 100644 --- a/src/renderer/src/services/NotificationService.ts +++ b/src/renderer/src/services/NotificationService.ts @@ -1,3 +1,5 @@ +import store from '@renderer/store' +import { initialState as defaultNotificationSettings } from '@renderer/store/settings' import type { Notification } from '@renderer/types/notification' import { NotificationQueue } from '../queue/NotificationQueue' @@ -23,7 +25,11 @@ export class NotificationService { * @param notification 要发送的通知 */ public async send(notification: Notification): Promise { - await this.queue.add(notification) + const notificationSettings = store.getState().settings.notification || defaultNotificationSettings + + if (notificationSettings[notification.source]) { + this.queue.add(notification) + } } /** @@ -33,8 +39,8 @@ export class NotificationService { // Register an event listener for notification clicks window.electron.ipcRenderer.on('notification-click', (_event, notification: Notification) => { // 根据通知类型处理点击事件 - if (notification.type === 'action' && notification.onClick) { - notification.onClick() + if (notification.type === 'action') { + notification.onClick?.() } }) }