mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-07 22:10:21 +08:00
refactor(AppUpdater): remove mainWindow dependency and utilize windowService (#9091)
- Updated AppUpdater to eliminate the mainWindow parameter from the constructor. - Replaced direct mainWindow references with windowService calls to retrieve the main window, improving modularity and decoupling.
This commit is contained in:
parent
399118174e
commit
e4e1325b08
@ -70,7 +70,7 @@ const memoryService = MemoryService.getInstance()
|
|||||||
const dxtService = new DxtService()
|
const dxtService = new DxtService()
|
||||||
|
|
||||||
export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
|
export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
|
||||||
const appUpdater = new AppUpdater(mainWindow)
|
const appUpdater = new AppUpdater()
|
||||||
const notificationService = new NotificationService(mainWindow)
|
const notificationService = new NotificationService(mainWindow)
|
||||||
|
|
||||||
// Initialize Python service with main window
|
// Initialize Python service with main window
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import { CancellationToken, UpdateInfo } from 'builder-util-runtime'
|
|||||||
import { app, BrowserWindow, dialog } from 'electron'
|
import { app, BrowserWindow, dialog } from 'electron'
|
||||||
import { AppUpdater as _AppUpdater, autoUpdater, Logger, NsisUpdater, UpdateCheckResult } from 'electron-updater'
|
import { AppUpdater as _AppUpdater, autoUpdater, Logger, NsisUpdater, UpdateCheckResult } from 'electron-updater'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
import { windowService } from './WindowService'
|
||||||
|
|
||||||
import icon from '../../../build/icon.png?asset'
|
import icon from '../../../build/icon.png?asset'
|
||||||
import { configManager } from './ConfigManager'
|
import { configManager } from './ConfigManager'
|
||||||
@ -21,7 +22,7 @@ export default class AppUpdater {
|
|||||||
private cancellationToken: CancellationToken = new CancellationToken()
|
private cancellationToken: CancellationToken = new CancellationToken()
|
||||||
private updateCheckResult: UpdateCheckResult | null = null
|
private updateCheckResult: UpdateCheckResult | null = null
|
||||||
|
|
||||||
constructor(mainWindow: BrowserWindow) {
|
constructor() {
|
||||||
autoUpdater.logger = logger as Logger
|
autoUpdater.logger = logger as Logger
|
||||||
autoUpdater.forceDevUpdateConfig = !app.isPackaged
|
autoUpdater.forceDevUpdateConfig = !app.isPackaged
|
||||||
autoUpdater.autoDownload = configManager.getAutoUpdate()
|
autoUpdater.autoDownload = configManager.getAutoUpdate()
|
||||||
@ -33,12 +34,12 @@ export default class AppUpdater {
|
|||||||
|
|
||||||
autoUpdater.on('error', (error) => {
|
autoUpdater.on('error', (error) => {
|
||||||
logger.error('update error', error as Error)
|
logger.error('update error', error as Error)
|
||||||
mainWindow.webContents.send(IpcChannel.UpdateError, error)
|
windowService.getMainWindow()?.webContents.send(IpcChannel.UpdateError, error)
|
||||||
})
|
})
|
||||||
|
|
||||||
autoUpdater.on('update-available', (releaseInfo: UpdateInfo) => {
|
autoUpdater.on('update-available', (releaseInfo: UpdateInfo) => {
|
||||||
logger.info('update available', releaseInfo)
|
logger.info('update available', releaseInfo)
|
||||||
mainWindow.webContents.send(IpcChannel.UpdateAvailable, releaseInfo)
|
windowService.getMainWindow()?.webContents.send(IpcChannel.UpdateAvailable, releaseInfo)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 检测到不需要更新时
|
// 检测到不需要更新时
|
||||||
@ -49,17 +50,17 @@ export default class AppUpdater {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
mainWindow.webContents.send(IpcChannel.UpdateNotAvailable)
|
windowService.getMainWindow()?.webContents.send(IpcChannel.UpdateNotAvailable)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 更新下载进度
|
// 更新下载进度
|
||||||
autoUpdater.on('download-progress', (progress) => {
|
autoUpdater.on('download-progress', (progress) => {
|
||||||
mainWindow.webContents.send(IpcChannel.DownloadProgress, progress)
|
windowService.getMainWindow()?.webContents.send(IpcChannel.DownloadProgress, progress)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 当需要更新的内容下载完成后
|
// 当需要更新的内容下载完成后
|
||||||
autoUpdater.on('update-downloaded', (releaseInfo: UpdateInfo) => {
|
autoUpdater.on('update-downloaded', (releaseInfo: UpdateInfo) => {
|
||||||
mainWindow.webContents.send(IpcChannel.UpdateDownloaded, releaseInfo)
|
windowService.getMainWindow()?.webContents.send(IpcChannel.UpdateDownloaded, releaseInfo)
|
||||||
this.releaseInfo = releaseInfo
|
this.releaseInfo = releaseInfo
|
||||||
logger.info('update downloaded', releaseInfo)
|
logger.info('update downloaded', releaseInfo)
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user