mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-08 22:39:36 +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) {
|
export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
|
||||||
const appUpdater = new AppUpdater()
|
const appUpdater = new AppUpdater()
|
||||||
const notificationService = new NotificationService(mainWindow)
|
const notificationService = new NotificationService()
|
||||||
|
|
||||||
// Initialize Python service with main window
|
// Initialize Python service with main window
|
||||||
pythonService.setMainWindow(mainWindow)
|
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 { Notification } from 'src/renderer/src/types/notification'
|
||||||
|
import { windowService } from './WindowService'
|
||||||
|
|
||||||
class NotificationService {
|
class NotificationService {
|
||||||
private window: BrowserWindow
|
|
||||||
|
|
||||||
constructor(window: BrowserWindow) {
|
|
||||||
// Initialize the service
|
|
||||||
this.window = window
|
|
||||||
}
|
|
||||||
|
|
||||||
public async sendNotification(notification: Notification) {
|
public async sendNotification(notification: Notification) {
|
||||||
// 使用 Electron Notification API
|
// 使用 Electron Notification API
|
||||||
const electronNotification = new ElectronNotification({
|
const electronNotification = new ElectronNotification({
|
||||||
@ -17,8 +11,8 @@ class NotificationService {
|
|||||||
})
|
})
|
||||||
|
|
||||||
electronNotification.on('click', () => {
|
electronNotification.on('click', () => {
|
||||||
this.window.show()
|
windowService.getMainWindow()?.show()
|
||||||
this.window.webContents.send('notification-click', notification)
|
windowService.getMainWindow()?.webContents.send('notification-click', notification)
|
||||||
})
|
})
|
||||||
|
|
||||||
electronNotification.show()
|
electronNotification.show()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user