Fix auto-update channel checking and pinning (#4030)

This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-10-13 14:48:47 -04:00
1 parent 743e7f2b36
commit 3988229a6c
5 files changed
+33 -31

No files matched your search

+4 -5
View File
@@ -29,7 +29,6 @@ import { ipcMain } from "electron";
import { nextUpdateChannel } from "./utils/update-channel";
import { UserStore } from "../common/user-store";
const updateChannel = autoUpdater.channel;
let installVersion: null | string = null;
export function isAutoUpdateEnabled() {
@@ -59,13 +58,13 @@ export const startUpdateChecking = once(function (interval = 1000 * 60 * 60 * 24
return;
}
const us = UserStore.getInstance();
const userStore = UserStore.getInstance();
autoUpdater.logger = logger;
autoUpdater.autoDownload = false;
autoUpdater.autoInstallOnAppQuit = false;
autoUpdater.channel = us.updateChannel;
autoUpdater.allowDowngrade = us.isAllowedToDowngrade;
autoUpdater.channel = userStore.updateChannel;
autoUpdater.allowDowngrade = userStore.isAllowedToDowngrade;
autoUpdater
.on("update-available", (info: UpdateInfo) => {
@@ -109,7 +108,7 @@ export const startUpdateChecking = once(function (interval = 1000 * 60 * 60 * 24
}
})
.on("update-not-available", () => {
const nextChannel = nextUpdateChannel(updateChannel, autoUpdater.channel);
const nextChannel = nextUpdateChannel(userStore.updateChannel, autoUpdater.channel);
logger.info(`${AutoUpdateLogPrefix}: update not available from ${autoUpdater.channel}, will check ${nextChannel} channel next`);
@@ -33,17 +33,17 @@ describe("nextUpdateChannel", () => {
expect(nextUpdateChannel("latest", "alpha")).toEqual("beta");
});
it("returns rc if current channel is beta", () => {
expect(nextUpdateChannel("alpha", "beta")).toEqual("rc");
expect(nextUpdateChannel("beta", "beta")).toEqual("rc");
expect(nextUpdateChannel("rc", "beta")).toEqual("rc");
expect(nextUpdateChannel("latest", "beta")).toEqual("rc");
it("returns latest if current channel is beta", () => {
expect(nextUpdateChannel("alpha", "beta")).toEqual("latest");
expect(nextUpdateChannel("beta", "beta")).toEqual("latest");
expect(nextUpdateChannel("rc", "beta")).toEqual("latest");
expect(nextUpdateChannel("latest", "beta")).toEqual("latest");
});
it("returns latest if current channel is rc", () => {
expect(nextUpdateChannel("alpha", "rc")).toEqual("latest");
expect(nextUpdateChannel("beta", "rc")).toEqual("latest");
expect(nextUpdateChannel("rc", "rc")).toEqual("latest");
it("returns default if current channel is unknown", () => {
expect(nextUpdateChannel("alpha", "rc")).toEqual("alpha");
expect(nextUpdateChannel("beta", "rc")).toEqual("beta");
expect(nextUpdateChannel("rc", "rc")).toEqual("rc");
expect(nextUpdateChannel("latest", "rc")).toEqual("latest");
});
});
+13 -8
View File
@@ -19,14 +19,19 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* Compute the next update channel from the current updating channel
* @param defaultChannel The default (initial) channel to check
* @param channel The current channel that did not have a new version associated with it
* @returns The channel name of the next release version
*/
export function nextUpdateChannel(defaultChannel: string, channel: string): string {
if (channel === "alpha") {
return "beta";
} else if (channel === "beta") {
return "rc";
} else if (channel === "rc") {
return "latest";
} else {
return defaultChannel;
switch (channel) {
case "alpha":
return "beta";
case "beta":
return "latest"; // there is no RC currently
default:
return defaultChannel;
}
}