1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

reverted some changes, removed auto-opening devtools in dev-mode

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2021-05-20 13:49:46 +03:00
parent 7e0d2065f8
commit de11075d2d
5 changed files with 52 additions and 30 deletions

View File

@ -53,6 +53,10 @@ export class CatalogCategoryRegistry {
return Array.from(this.categories); return Array.from(this.categories);
} }
getById(id: string): CatalogCategory{
return this.items.find(category => category.getId() === id);
}
getForGroupKind<T extends CatalogCategory>(group: string, kind: string): T | undefined { getForGroupKind<T extends CatalogCategory>(group: string, kind: string): T | undefined {
return this.groupKindLookup.get(group)?.get(kind) as T; return this.groupKindLookup.get(group)?.get(kind) as T;
} }

View File

@ -21,25 +21,21 @@
import { action, computed, IComputedValue, IObservableArray, makeObservable, observable } from "mobx"; import { action, computed, IComputedValue, IObservableArray, makeObservable, observable } from "mobx";
import type { CatalogEntity } from "./catalog-entity"; import type { CatalogEntity } from "./catalog-entity";
import logger from "../../main/logger"; import { iter } from "../utils";
export class CatalogEntityRegistry { export class CatalogEntityRegistry {
private logPrefix = `[CatalogEntityRegistry]`;
protected sources = observable.map<string, IComputedValue<CatalogEntity[]>>(); protected sources = observable.map<string, IComputedValue<CatalogEntity[]>>();
constructor() { constructor() {
makeObservable(this); makeObservable(this);
} }
@action @action addObservableSource(id: string, source: IObservableArray<CatalogEntity>) {
addObservableSource(id: string, source: IObservableArray<CatalogEntity> | IComputedValue<CatalogEntity[]>) { this.sources.set(id, computed(() => source));
logger.debug(`${this.logPrefix}: adding observable source with id="${id}"`); }
if (Array.isArray(source)) { @action addComputedSource(id: string, source: IComputedValue<CatalogEntity[]>) {
this.sources.set(id, computed(() => source.toJSON())); this.sources.set(id, source);
} else {
this.sources.set(id, source);
}
} }
@action removeSource(id: string) { @action removeSource(id: string) {
@ -47,9 +43,7 @@ export class CatalogEntityRegistry {
} }
@computed get items(): CatalogEntity[] { @computed get items(): CatalogEntity[] {
return Array.from(this.sources.values()) return Array.from(iter.flatMap(this.sources.values(), source => source.get()));
.map(source => source.get())
.flat();
} }
getItemsForApiKind<T extends CatalogEntity>(apiVersion: string, kind: string): T[] { getItemsForApiKind<T extends CatalogEntity>(apiVersion: string, kind: string): T[] {

View File

@ -19,6 +19,7 @@
* 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.
*/ */
import { action, IEnhancer, IObservableMapInitialValues, ObservableMap } from "mobx";
export class ExtendedMap<K, V> extends Map<K, V> { export class ExtendedMap<K, V> extends Map<K, V> {
static new<K, V>(entries?: readonly (readonly [K, V])[] | null): ExtendedMap<K, V> { static new<K, V>(entries?: readonly (readonly [K, V])[] | null): ExtendedMap<K, V> {
@ -64,3 +65,36 @@ export class ExtendedMap<K, V> extends Map<K, V> {
return this.get(key); return this.get(key);
} }
} }
export class ExtendedObservableMap<K, V> extends ObservableMap<K, V> {
constructor(protected getDefault: () => V, initialData?: IObservableMapInitialValues<K, V>, enhancer?: IEnhancer<V>, name?: string) {
super(initialData, enhancer, name);
}
@action
getOrInsert(key: K, val: V): V {
if (this.has(key)) {
return this.get(key);
}
return this.set(key, val).get(key);
}
@action
getOrInsertWith(key: K, getVal: () => V): V {
if (this.has(key)) {
return this.get(key);
}
return this.set(key, getVal()).get(key);
}
@action
getOrDefault(key: K): V {
if (this.has(key)) {
return this.get(key);
}
return this.set(key, this.getDefault()).get(key);
}
}

View File

@ -19,13 +19,13 @@
* 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.
*/ */
import { action, computed, IComputedValue, makeObservable, observable, ObservableMap, runInAction, observe } from "mobx"; import { action, observable, IComputedValue, computed, ObservableMap, runInAction, makeObservable, observe } from "mobx";
import { CatalogEntity, catalogEntityRegistry } from "../../common/catalog"; import { CatalogEntity, catalogEntityRegistry } from "../../common/catalog";
import { watch } from "chokidar"; import { watch } from "chokidar";
import fs from "fs"; import fs from "fs";
import fse from "fs-extra"; import fse from "fs-extra";
import type stream from "stream"; import type stream from "stream";
import { Disposer, iter, Singleton } from "../../common/utils"; import { Disposer, ExtendedObservableMap, iter, Singleton } from "../../common/utils";
import logger from "../logger"; import logger from "../logger";
import type { KubeConfig } from "@kubernetes/client-node"; import type { KubeConfig } from "@kubernetes/client-node";
import { loadConfigFromString, splitConfig, validateKubeConfig } from "../../common/kube-helpers"; import { loadConfigFromString, splitConfig, validateKubeConfig } from "../../common/kube-helpers";
@ -60,7 +60,7 @@ export class KubeconfigSyncManager extends Singleton {
logger.info(`${logPrefix} starting requested syncs`); logger.info(`${logPrefix} starting requested syncs`);
catalogEntityRegistry.addObservableSource(KubeconfigSyncManager.syncName, computed(() => ( catalogEntityRegistry.addComputedSource(KubeconfigSyncManager.syncName, computed(() => (
Array.from(iter.flatMap( Array.from(iter.flatMap(
this.sources.values(), this.sources.values(),
([entities]) => entities.get() ([entities]) => entities.get()
@ -111,7 +111,6 @@ export class KubeconfigSyncManager extends Singleton {
logger.info(`${logPrefix} starting sync of file/folder`, { filePath }); logger.info(`${logPrefix} starting sync of file/folder`, { filePath });
logger.debug(`${logPrefix} ${this.sources.size} files/folders watched`, { files: Array.from(this.sources.keys()) }); logger.debug(`${logPrefix} ${this.sources.size} files/folders watched`, { files: Array.from(this.sources.keys()) });
} catch (error) { } catch (error) {
console.error(error);
logger.warn(`${logPrefix} failed to start watching changes: ${error}`); logger.warn(`${logPrefix} failed to start watching changes: ${error}`);
} }
} }
@ -255,25 +254,17 @@ async function watchFileChanges(filePath: string): Promise<[IComputedValue<Catal
depth: stat.isDirectory() ? 0 : 1, // DIRs works with 0 but files need 1 (bug: https://github.com/paulmillr/chokidar/issues/1095) depth: stat.isDirectory() ? 0 : 1, // DIRs works with 0 but files need 1 (bug: https://github.com/paulmillr/chokidar/issues/1095)
disableGlobbing: true, disableGlobbing: true,
}); });
const rootSource = new ObservableMap<string, ObservableMap<string, RootSourceValue>>(); const rootSource = new ExtendedObservableMap<string, ObservableMap<string, RootSourceValue>>(observable.map);
const derivedSource = computed(() => Array.from(iter.flatMap(rootSource.values(), from => iter.map(from.values(), child => child[1])))); const derivedSource = computed(() => Array.from(iter.flatMap(rootSource.values(), from => iter.map(from.values(), child => child[1]))));
const stoppers = new Map<string, Disposer>(); const stoppers = new Map<string, Disposer>();
watcher watcher
.on("change", (childFilePath) => { .on("change", (childFilePath) => {
if (!rootSource.has(childFilePath)) {
rootSource.set(childFilePath, observable.map());
}
stoppers.get(childFilePath)(); stoppers.get(childFilePath)();
stoppers.set(childFilePath, diffChangedConfig(childFilePath, rootSource.get(childFilePath))); stoppers.set(childFilePath, diffChangedConfig(childFilePath, rootSource.getOrDefault(childFilePath)));
}) })
.on("add", (childFilePath) => { .on("add", (childFilePath) => {
if (!rootSource.has(childFilePath)) { stoppers.set(childFilePath, diffChangedConfig(childFilePath, rootSource.getOrDefault(childFilePath)));
rootSource.set(childFilePath, observable.map());
}
stoppers.set(childFilePath, diffChangedConfig(childFilePath, rootSource.get(childFilePath)));
}) })
.on("unlink", (childFilePath) => { .on("unlink", (childFilePath) => {
stoppers.get(childFilePath)(); stoppers.get(childFilePath)();

View File

@ -31,7 +31,7 @@ import { Singleton } from "../common/utils";
import { ClusterFrameInfo, clusterFrameMap } from "../common/cluster-frames"; import { ClusterFrameInfo, clusterFrameMap } from "../common/cluster-frames";
import { IpcRendererNavigationEvents } from "../renderer/navigation/events"; import { IpcRendererNavigationEvents } from "../renderer/navigation/events";
import logger from "./logger"; import logger from "./logger";
import { isDevelopment, productName } from "../common/vars"; import { productName } from "../common/vars";
import { LensProxy } from "./proxy/lens-proxy"; import { LensProxy } from "./proxy/lens-proxy";
export class WindowManager extends Singleton { export class WindowManager extends Singleton {
@ -106,7 +106,6 @@ export class WindowManager extends Singleton {
shell.openExternal(url); shell.openExternal(url);
}) })
.on("dom-ready", () => { .on("dom-ready", () => {
this.mainWindow.webContents.openDevTools({ mode: "right", activate: isDevelopment });
appEventBus.emit({ name: "app", action: "dom-ready" }); appEventBus.emit({ name: "app", action: "dom-ready" });
}) })
.on("did-fail-load", (_event, code, desc) => { .on("did-fail-load", (_event, code, desc) => {