Add an update-error
listener
This commit is contained in:
3
interface.d.ts
vendored
3
interface.d.ts
vendored
@ -69,6 +69,9 @@ export interface IElectronAPI {
|
||||
onUpdateDownloaded: (
|
||||
callback: (value: string) => void
|
||||
) => Electron.IpcRenderer
|
||||
onUpdateError: (
|
||||
callback: (value: { error: Error }) => void
|
||||
) => Electron
|
||||
appRestart: () => void
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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) => {
|
||||
|
@ -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,
|
||||
})
|
||||
|
Reference in New Issue
Block a user