Skip to content
31 changes: 29 additions & 2 deletions desktop/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ const showKeyboardShortcutsPage = (browserWindow: BrowserWindow) => {
const electronUpdater = (browserWindow: BrowserWindow): PlatformSpecificUpdater => ({
init: () => {
autoUpdater.on(ELECTRON_EVENTS.UPDATE_DOWNLOADED, (info) => {
// eslint-disable-next-line no-console
console.group('[dev] ELECTRON_EVENTS.UPDATE_DOWNLOADED');
console.debug('[dev] info:', info);
const systemMenu = Menu.getApplicationMenu();
const updateMenuItem = systemMenu?.getMenuItemById(`update`);
const checkForUpdatesMenuItem = systemMenu?.getMenuItemById(`checkForUpdates`);
Expand All @@ -227,15 +230,39 @@ const electronUpdater = (browserWindow: BrowserWindow): PlatformSpecificUpdater
if (browserWindow.isVisible() && !isSilentUpdating) {
browserWindow.webContents.send(ELECTRON_EVENTS.UPDATE_DOWNLOADED, info.version);
} else {
quitAndInstallWithUpdate();
console.debug('[dev] else');

autoUpdater
.checkForUpdates()
.then((result) => {
console.debug('[dev] result', result);
if (result?.updateInfo.version === downloadedVersion) {
console.debug('[dev] if - versions match, installing');
quitAndInstallWithUpdate();
} else {
console.debug('[dev] else - downloading new update');
return autoUpdater.downloadUpdate().then(() => {
console.debug('[dev] download complete, installing');
quitAndInstallWithUpdate();
});
}
})
.catch((error) => {
console.debug('[dev] error', error);
log.error('Error during update check or download:', error);
});
}
// eslint-disable-next-line no-console
console.groupEnd();
});

ipcMain.on(ELECTRON_EVENTS.START_UPDATE, quitAndInstallWithUpdate);
autoUpdater.checkForUpdates();
},
update: () => {
autoUpdater.checkForUpdates();
autoUpdater.checkForUpdates().then((result) => {
console.debug('[dev] update result', result);
});
},
});

Expand Down