mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-26 20:12:38 +08:00
refactor: simplify NotificationService initialization and use windowService for notifications (#9411)
* refactor: simplify NotificationService initialization and use windowService for notifications - Removed the dependency on BrowserWindow in NotificationService constructor. - Updated the notification handling to utilize windowService for showing notifications and sending events, improving code modularity. * refactor: remove constructor from NotificationService for cleaner initialization
This commit is contained in:
parent
a4cdb5d45f
commit
f66cb2651f
@ -71,7 +71,7 @@ const dxtService = new DxtService()
|
||||
|
||||
export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
|
||||
const appUpdater = new AppUpdater()
|
||||
const notificationService = new NotificationService(mainWindow)
|
||||
const notificationService = new NotificationService()
|
||||
|
||||
// Initialize Python service with main window
|
||||
pythonService.setMainWindow(mainWindow)
|
||||
|
||||
@ -1,14 +1,8 @@
|
||||
import { BrowserWindow, Notification as ElectronNotification } from 'electron'
|
||||
import { Notification as ElectronNotification } from 'electron'
|
||||
import { Notification } from 'src/renderer/src/types/notification'
|
||||
import { windowService } from './WindowService'
|
||||
|
||||
class NotificationService {
|
||||
private window: BrowserWindow
|
||||
|
||||
constructor(window: BrowserWindow) {
|
||||
// Initialize the service
|
||||
this.window = window
|
||||
}
|
||||
|
||||
public async sendNotification(notification: Notification) {
|
||||
// 使用 Electron Notification API
|
||||
const electronNotification = new ElectronNotification({
|
||||
@ -17,8 +11,8 @@ class NotificationService {
|
||||
})
|
||||
|
||||
electronNotification.on('click', () => {
|
||||
this.window.show()
|
||||
this.window.webContents.send('notification-click', notification)
|
||||
windowService.getMainWindow()?.show()
|
||||
windowService.getMainWindow()?.webContents.send('notification-click', notification)
|
||||
})
|
||||
|
||||
electronNotification.show()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user