mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix auto-update channel checking and pinning (#4030)
This commit is contained in:
parent
743e7f2b36
commit
3988229a6c
@ -23,9 +23,10 @@ import moment from "moment-timezone";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
import { ThemeStore } from "../../renderer/theme.store";
|
import { ThemeStore } from "../../renderer/theme.store";
|
||||||
import { ObservableToggleSet } from "../utils";
|
import { getAppVersion, ObservableToggleSet } from "../utils";
|
||||||
import type {monaco} from "react-monaco-editor";
|
import type {monaco} from "react-monaco-editor";
|
||||||
import merge from "lodash/merge";
|
import merge from "lodash/merge";
|
||||||
|
import { SemVer } from "semver";
|
||||||
|
|
||||||
export interface KubeconfigSyncEntry extends KubeconfigSyncValue {
|
export interface KubeconfigSyncEntry extends KubeconfigSyncValue {
|
||||||
filePath: string;
|
filePath: string;
|
||||||
@ -260,9 +261,8 @@ const editorConfiguration: PreferenceDescription<EditorConfiguration, EditorConf
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultUpdateChannel = "latest";
|
|
||||||
const updateChannels = new Map([
|
const updateChannels = new Map([
|
||||||
[defaultUpdateChannel, {
|
["latest", {
|
||||||
label: "Stable"
|
label: "Stable"
|
||||||
}],
|
}],
|
||||||
["beta", {
|
["beta", {
|
||||||
@ -272,6 +272,7 @@ const updateChannels = new Map([
|
|||||||
label: "Alpha"
|
label: "Alpha"
|
||||||
}],
|
}],
|
||||||
]);
|
]);
|
||||||
|
const defaultUpdateChannel = new SemVer(getAppVersion()).prerelease[0]?.toString() || "latest";
|
||||||
|
|
||||||
const updateChannel: PreferenceDescription<string> = {
|
const updateChannel: PreferenceDescription<string> = {
|
||||||
fromStore(val) {
|
fromStore(val) {
|
||||||
@ -318,6 +319,5 @@ export const DESCRIPTORS = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const CONSTANTS = {
|
export const CONSTANTS = {
|
||||||
defaultUpdateChannel,
|
|
||||||
updateChannels,
|
updateChannels,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { app, ipcMain } from "electron";
|
import { app, ipcMain } from "electron";
|
||||||
import semver from "semver";
|
import semver, { SemVer } from "semver";
|
||||||
import { action, computed, observable, reaction, makeObservable } from "mobx";
|
import { action, computed, observable, reaction, makeObservable } from "mobx";
|
||||||
import { BaseStore } from "../base-store";
|
import { BaseStore } from "../base-store";
|
||||||
import migrations from "../../migrations/user-store";
|
import migrations from "../../migrations/user-store";
|
||||||
@ -30,7 +30,7 @@ import { appEventBus } from "../event-bus";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import { fileNameMigration } from "../../migrations/user-store";
|
import { fileNameMigration } from "../../migrations/user-store";
|
||||||
import { ObservableToggleSet, toJS } from "../../renderer/utils";
|
import { ObservableToggleSet, toJS } from "../../renderer/utils";
|
||||||
import { DESCRIPTORS, KubeconfigSyncValue, UserPreferencesModel, EditorConfiguration, CONSTANTS } from "./preferences-helpers";
|
import { DESCRIPTORS, KubeconfigSyncValue, UserPreferencesModel, EditorConfiguration } from "./preferences-helpers";
|
||||||
import logger from "../../main/logger";
|
import logger from "../../main/logger";
|
||||||
import type { monaco } from "react-monaco-editor";
|
import type { monaco } from "react-monaco-editor";
|
||||||
import { getPath } from "../utils/getPath";
|
import { getPath } from "../utils/getPath";
|
||||||
@ -107,9 +107,7 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
|
|||||||
return this.shell || process.env.SHELL || process.env.PTYSHELL;
|
return this.shell || process.env.SHELL || process.env.PTYSHELL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get isAllowedToDowngrade(): boolean {
|
readonly isAllowedToDowngrade = new SemVer(getAppVersion()).prerelease[0] !== "latest";
|
||||||
return this.updateChannel !== CONSTANTS.defaultUpdateChannel;
|
|
||||||
}
|
|
||||||
|
|
||||||
startMainReactions() {
|
startMainReactions() {
|
||||||
// track telemetry availability
|
// track telemetry availability
|
||||||
|
|||||||
@ -29,7 +29,6 @@ import { ipcMain } from "electron";
|
|||||||
import { nextUpdateChannel } from "./utils/update-channel";
|
import { nextUpdateChannel } from "./utils/update-channel";
|
||||||
import { UserStore } from "../common/user-store";
|
import { UserStore } from "../common/user-store";
|
||||||
|
|
||||||
const updateChannel = autoUpdater.channel;
|
|
||||||
let installVersion: null | string = null;
|
let installVersion: null | string = null;
|
||||||
|
|
||||||
export function isAutoUpdateEnabled() {
|
export function isAutoUpdateEnabled() {
|
||||||
@ -59,13 +58,13 @@ export const startUpdateChecking = once(function (interval = 1000 * 60 * 60 * 24
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const us = UserStore.getInstance();
|
const userStore = UserStore.getInstance();
|
||||||
|
|
||||||
autoUpdater.logger = logger;
|
autoUpdater.logger = logger;
|
||||||
autoUpdater.autoDownload = false;
|
autoUpdater.autoDownload = false;
|
||||||
autoUpdater.autoInstallOnAppQuit = false;
|
autoUpdater.autoInstallOnAppQuit = false;
|
||||||
autoUpdater.channel = us.updateChannel;
|
autoUpdater.channel = userStore.updateChannel;
|
||||||
autoUpdater.allowDowngrade = us.isAllowedToDowngrade;
|
autoUpdater.allowDowngrade = userStore.isAllowedToDowngrade;
|
||||||
|
|
||||||
autoUpdater
|
autoUpdater
|
||||||
.on("update-available", (info: UpdateInfo) => {
|
.on("update-available", (info: UpdateInfo) => {
|
||||||
@ -109,7 +108,7 @@ export const startUpdateChecking = once(function (interval = 1000 * 60 * 60 * 24
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on("update-not-available", () => {
|
.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`);
|
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");
|
expect(nextUpdateChannel("latest", "alpha")).toEqual("beta");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns rc if current channel is beta", () => {
|
it("returns latest if current channel is beta", () => {
|
||||||
expect(nextUpdateChannel("alpha", "beta")).toEqual("rc");
|
expect(nextUpdateChannel("alpha", "beta")).toEqual("latest");
|
||||||
expect(nextUpdateChannel("beta", "beta")).toEqual("rc");
|
expect(nextUpdateChannel("beta", "beta")).toEqual("latest");
|
||||||
expect(nextUpdateChannel("rc", "beta")).toEqual("rc");
|
expect(nextUpdateChannel("rc", "beta")).toEqual("latest");
|
||||||
expect(nextUpdateChannel("latest", "beta")).toEqual("rc");
|
expect(nextUpdateChannel("latest", "beta")).toEqual("latest");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns latest if current channel is rc", () => {
|
it("returns default if current channel is unknown", () => {
|
||||||
expect(nextUpdateChannel("alpha", "rc")).toEqual("latest");
|
expect(nextUpdateChannel("alpha", "rc")).toEqual("alpha");
|
||||||
expect(nextUpdateChannel("beta", "rc")).toEqual("latest");
|
expect(nextUpdateChannel("beta", "rc")).toEqual("beta");
|
||||||
expect(nextUpdateChannel("rc", "rc")).toEqual("latest");
|
expect(nextUpdateChannel("rc", "rc")).toEqual("rc");
|
||||||
expect(nextUpdateChannel("latest", "rc")).toEqual("latest");
|
expect(nextUpdateChannel("latest", "rc")).toEqual("latest");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -19,14 +19,19 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* 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 {
|
export function nextUpdateChannel(defaultChannel: string, channel: string): string {
|
||||||
if (channel === "alpha") {
|
switch (channel) {
|
||||||
return "beta";
|
case "alpha":
|
||||||
} else if (channel === "beta") {
|
return "beta";
|
||||||
return "rc";
|
case "beta":
|
||||||
} else if (channel === "rc") {
|
return "latest"; // there is no RC currently
|
||||||
return "latest";
|
default:
|
||||||
} else {
|
return defaultChannel;
|
||||||
return defaultChannel;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user