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 { import type {
ProgressInfo, ProgressInfo,
UpdateDownloadedEvent, UpdateDownloadedEvent,
UpdateInfo,
} from 'electron-updater' } from 'electron-updater'
const { autoUpdater } = createRequire(import.meta.url)('electron-updater'); const { autoUpdater } = createRequire(import.meta.url)('electron-updater');
@@ -17,11 +18,11 @@ export function update(win: Electron.BrowserWindow) {
// start check // start check
autoUpdater.on('checking-for-update', function () { }) autoUpdater.on('checking-for-update', function () { })
// update available // 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 }) win.webContents.send('update-can-available', { update: true, version: app.getVersion(), newVersion: arg?.version })
}) })
// update not available // 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 }) 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 // Start downloading and feedback on progress
ipcMain.handle('start-download', (event) => { ipcMain.handle('start-download', (event: Electron.IpcMainInvokeEvent) => {
startDownload( startDownload(
(error, progressInfo) => { (error, progressInfo) => {
if (error) { if (error) {
@@ -68,8 +69,8 @@ function startDownload(
callback: (error: Error | null, info: ProgressInfo | null) => void, callback: (error: Error | null, info: ProgressInfo | null) => void,
complete: (event: UpdateDownloadedEvent) => void, complete: (event: UpdateDownloadedEvent) => void,
) { ) {
autoUpdater.on('download-progress', info => callback(null, info)) autoUpdater.on('download-progress', (info: ProgressInfo) => callback(null, info))
autoUpdater.on('error', error => callback(error, null)) autoUpdater.on('error', (error: Error) => callback(error, null))
autoUpdater.on('update-downloaded', complete) autoUpdater.on('update-downloaded', complete)
autoUpdater.downloadUpdate() autoUpdater.downloadUpdate()
} }