From 6e9195c83572f376e9c9678e9aed4268254ed031 Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Thu, 7 Dec 2023 00:42:29 +0100 Subject: [PATCH] Fix auto updating beta versions by setting autoUpdater.allowPrerelease instead of autoUpdater.channel --- electron/config.js | 4 ++-- electron/main/auto-update.ts | 19 ++++++++++++++----- electron/main/index.ts | 9 +-------- src/components/App.vue | 1 + src/components/StatusBar.vue | 3 ++- src/components/UpdateStatusItem.vue | 13 +++++++++++++ src/components/settings/Settings.vue | 24 ++++++++++++------------ 7 files changed, 45 insertions(+), 28 deletions(-) diff --git a/electron/config.js b/electron/config.js index 1085c4c0..05339bb3 100644 --- a/electron/config.js +++ b/electron/config.js @@ -25,7 +25,7 @@ const schema = { "emacsMetaKey": { "enum": [null, "alt", "meta"], default: null }, "showLineNumberGutter": {type: "boolean", default:true}, "showFoldGutter": {type: "boolean", default:true}, - "releaseChannel": {enum: [null, "beta"], default: null}, + "allowBetaVersions": {type: "boolean", default: false}, }, }, @@ -46,7 +46,7 @@ const defaults = { emacsMetaKey: "meta", showLineNumberGutter: true, showFoldGutter: true, - releaseChannel: null, + allowBetaVersions: false, }, theme: "system", } diff --git a/electron/main/auto-update.ts b/electron/main/auto-update.ts index e1837a58..fc8db980 100644 --- a/electron/main/auto-update.ts +++ b/electron/main/auto-update.ts @@ -25,9 +25,6 @@ autoUpdater.logger.transports.file.level = "info" autoUpdater.autoDownload = false -// set channel -autoUpdater.channel = CONFIG.get("settings.releaseChannel") - autoUpdater.on('error', (error) => { window?.webContents.send(UPDATE_ERROR, error == null ? "unknown" : (error.stack || error).toString()) //dialog.showErrorBox('Error: ', error == null ? "unknown" : (error.stack || error).toString()) @@ -69,8 +66,7 @@ ipcMain.handle(UPDATE_INSTALL_AND_RESTART, () => { export function checkForUpdates() { - const settingsChannel = CONFIG.get("settings.releaseChannel") - autoUpdater.channel = (settingsChannel === null ? "latest" : settingsChannel) + autoUpdater.allowPrerelease = CONFIG.get("settings.allowBetaVersions") autoUpdater.checkForUpdates() // for development, the autoUpdater will not work, so we need to trigger the event manually if (process.env.NODE_ENV === "development") { @@ -84,4 +80,17 @@ ipcMain.handle(UPDATE_CHECK_FOR_UPDATES, () => { export function initializeAutoUpdate(win) { window = win + + /** + * To debug auto updates (actually downloading an update won't work), + * uncomment the lines below, and create a dev-app-update.yml with the content: + * + * owner: heyman + * repo: heynote + * provider: github + */ + // Useful for some dev/debugging tasks, but download can + // not be validated becuase dev app is not signed + //autoUpdater.updateConfigPath = "/Users/heyman/projects/heynote/dev-app-update.yml" //path.join(__dirname, 'dev-app-update.yml'); + //autoUpdater.forceDevUpdateConfig = true; } diff --git a/electron/main/index.ts b/electron/main/index.ts index 62664931..5fd27991 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -62,7 +62,7 @@ let contentSaved = false // if this version is a beta version, set the release channel to beta const isBetaVersion = app.getVersion().includes("beta") if (isBetaVersion) { - CONFIG.set("settings.releaseChannel", "beta") + CONFIG.set("settings.allowBetaVersions", true) } @@ -212,13 +212,6 @@ ipcMain.handle('settings:set', (event, settings) => { if (settings.keymap !== CONFIG.get("settings.keymap")) { currentKeymap = settings.keymap } - const releaseChannelChanged = settings.releaseChannel !== CONFIG.get("settings.releaseChannel") - CONFIG.set("settings", settings) - - if (releaseChannelChanged) { - // release channel changed, check for updates - checkForUpdates() - } win?.webContents.send(SETTINGS_CHANGE_EVENT, settings) }) diff --git a/src/components/App.vue b/src/components/App.vue index f7d70d77..0e0370bf 100644 --- a/src/components/App.vue +++ b/src/components/App.vue @@ -121,6 +121,7 @@ :languageAuto="languageAuto" :theme="theme" :systemTheme="systemTheme" + :allowBetaVersions="settings.allowBetaVersions" @toggleTheme="toggleTheme" @openLanguageSelector="openLanguageSelector" @formatCurrentBlock="formatCurrentBlock" diff --git a/src/components/StatusBar.vue b/src/components/StatusBar.vue index 2deb8813..7681b6b9 100644 --- a/src/components/StatusBar.vue +++ b/src/components/StatusBar.vue @@ -13,6 +13,7 @@ "languageAuto", "theme", "systemTheme", + "allowBetaVersions", ], components: { @@ -63,7 +64,7 @@ > - +
diff --git a/src/components/UpdateStatusItem.vue b/src/components/UpdateStatusItem.vue index 464b459e..a57b5ec4 100644 --- a/src/components/UpdateStatusItem.vue +++ b/src/components/UpdateStatusItem.vue @@ -1,5 +1,9 @@