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);
}
getById(id: string): CatalogCategory{
return this.items.find(category => category.getId() === id);
}
getForGroupKind<T extends CatalogCategory>(group: string, kind: string): T | undefined {
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 type { CatalogEntity } from "./catalog-entity";
import logger from "../../main/logger";
import { iter } from "../utils";
export class CatalogEntityRegistry {
private logPrefix = `[CatalogEntityRegistry]`;
protected sources = observable.map<string, IComputedValue<CatalogEntity[]>>();
constructor() {
makeObservable(this);
}
@action
addObservableSource(id: string, source: IObservableArray<CatalogEntity> | IComputedValue<CatalogEntity[]>) {
logger.debug(`${this.logPrefix}: adding observable source with id="${id}"`);
@action addObservableSource(id: string, source: IObservableArray<CatalogEntity>) {
this.sources.set(id, computed(() => source));
}
if (Array.isArray(source)) {
this.sources.set(id, computed(() => source.toJSON()));
} else {
this.sources.set(id, source);
}
@action addComputedSource(id: string, source: IComputedValue<CatalogEntity[]>) {
this.sources.set(id, source);
}
@action removeSource(id: string) {
@ -47,9 +43,7 @@ export class CatalogEntityRegistry {
}
@computed get items(): CatalogEntity[] {
return Array.from(this.sources.values())
.map(source => source.get())
.flat();
return Array.from(iter.flatMap(this.sources.values(), source => source.get()));
}
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.
*/
import { action, IEnhancer, IObservableMapInitialValues, ObservableMap } from "mobx";
export class ExtendedMap<K, V> extends Map<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);
}
}
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.
*/
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 { watch } from "chokidar";
import fs from "fs";
import fse from "fs-extra";
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 type { KubeConfig } from "@kubernetes/client-node";
import { loadConfigFromString, splitConfig, validateKubeConfig } from "../../common/kube-helpers";
@ -60,7 +60,7 @@ export class KubeconfigSyncManager extends Singleton {
logger.info(`${logPrefix} starting requested syncs`);
catalogEntityRegistry.addObservableSource(KubeconfigSyncManager.syncName, computed(() => (
catalogEntityRegistry.addComputedSource(KubeconfigSyncManager.syncName, computed(() => (
Array.from(iter.flatMap(
this.sources.values(),
([entities]) => entities.get()
@ -111,7 +111,6 @@ export class KubeconfigSyncManager extends Singleton {
logger.info(`${logPrefix} starting sync of file/folder`, { filePath });
logger.debug(`${logPrefix} ${this.sources.size} files/folders watched`, { files: Array.from(this.sources.keys()) });
} catch (error) {
console.error(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)
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 stoppers = new Map<string, Disposer>();
watcher
.on("change", (childFilePath) => {
if (!rootSource.has(childFilePath)) {
rootSource.set(childFilePath, observable.map());
}
stoppers.get(childFilePath)();
stoppers.set(childFilePath, diffChangedConfig(childFilePath, rootSource.get(childFilePath)));
stoppers.set(childFilePath, diffChangedConfig(childFilePath, rootSource.getOrDefault(childFilePath)));
})
.on("add", (childFilePath) => {
if (!rootSource.has(childFilePath)) {
rootSource.set(childFilePath, observable.map());
}
stoppers.set(childFilePath, diffChangedConfig(childFilePath, rootSource.get(childFilePath)));
stoppers.set(childFilePath, diffChangedConfig(childFilePath, rootSource.getOrDefault(childFilePath)));
})
.on("unlink", (childFilePath) => {
stoppers.get(childFilePath)();

View File

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