Skip to content

Commit

Permalink
Fix auto updating beta versions by setting autoUpdater.allowPrereleas…
Browse files Browse the repository at this point in the history
…e instead of autoUpdater.channel
  • Loading branch information
heyman committed Dec 6, 2023
1 parent 5a497ba commit 782564e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 28 deletions.
4 changes: 2 additions & 2 deletions electron/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
},

Expand All @@ -46,7 +46,7 @@ const defaults = {
emacsMetaKey: "meta",
showLineNumberGutter: true,
showFoldGutter: true,
releaseChannel: null,
allowBetaVersions: false,
},
theme: "system",
}
Expand Down
19 changes: 14 additions & 5 deletions electron/main/auto-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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") {
Expand All @@ -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;
}
9 changes: 1 addition & 8 deletions electron/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}


Expand Down Expand Up @@ -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)
})
1 change: 1 addition & 0 deletions src/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
:languageAuto="languageAuto"
:theme="theme"
:systemTheme="systemTheme"
:allowBetaVersions="settings.allowBetaVersions"
@toggleTheme="toggleTheme"
@openLanguageSelector="openLanguageSelector"
@formatCurrentBlock="formatCurrentBlock"
Expand Down
3 changes: 2 additions & 1 deletion src/components/StatusBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"languageAuto",
"theme",
"systemTheme",
"allowBetaVersions",
],
components: {
Expand Down Expand Up @@ -63,7 +64,7 @@
>
<span class="icon icon-format"></span>
</div>
<UpdateStatusItem />
<UpdateStatusItem :allowBetaVersions="allowBetaVersions" />
<div class="status-block theme clickable" @click="$emit('toggleTheme')" title="Toggle dark/light mode">
<span :class="'icon ' + systemTheme"></span>
</div>
Expand Down
13 changes: 13 additions & 0 deletions src/components/UpdateStatusItem.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<script>
export default {
props: [
"allowBetaVersions",
],
data() {
return {
updateAvailable: false,
Expand Down Expand Up @@ -62,6 +66,14 @@
}
},
watch: {
allowBetaVersions: {
handler: function (newValue) {
this.checkForUpdate()
},
}
},
computed: {
statusText() {
if (this.downloading) {
Expand Down Expand Up @@ -123,6 +135,7 @@
},
checkForUpdate() {
this.updateAvailable = false
this.checkingForUpdate = true
window.heynote.autoUpdate.checkForUpdates()
}
Expand Down
24 changes: 12 additions & 12 deletions src/components/settings/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
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,
allowBetaVersions: this.initialSettings.allowBetaVersions,
}
},
Expand All @@ -45,7 +41,7 @@
showFoldGutter: this.showFoldGutter,
keymap: this.keymap,
emacsMetaKey: this.metaKey,
releaseChannel: this.releaseChannel,
allowBetaVersions: this.allowBetaVersions,
})
}
}
Expand Down Expand Up @@ -99,12 +95,16 @@
</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>
<h2>Beta Versions</h2>
<div class="checkbox">
<input
type="checkbox"
id="allowBetaVersions"
v-model="allowBetaVersions"
@change="updateSettings"
/>
<label for="allowBetaVersions">Use beta versions of Heynote</label>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 782564e

Please sign in to comment.