mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-23 01:50:13 +08:00
refactor: update IPC channel names for notifications
- Renamed IPC channels for notifications to improve clarity and consistency. - Updated related handlers in the main process and preload scripts to reflect the new naming convention. - Enhanced notification service to respect user settings before sending notifications.
This commit is contained in:
parent
b6675853ed
commit
c49a262df6
@ -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',
|
||||
|
||||
|
||||
@ -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)
|
||||
})
|
||||
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -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<void> {
|
||||
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?.()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user