Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions emain/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ function getUpdateChannel(settings: SettingsType): string {
let retVal = settingsChannel;

// If the user setting doesn't exist yet, set it to the value of the updater config.
// If the user was previously on the `latest` channel and has downloaded a `beta` version, update their configured channel to `beta` to prevent downgrading.
if (!settingsChannel || (settingsChannel == "latest" && updaterChannel == "beta")) {
// A beta build must not force the setting back to `beta`: this fork never publishes beta.yml, so that would strand
// the build with no way to reach a release. autoUpdater.allowDowngrade = false already prevents downgrades.
if (!settingsChannel) {
console.log("Update channel setting does not exist, setting to value from updater config.");
RpcApi.SetConfigCommand(ElectronWshClient, { "autoupdate:channel": updaterChannel });
retVal = updaterChannel;
Expand All @@ -53,6 +54,17 @@ function getUpdateChannel(settings: SettingsType): string {
return retVal;
}

// The channel is otherwise read only when the Updater is constructed, so a settings change would need a restart.
async function refreshUpdateChannel() {
const settings = (await RpcApi.GetFullConfigCommand(ElectronWshClient)).settings;
const channel = settings["autoupdate:channel"];
if (!channel || channel == autoUpdater.channel) {
return;
}
console.log("Update channel changed:", autoUpdater.channel, "->", channel);
autoUpdater.channel = channel;
}

export class Updater {
autoCheckInterval: NodeJS.Timeout | null;
intervalms: number;
Expand Down Expand Up @@ -176,6 +188,7 @@ export class Updater {
(this.autoCheckInterval &&
(!this.lastUpdateCheck || Math.abs(now.getTime() - this.lastUpdateCheck.getTime()) > this.intervalms))
) {
await refreshUpdateChannel();
const result = await autoUpdater.checkForUpdates();

// If the user requested this check and we do not have an available update, let them know with a popup dialog. No need to tell them if there is an update, because we show a banner once the update is ready to install.
Expand Down