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 { import {
type ProgressInfo, type ProgressInfo,
type UpdateDownloadedEvent, type UpdateDownloadedEvent,
CancellationToken,
autoUpdater autoUpdater
} from 'electron-updater' } from 'electron-updater'
let cancellationToken = new CancellationToken()
export function update(win: Electron.BrowserWindow) { export function update(win: Electron.BrowserWindow) {
// When set to false, the update download will be triggered through the API // 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 // Install now
ipcMain.handle('quit-and-install', () => { ipcMain.handle('quit-and-install', () => {
autoUpdater.quitAndInstall(false, true) autoUpdater.quitAndInstall(false, true)
@ -69,5 +78,5 @@ function startDownload(
autoUpdater.on('download-progress', info => callback(null, info)) autoUpdater.on('download-progress', info => callback(null, info))
autoUpdater.on('error', error => callback(error, null)) autoUpdater.on('error', error => callback(error, null))
autoUpdater.on('update-downloaded', complete) autoUpdater.on('update-downloaded', complete)
autoUpdater.downloadUpdate() autoUpdater.downloadUpdate(cancellationToken)
} }

View File

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