This commit is contained in:
Adnan Lahrech 2023-10-12 04:46:29 +00:00 committed by GitHub
commit de73e52b45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -2,9 +2,12 @@ import { app, ipcMain } from 'electron'
import {
type ProgressInfo,
type UpdateDownloadedEvent,
CancellationToken,
autoUpdater
} from 'electron-updater'
let cancellationToken = new CancellationToken()
export function update(win: Electron.BrowserWindow) {
// When set to false, the update download will be triggered through the API
@ -56,6 +59,12 @@ export function update(win: Electron.BrowserWindow) {
)
})
// Cancel downloading
ipcMain.handle('cancel-download', () => {
cancellationToken.cancel()
cancellationToken = new CancellationToken();
})
// Install now
ipcMain.handle('quit-and-install', () => {
autoUpdater.quitAndInstall(false, true)
@ -69,5 +78,5 @@ function startDownload(
autoUpdater.on('download-progress', info => callback(null, info))
autoUpdater.on('error', error => callback(error, null))
autoUpdater.on('update-downloaded', complete)
autoUpdater.downloadUpdate()
autoUpdater.downloadUpdate(cancellationToken)
}

View File

@ -18,7 +18,7 @@ const Update = () => {
onCancel?: () => void
onOk?: () => void
}>({
onCancel: () => setModalOpen(false),
onCancel: () => ipcRenderer.invoke('cancel-download').then(() => setModalOpen(false)),
onOk: () => ipcRenderer.invoke('start-download'),
})