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:
beyondkmp 2025-08-22 14:41:36 +08:00 committed by GitHub
parent a4cdb5d45f
commit f66cb2651f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 11 deletions

View File

@ -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)

View File

@ -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()