Skip to content

Commit

Permalink
fix(update): type supplement (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
RSS1102 authored Jan 12, 2024
1 parent 3d4395f commit e544554
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions electron/main/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 })
})

Expand All @@ -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) {
Expand Down Expand Up @@ -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()
}

0 comments on commit e544554

Please sign in to comment.