mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Switch to using single source of truth for selected update channel
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
14 files changed
+84
-114
No files matched your search
@@ -6,14 +6,11 @@
|
||||
import moment from "moment-timezone";
|
||||
import path from "path";
|
||||
import os from "os";
|
||||
import { getAppVersion } from "../utils";
|
||||
import type { editor } from "monaco-editor";
|
||||
import merge from "lodash/merge";
|
||||
import { SemVer } from "semver";
|
||||
import { defaultThemeId, defaultEditorFontFamily, defaultFontSize, defaultTerminalFontFamily } from "../vars";
|
||||
import type { ObservableMap } from "mobx";
|
||||
import { observable } from "mobx";
|
||||
import { readonly } from "../utils/readonly";
|
||||
|
||||
export interface KubeconfigSyncEntry extends KubeconfigSyncValue {
|
||||
filePath: string;
|
||||
@@ -296,38 +293,6 @@ const terminalConfig: PreferenceDescription<TerminalConfig, TerminalConfig> = {
|
||||
},
|
||||
};
|
||||
|
||||
export interface UpdateChannelInfo {
|
||||
label: string;
|
||||
}
|
||||
|
||||
export const updateChannels = readonly(new Map<string, UpdateChannelInfo>([
|
||||
["latest", {
|
||||
label: "Stable",
|
||||
}],
|
||||
["beta", {
|
||||
label: "Beta",
|
||||
}],
|
||||
["alpha", {
|
||||
label: "Alpha",
|
||||
}],
|
||||
]));
|
||||
export const defaultUpdateChannel = new SemVer(getAppVersion()).prerelease[0]?.toString() || "latest";
|
||||
|
||||
const updateChannel: PreferenceDescription<string> = {
|
||||
fromStore(val) {
|
||||
return !val || !updateChannels.has(val)
|
||||
? defaultUpdateChannel
|
||||
: val;
|
||||
},
|
||||
toStore(val) {
|
||||
if (!updateChannels.has(val) || val === defaultUpdateChannel) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return val;
|
||||
},
|
||||
};
|
||||
|
||||
export type ExtensionRegistryLocation = "default" | "npmrc" | "custom";
|
||||
|
||||
export type ExtensionRegistry = {
|
||||
@@ -365,7 +330,7 @@ export type UserStoreFlatModel = {
|
||||
|
||||
export type UserPreferencesModel = {
|
||||
[field in keyof typeof DESCRIPTORS]: PreferencesModelType<field>;
|
||||
};
|
||||
} & { updateChannel: string };
|
||||
|
||||
export const DESCRIPTORS = {
|
||||
httpsProxy,
|
||||
@@ -385,6 +350,5 @@ export const DESCRIPTORS = {
|
||||
editorConfiguration,
|
||||
terminalCopyOnSelect,
|
||||
terminalConfig,
|
||||
updateChannel,
|
||||
extensionRegistryUrl,
|
||||
};
|
||||
@@ -6,6 +6,7 @@ import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { ipcMain } from "electron";
|
||||
import userStoreFileNameMigrationInjectable from "./file-name-migration.injectable";
|
||||
import { UserStore } from "./user-store";
|
||||
import selectedUpdateChannelInjectable from "../application-update/selected-update-channel/selected-update-channel.injectable";
|
||||
|
||||
const userStoreInjectable = getInjectable({
|
||||
id: "user-store",
|
||||
@@ -17,7 +18,9 @@ const userStoreInjectable = getInjectable({
|
||||
di.inject(userStoreFileNameMigrationInjectable);
|
||||
}
|
||||
|
||||
return UserStore.createInstance();
|
||||
return UserStore.createInstance({
|
||||
selectedUpdateChannel: di.inject(selectedUpdateChannelInjectable),
|
||||
});
|
||||
},
|
||||
|
||||
causesSideEffects: true,
|
||||
|
||||
@@ -15,15 +15,22 @@ import { getOrInsertSet, toggle, toJS, object } from "../../renderer/utils";
|
||||
import { DESCRIPTORS } from "./preferences-helpers";
|
||||
import type { UserPreferencesModel, StoreType } from "./preferences-helpers";
|
||||
import logger from "../../main/logger";
|
||||
import type { SelectedUpdateChannel } from "../application-update/selected-update-channel/selected-update-channel.injectable";
|
||||
import type { UpdateChannelId } from "../application-update/update-channels";
|
||||
|
||||
export interface UserStoreModel {
|
||||
lastSeenAppVersion: string;
|
||||
preferences: UserPreferencesModel;
|
||||
}
|
||||
|
||||
interface Dependencies {
|
||||
selectedUpdateChannel: SelectedUpdateChannel;
|
||||
}
|
||||
|
||||
export class UserStore extends BaseStore<UserStoreModel> /* implements UserStoreFlatModel (when strict null is enabled) */ {
|
||||
readonly displayName = "UserStore";
|
||||
constructor() {
|
||||
|
||||
constructor(private dependencies: Dependencies) {
|
||||
super({
|
||||
configName: "lens-user-store",
|
||||
migrations,
|
||||
@@ -63,7 +70,6 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
|
||||
@observable kubectlBinariesPath!: StoreType<typeof DESCRIPTORS["kubectlBinariesPath"]>;
|
||||
@observable terminalCopyOnSelect!: StoreType<typeof DESCRIPTORS["terminalCopyOnSelect"]>;
|
||||
@observable terminalConfig!: StoreType<typeof DESCRIPTORS["terminalConfig"]>;
|
||||
@observable updateChannel!: StoreType<typeof DESCRIPTORS["updateChannel"]>;
|
||||
@observable extensionRegistryUrl!: StoreType<typeof DESCRIPTORS["extensionRegistryUrl"]>;
|
||||
|
||||
/**
|
||||
@@ -171,6 +177,11 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
|
||||
this[key] = newVal;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Switch to action-based saving instead saving stores by reaction
|
||||
if (preferences?.updateChannel) {
|
||||
this.dependencies.selectedUpdateChannel.setValue(preferences?.updateChannel as UpdateChannelId);
|
||||
}
|
||||
}
|
||||
|
||||
toJSON(): UserStoreModel {
|
||||
@@ -181,7 +192,12 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
|
||||
|
||||
return toJS({
|
||||
lastSeenAppVersion: this.lastSeenAppVersion,
|
||||
preferences,
|
||||
|
||||
preferences: {
|
||||
...preferences,
|
||||
|
||||
updateChannel: this.dependencies.selectedUpdateChannel.value.get().id,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user