Add an update-error listener

This commit is contained in:
Frank Noirot
2024-09-26 12:03:42 -04:00
parent 15b42eb8b7
commit df8d3740b6
4 changed files with 19 additions and 0 deletions

3
interface.d.ts vendored
View File

@ -69,6 +69,9 @@ export interface IElectronAPI {
onUpdateDownloaded: (
callback: (value: string) => void
) => Electron.IpcRenderer
onUpdateError: (
callback: (value: { error: Error }) => void
) => Electron
appRestart: () => void
}

View File

@ -62,6 +62,14 @@ if (isDesktop()) {
console.log(message)
toast.loading(message, { id: AUTO_UPDATER_TOAST_ID })
})
// Listen for update download errors to show
// an error toast and clear the loading toast.
window.electron.onUpdateError(({ error }) => {
console.error(error)
toast.error('An error occurred while downloading the update.', {
id: AUTO_UPDATER_TOAST_ID,
})
})
window.electron.onUpdateDownloaded((version: string) => {
const message = `A new update (${version}) was downloaded and will be available next time you open the app.`
console.log(message)

View File

@ -261,6 +261,11 @@ app.on('ready', () => {
autoUpdater.checkForUpdates().catch(reportRejection)
}, fifteenMinutes)
autoUpdater.on('error', (error) => {
console.error('updater-error', error)
mainWindow?.webContents.send('updater-error', error)
})
autoUpdater.on('update-available', (info) => {
console.log('update-available', info)
autoUpdater.prependOnceListener('download-progress', (progress) => {

View File

@ -20,6 +20,8 @@ const onUpdateDownloadStart = (
) => ipcRenderer.on('update-download-start', (_event, value) => callback(value))
const onUpdateDownloaded = (callback: (value: string) => void) =>
ipcRenderer.on('update-downloaded', (_event, value) => callback(value))
const onUpdateError = (callback: (value: Error) => void) =>
ipcRenderer.on('update-error', (_event, value) => callback(value))
const appRestart = () => ipcRenderer.invoke('app.restart')
const isMac = os.platform() === 'darwin'
@ -131,5 +133,6 @@ contextBridge.exposeInMainWorld('electron', {
getMachineApiIp,
onUpdateDownloadStart,
onUpdateDownloaded,
onUpdateError,
appRestart,
})