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:
authored and GitHub committed 2026-05-17 14:25:37 +08:00
1 parent ab63dcdea5
commit 2907f09e58
2 files changed
+10 -2

No files matched your search

+9 -1
View File
@@ -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)
}
+1 -1
View File
@@ -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'),
})