feat: cancel download (#137)
* feat: cancel download * Fix: Cannot download differentially, fallback to full download: Error: cancelled * Apply suggestion from @ViniciusFXavier Co-authored-by: Vinícius Francisco Xavier <viniciusfranciscoxavier@gmail.com> --------- Co-authored-by: Song <1667077010@qq.com> Co-authored-by: Vinícius Francisco Xavier <viniciusfranciscoxavier@gmail.com>
This commit is contained in:
2 files changed
+10
-2
No files matched your search
@@ -4,9 +4,11 @@ import type {
|
||||
ProgressInfo,
|
||||
UpdateDownloadedEvent,
|
||||
UpdateInfo,
|
||||
CancellationToken
|
||||
} from 'electron-updater'
|
||||
|
||||
const { autoUpdater } = createRequire(import.meta.url)('electron-updater');
|
||||
let cancellationToken = new CancellationToken()
|
||||
|
||||
export function update(win: Electron.BrowserWindow) {
|
||||
|
||||
@@ -59,6 +61,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)
|
||||
@@ -72,5 +80,5 @@ function startDownload(
|
||||
autoUpdater.on('download-progress', (info: ProgressInfo) => callback(null, info))
|
||||
autoUpdater.on('error', (error: Error) => callback(error, null))
|
||||
autoUpdater.on('update-downloaded', complete)
|
||||
autoUpdater.downloadUpdate()
|
||||
autoUpdater.downloadUpdate(cancellationToken)
|
||||
}
|
||||
@@ -17,7 +17,7 @@ const Update = () => {
|
||||
onCancel?: () => void
|
||||
onOk?: () => void
|
||||
}>({
|
||||
onCancel: () => setModalOpen(false),
|
||||
onCancel: () => window.ipcRenderer.invoke('cancel-download').then(() => setModalOpen(false)),
|
||||
onOk: () => window.ipcRenderer.invoke('start-download'),
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user