Skip to content

Commit

Permalink
Add release channels (Stable and Beta)
Browse files Browse the repository at this point in the history
  • Loading branch information
heyman committed Dec 6, 2023
1 parent 4b73d8d commit 0c55dce
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
2 changes: 2 additions & 0 deletions electron/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
},

Expand All @@ -45,6 +46,7 @@ const defaults = {
emacsMetaKey: "meta",
showLineNumberGutter: true,
showFoldGutter: true,
releaseChannel: null,
},
theme: "system",
}
Expand Down
15 changes: 13 additions & 2 deletions electron/main/auto-update.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { autoUpdater } from "electron-updater"
import { app, dialog, ipcMain } from "electron"
import CONFIG from "../config"

import {
UPDATE_AVAILABLE_EVENT,
Expand All @@ -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
Expand All @@ -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())
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 14 additions & 1 deletion electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"build": {
"appId": "com.heynote.app",
"generateUpdatesFilesForAllChannels": true,
"directories": {
"buildResources": "resources"
}
Expand Down
16 changes: 16 additions & 0 deletions src/components/settings/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
},
Expand All @@ -40,6 +45,7 @@
showFoldGutter: this.showFoldGutter,
keymap: this.keymap,
emacsMetaKey: this.metaKey,
releaseChannel: this.releaseChannel,
})
}
}
Expand Down Expand Up @@ -91,6 +97,16 @@
</div>
</div>
</div>
<div class="row">
<div class="entry">
<h2>Release Channel</h2>
<select ref="releaseChannelSelector" v-model="releaseChannel" @change="updateSettings">
<template v-for="rc in releaseChannels" :key="rc.value">
<option :selected="rc.value === releaseChannel" :value="rc.value">{{ rc.name }}</option>
</template>
</select>
</div>
</div>
</div>
<button
@click="$emit('closeSettings')"
Expand Down

0 comments on commit 0c55dce

Please sign in to comment.