feat: cancel download
This commit is contained in:
parent
1b5b326aa6
commit
9f48157a49
|
@ -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'
|
||||||
|
|
||||||
|
const 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,11 @@ export function update(win: Electron.BrowserWindow) {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Cancel downloading
|
||||||
|
ipcMain.handle('cancel-download', () => {
|
||||||
|
cancellationToken.cancel()
|
||||||
|
})
|
||||||
|
|
||||||
// Install now
|
// Install now
|
||||||
ipcMain.handle('quit-and-install', () => {
|
ipcMain.handle('quit-and-install', () => {
|
||||||
autoUpdater.quitAndInstall(false, true)
|
autoUpdater.quitAndInstall(false, true)
|
||||||
|
@ -69,5 +77,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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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'),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue