From 0c55dcecb000a814514e3a588cfe3b6e03ec1d60 Mon Sep 17 00:00:00 2001 From: Jonatan Heyman Date: Wed, 6 Dec 2023 13:31:47 +0100 Subject: [PATCH] Add release channels (Stable and Beta) --- electron/config.js | 2 ++ electron/main/auto-update.ts | 15 +++++++++++++-- electron/main/index.ts | 15 ++++++++++++++- package.json | 1 + src/components/settings/Settings.vue | 16 ++++++++++++++++ 5 files changed, 46 insertions(+), 3 deletions(-) diff --git a/electron/config.js b/electron/config.js index 0eaa1bd..1085c4c 100644 --- a/electron/config.js +++ b/electron/config.js @@ -25,6 +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}, }, }, @@ -45,6 +46,7 @@ const defaults = { emacsMetaKey: "meta", showLineNumberGutter: true, showFoldGutter: true, + releaseChannel: null, }, theme: "system", } diff --git a/electron/main/auto-update.ts b/electron/main/auto-update.ts index 63252f6..e1837a5 100644 --- a/electron/main/auto-update.ts +++ b/electron/main/auto-update.ts @@ -1,5 +1,6 @@ import { autoUpdater } from "electron-updater" import { app, dialog, ipcMain } from "electron" +import CONFIG from "../config" import { UPDATE_AVAILABLE_EVENT, @@ -10,7 +11,7 @@ import { UPDATE_START_DOWNLOAD, UPDATE_INSTALL_AND_RESTART, UPDATE_CHECK_FOR_UPDATES, - } from '../constants' +} from '../constants' // will reference the main window @@ -24,6 +25,9 @@ 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()) @@ -63,12 +67,19 @@ ipcMain.handle(UPDATE_INSTALL_AND_RESTART, () => { setImmediate(() => autoUpdater.quitAndInstall(true, true)) }) -ipcMain.handle(UPDATE_CHECK_FOR_UPDATES, () => { + +export function checkForUpdates() { + const settingsChannel = CONFIG.get("settings.releaseChannel") + autoUpdater.channel = (settingsChannel === null ? "latest" : settingsChannel) autoUpdater.checkForUpdates() // for development, the autoUpdater will not work, so we need to trigger the event manually if (process.env.NODE_ENV === "development") { window?.webContents.send(UPDATE_NOT_AVAILABLE_EVENT) } +} + +ipcMain.handle(UPDATE_CHECK_FOR_UPDATES, () => { + checkForUpdates() }) export function initializeAutoUpdate(win) { diff --git a/electron/main/index.ts b/electron/main/index.ts index 5e6ea93..6266493 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -9,7 +9,7 @@ import { WINDOW_CLOSE_EVENT, SETTINGS_CHANGE_EVENT } from '../constants'; import CONFIG from "../config" import { onBeforeInputEvent } from "../keymap" import { isMac } from '../detect-platform'; -import { initializeAutoUpdate } from './auto-update'; +import { initializeAutoUpdate, checkForUpdates } from './auto-update'; import { fixElectronCors } from './cors'; @@ -59,6 +59,12 @@ const isDev = !!process.env.VITE_DEV_SERVER_URL let currentKeymap = CONFIG.get("settings.keymap") 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") +} + async function createWindow() { // read any stored window settings from config, or use defaults @@ -206,6 +212,13 @@ 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/package.json b/package.json index 0c50cf2..3f7c7d6 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ }, "build": { "appId": "com.heynote.app", + "generateUpdatesFilesForAllChannels": true, "directories": { "buildResources": "resources" } diff --git a/src/components/settings/Settings.vue b/src/components/settings/Settings.vue index f4c1a68..c849c22 100644 --- a/src/components/settings/Settings.vue +++ b/src/components/settings/Settings.vue @@ -16,6 +16,11 @@ isMac: window.heynote.platform.isMac, showLineNumberGutter: this.initialSettings.showLineNumberGutter, showFoldGutter: this.initialSettings.showFoldGutter, + releaseChannels: [ + { name: "Stable", value: null }, + { name: "Beta", value: "beta" }, + ], + releaseChannel: this.initialSettings.releaseChannel, } }, @@ -40,6 +45,7 @@ showFoldGutter: this.showFoldGutter, keymap: this.keymap, emacsMetaKey: this.metaKey, + releaseChannel: this.releaseChannel, }) } } @@ -91,6 +97,16 @@ +
+
+

Release Channel

+ +
+