mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Cascade different refactorings to eliminate global shared state from app paths
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
1 parent
908a40975e
commit
9d33fff906
336 files changed
+9105
-3307
No files matched your search
@@ -24,7 +24,6 @@ import { EventEmitter } from "events";
|
||||
import { isEqual } from "lodash";
|
||||
import { action, computed, makeObservable, observable, observe, reaction, when } from "mobx";
|
||||
import path from "path";
|
||||
import { AppPaths } from "../../common/app-paths";
|
||||
import { broadcastMessage, ipcMainOn, ipcRendererOn, requestMain, ipcMainHandle } from "../../common/ipc";
|
||||
import { Disposer, toJS } from "../../common/utils";
|
||||
import logger from "../../main/logger";
|
||||
@@ -35,14 +34,16 @@ import type { LensRendererExtension } from "../lens-renderer-extension";
|
||||
import * as registries from "../registries";
|
||||
import type { LensExtensionState } from "../extensions-store/extensions-store";
|
||||
|
||||
export function extensionPackagesRoot() {
|
||||
return path.join(AppPaths.get("userData"));
|
||||
}
|
||||
|
||||
const logModule = "[EXTENSIONS-LOADER]";
|
||||
|
||||
interface Dependencies {
|
||||
updateExtensionsState: (extensionsState: Record<LensExtensionId, LensExtensionState>) => void
|
||||
createExtensionInstance: (ExtensionClass: LensExtensionConstructor, extension: InstalledExtension) => LensExtension,
|
||||
}
|
||||
|
||||
export interface ExtensionLoading {
|
||||
isBundled: boolean,
|
||||
loaded: Promise<void>
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,6 +82,7 @@ export class ExtensionLoader {
|
||||
|
||||
constructor(protected dependencies : Dependencies) {
|
||||
makeObservable(this);
|
||||
|
||||
observe(this.instances, change => {
|
||||
switch (change.type) {
|
||||
case "add":
|
||||
@@ -260,7 +262,7 @@ export class ExtensionLoader {
|
||||
this.autoInitExtensions(() => Promise.resolve([]));
|
||||
}
|
||||
|
||||
loadOnClusterManagerRenderer() {
|
||||
loadOnClusterManagerRenderer = () => {
|
||||
logger.debug(`${logModule}: load on main renderer (cluster manager)`);
|
||||
|
||||
return this.autoInitExtensions(async (extension: LensRendererExtension) => {
|
||||
@@ -286,9 +288,9 @@ export class ExtensionLoader {
|
||||
|
||||
return removeItems;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
loadOnClusterRenderer(entity: KubernetesCluster) {
|
||||
loadOnClusterRenderer = (entity: KubernetesCluster) => {
|
||||
logger.debug(`${logModule}: load on cluster renderer (dashboard)`);
|
||||
|
||||
this.autoInitExtensions(async (extension: LensRendererExtension) => {
|
||||
@@ -316,12 +318,12 @@ export class ExtensionLoader {
|
||||
|
||||
return removeItems;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
protected autoInitExtensions(register: (ext: LensExtension) => Promise<Disposer[]>) {
|
||||
const loadingExtensions: { isBundled: boolean, loaded: Promise<void> }[] = [];
|
||||
const loadingExtensions: ExtensionLoading[] = [];
|
||||
|
||||
reaction(() => this.toJSON(), installedExtensions => {
|
||||
reaction(() => this.toJSON(), async installedExtensions => {
|
||||
for (const [extId, extension] of installedExtensions) {
|
||||
const alreadyInit = this.instances.has(extId) || this.nonInstancesByName.has(extension.manifest.name);
|
||||
|
||||
@@ -334,7 +336,10 @@ export class ExtensionLoader {
|
||||
continue;
|
||||
}
|
||||
|
||||
const instance = new LensExtensionClass(extension);
|
||||
const instance = this.dependencies.createExtensionInstance(
|
||||
LensExtensionClass,
|
||||
extension,
|
||||
);
|
||||
|
||||
const loaded = instance.enable(register).catch((err) => {
|
||||
logger.error(`${logModule}: failed to enable`, { ext: extension, err });
|
||||
|
||||
Reference in new issue
Block a user