Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion electron/main/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion src/components/update/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
})

Expand Down