fix(update): type supplement (#195)

This commit is contained in:
阿菜 Cai authored and GitHub committed 2024-01-13 01:54:49 +08:00
1 parent 3d4395fb20
commit e54455470d
1 file changed
+6 -5
+6 -5
View File
@@ -3,6 +3,7 @@ import { createRequire } from 'node:module'
import type {
ProgressInfo,
UpdateDownloadedEvent,
UpdateInfo,
} from 'electron-updater'
const { autoUpdater } = createRequire(import.meta.url)('electron-updater');
@@ -17,11 +18,11 @@ export function update(win: Electron.BrowserWindow) {
// start check
autoUpdater.on('checking-for-update', function () { })
// update available
autoUpdater.on('update-available', (arg) => {
autoUpdater.on('update-available', (arg: UpdateInfo) => {
win.webContents.send('update-can-available', { update: true, version: app.getVersion(), newVersion: arg?.version })
})
// update not available
autoUpdater.on('update-not-available', (arg) => {
autoUpdater.on('update-not-available', (arg: UpdateInfo) => {
win.webContents.send('update-can-available', { update: false, version: app.getVersion(), newVersion: arg?.version })
})
@@ -40,7 +41,7 @@ export function update(win: Electron.BrowserWindow) {
})
// Start downloading and feedback on progress
ipcMain.handle('start-download', (event) => {
ipcMain.handle('start-download', (event: Electron.IpcMainInvokeEvent) => {
startDownload(
(error, progressInfo) => {
if (error) {
@@ -68,8 +69,8 @@ function startDownload(
callback: (error: Error | null, info: ProgressInfo | null) => void,
complete: (event: UpdateDownloadedEvent) => void,
) {
autoUpdater.on('download-progress', info => callback(null, info))
autoUpdater.on('error', error => callback(error, null))
autoUpdater.on('download-progress', (info: ProgressInfo) => callback(null, info))
autoUpdater.on('error', (error: Error) => callback(error, null))
autoUpdater.on('update-downloaded', complete)
autoUpdater.downloadUpdate()
}