mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
introduce bundledExtensionInjectionToken
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
261b7d763b
commit
71a0396343
@ -86,8 +86,7 @@
|
|||||||
"bundledHelmVersion": "3.7.2",
|
"bundledHelmVersion": "3.7.2",
|
||||||
"sentryDsn": "",
|
"sentryDsn": "",
|
||||||
"contentSecurityPolicy": "script-src 'unsafe-eval' 'self'; frame-src http://*.localhost:*/; img-src * data:",
|
"contentSecurityPolicy": "script-src 'unsafe-eval' 'self'; frame-src http://*.localhost:*/; img-src * data:",
|
||||||
"welcomeRoute": "/welcome",
|
"welcomeRoute": "/welcome"
|
||||||
"extensions": []
|
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16 <17"
|
"node": ">=16 <17"
|
||||||
@ -233,7 +232,6 @@
|
|||||||
"@sentry/electron": "^3.0.8",
|
"@sentry/electron": "^3.0.8",
|
||||||
"@sentry/integrations": "^6.19.3",
|
"@sentry/integrations": "^6.19.3",
|
||||||
"@side/jest-runtime": "^1.0.1",
|
"@side/jest-runtime": "^1.0.1",
|
||||||
"@types/circular-dependency-plugin": "5.0.5",
|
|
||||||
"abort-controller": "^3.0.0",
|
"abort-controller": "^3.0.0",
|
||||||
"auto-bind": "^4.0.0",
|
"auto-bind": "^4.0.0",
|
||||||
"await-lock": "^2.2.2",
|
"await-lock": "^2.2.2",
|
||||||
@ -267,8 +265,6 @@
|
|||||||
"mock-fs": "^5.2.0",
|
"mock-fs": "^5.2.0",
|
||||||
"moment": "^2.29.4",
|
"moment": "^2.29.4",
|
||||||
"moment-timezone": "^0.5.39",
|
"moment-timezone": "^0.5.39",
|
||||||
"monaco-editor": "^0.29.1",
|
|
||||||
"monaco-editor-webpack-plugin": "^5.0.0",
|
|
||||||
"node-fetch": "^3.3.0",
|
"node-fetch": "^3.3.0",
|
||||||
"node-pty": "0.10.1",
|
"node-pty": "0.10.1",
|
||||||
"npm": "^8.19.3",
|
"npm": "^8.19.3",
|
||||||
@ -404,6 +400,8 @@
|
|||||||
"memorystream": "^0.3.1",
|
"memorystream": "^0.3.1",
|
||||||
"mini-css-extract-plugin": "^2.7.2",
|
"mini-css-extract-plugin": "^2.7.2",
|
||||||
"mock-http": "^1.1.0",
|
"mock-http": "^1.1.0",
|
||||||
|
"monaco-editor": "^0.29.1",
|
||||||
|
"monaco-editor-webpack-plugin": "^5.0.0",
|
||||||
"node-gyp": "^8.3.0",
|
"node-gyp": "^8.3.0",
|
||||||
"node-loader": "^2.0.0",
|
"node-loader": "^2.0.0",
|
||||||
"nodemon": "^2.0.20",
|
"nodemon": "^2.0.20",
|
||||||
@ -495,6 +493,7 @@
|
|||||||
"@types/triple-beam": "^1.3.2",
|
"@types/triple-beam": "^1.3.2",
|
||||||
"@types/url-parse": "^1.4.8",
|
"@types/url-parse": "^1.4.8",
|
||||||
"@types/uuid": "^8.3.4",
|
"@types/uuid": "^8.3.4",
|
||||||
|
"monaco-editor": "^0.29.1",
|
||||||
"react-select": "^5.7.0",
|
"react-select": "^5.7.0",
|
||||||
"typed-emitter": "^1.4.0",
|
"typed-emitter": "^1.4.0",
|
||||||
"xterm-addon-fit": "^0.5.0"
|
"xterm-addon-fit": "^0.5.0"
|
||||||
|
|||||||
@ -4,8 +4,10 @@
|
|||||||
*/
|
*/
|
||||||
import applicationInformationToken from "./vars/application-information-token";
|
import applicationInformationToken from "./vars/application-information-token";
|
||||||
import type { ApplicationInformation } from "./vars/application-information-token";
|
import type { ApplicationInformation } from "./vars/application-information-token";
|
||||||
|
import { bundledExtensionInjectionToken } from "../extensions/extension-discovery/bundled-extension-injection-token";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
applicationInformationToken,
|
applicationInformationToken,
|
||||||
ApplicationInformation,
|
ApplicationInformation,
|
||||||
|
bundledExtensionInjectionToken,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
|
import type { LensExtensionConstructor, LensExtensionManifest } from "../lens-extension";
|
||||||
|
|
||||||
|
export interface BundledExtension {
|
||||||
|
readonly manifest: LensExtensionManifest;
|
||||||
|
main: () => LensExtensionConstructor | null;
|
||||||
|
renderer: () => LensExtensionConstructor | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const bundledExtensionInjectionToken = getInjectionToken<BundledExtension>({
|
||||||
|
id: "bundled-extension-injection-token",
|
||||||
|
});
|
||||||
@ -1,13 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
|
||||||
import type { InstalledExtension } from "./extension-discovery";
|
|
||||||
|
|
||||||
const bundledExtensionsInjectable = getInjectable({
|
|
||||||
id: "bundled-extensions",
|
|
||||||
instantiate: (): InstalledExtension[] => [],
|
|
||||||
});
|
|
||||||
|
|
||||||
export default bundledExtensionsInjectable;
|
|
||||||
@ -27,9 +27,7 @@ import getRelativePathInjectable from "../../common/path/get-relative-path.injec
|
|||||||
import joinPathsInjectable from "../../common/path/join-paths.injectable";
|
import joinPathsInjectable from "../../common/path/join-paths.injectable";
|
||||||
import removePathInjectable from "../../common/fs/remove.injectable";
|
import removePathInjectable from "../../common/fs/remove.injectable";
|
||||||
import homeDirectoryPathInjectable from "../../common/os/home-directory-path.injectable";
|
import homeDirectoryPathInjectable from "../../common/os/home-directory-path.injectable";
|
||||||
import applicationInformationToken from "../../common/vars/application-information-token";
|
|
||||||
import lensResourcesDirInjectable from "../../common/vars/lens-resources-dir.injectable";
|
import lensResourcesDirInjectable from "../../common/vars/lens-resources-dir.injectable";
|
||||||
import bundledExtensionsInjectable from "./bundled-extensions.injectable";
|
|
||||||
|
|
||||||
const extensionDiscoveryInjectable = getInjectable({
|
const extensionDiscoveryInjectable = getInjectable({
|
||||||
id: "extension-discovery",
|
id: "extension-discovery",
|
||||||
@ -59,8 +57,6 @@ const extensionDiscoveryInjectable = getInjectable({
|
|||||||
getRelativePath: di.inject(getRelativePathInjectable),
|
getRelativePath: di.inject(getRelativePathInjectable),
|
||||||
joinPaths: di.inject(joinPathsInjectable),
|
joinPaths: di.inject(joinPathsInjectable),
|
||||||
homeDirectoryPath: di.inject(homeDirectoryPathInjectable),
|
homeDirectoryPath: di.inject(homeDirectoryPathInjectable),
|
||||||
applicationInformation: di.inject(applicationInformationToken),
|
|
||||||
bundledExtensions: di.inject(bundledExtensionsInjectable),
|
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -30,20 +30,17 @@ import type { GetDirnameOfPath } from "../../common/path/get-dirname.injectable"
|
|||||||
import type { GetRelativePath } from "../../common/path/get-relative-path.injectable";
|
import type { GetRelativePath } from "../../common/path/get-relative-path.injectable";
|
||||||
import type { RemovePath } from "../../common/fs/remove.injectable";
|
import type { RemovePath } from "../../common/fs/remove.injectable";
|
||||||
import type TypedEventEmitter from "typed-emitter";
|
import type TypedEventEmitter from "typed-emitter";
|
||||||
import type { ApplicationInformation } from "../../common/vars/application-information-token";
|
|
||||||
|
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
readonly extensionLoader: ExtensionLoader;
|
readonly extensionLoader: ExtensionLoader;
|
||||||
readonly extensionsStore: ExtensionsStore;
|
readonly extensionsStore: ExtensionsStore;
|
||||||
readonly extensionInstallationStateStore: ExtensionInstallationStateStore;
|
readonly extensionInstallationStateStore: ExtensionInstallationStateStore;
|
||||||
readonly extensionPackageRootDirectory: string;
|
readonly extensionPackageRootDirectory: string;
|
||||||
readonly bundledExtensions: InstalledExtension[];
|
|
||||||
readonly resourcesDirectory: string;
|
readonly resourcesDirectory: string;
|
||||||
readonly logger: Logger;
|
readonly logger: Logger;
|
||||||
readonly isProduction: boolean;
|
readonly isProduction: boolean;
|
||||||
readonly fileSystemSeparator: string;
|
readonly fileSystemSeparator: string;
|
||||||
readonly homeDirectoryPath: string;
|
readonly homeDirectoryPath: string;
|
||||||
readonly applicationInformation: ApplicationInformation;
|
|
||||||
isCompatibleExtension: (manifest: LensExtensionManifest) => boolean;
|
isCompatibleExtension: (manifest: LensExtensionManifest) => boolean;
|
||||||
installExtension: (name: string) => Promise<void>;
|
installExtension: (name: string) => Promise<void>;
|
||||||
readJsonFile: ReadJson;
|
readJsonFile: ReadJson;
|
||||||
@ -385,23 +382,16 @@ export class ExtensionDiscovery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async ensureExtensions(): Promise<Map<LensExtensionId, InstalledExtension>> {
|
async ensureExtensions(): Promise<Map<LensExtensionId, InstalledExtension>> {
|
||||||
const bundledExtensions = this.dependencies.bundledExtensions;
|
const userExtensions = await this.loadFromFolder(this.localFolderPath);
|
||||||
const userExtensions = await this.loadFromFolder(this.localFolderPath, bundledExtensions.map((extension) => extension.manifest.name));
|
|
||||||
const extensions = bundledExtensions.concat(userExtensions);
|
|
||||||
|
|
||||||
return this.extensions = new Map(extensions.map(extension => [extension.id, extension]));
|
return this.extensions = new Map(userExtensions.map(extension => [extension.id, extension]));
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadFromFolder(folderPath: string, bundledExtensions: string[]): Promise<InstalledExtension[]> {
|
async loadFromFolder(folderPath: string): Promise<InstalledExtension[]> {
|
||||||
const extensions: InstalledExtension[] = [];
|
const extensions: InstalledExtension[] = [];
|
||||||
const paths = await this.dependencies.readDirectory(folderPath);
|
const paths = await this.dependencies.readDirectory(folderPath);
|
||||||
|
|
||||||
for (const fileName of paths) {
|
for (const fileName of paths) {
|
||||||
// do not allow to override bundled extensions
|
|
||||||
if (bundledExtensions.includes(fileName)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const absPath = this.dependencies.joinPaths(folderPath, fileName);
|
const absPath = this.dependencies.joinPaths(folderPath, fileName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
|
|
||||||
|
export const extensionEntryPointNameInjectionToken = getInjectionToken<"main" | "renderer">({
|
||||||
|
id: "extension-entry-point-name-injection-token",
|
||||||
|
});
|
||||||
@ -12,6 +12,8 @@ import extensionInjectable from "./extension/extension.injectable";
|
|||||||
import loggerInjectable from "../../common/logger.injectable";
|
import loggerInjectable from "../../common/logger.injectable";
|
||||||
import joinPathsInjectable from "../../common/path/join-paths.injectable";
|
import joinPathsInjectable from "../../common/path/join-paths.injectable";
|
||||||
import getDirnameOfPathInjectable from "../../common/path/get-dirname.injectable";
|
import getDirnameOfPathInjectable from "../../common/path/get-dirname.injectable";
|
||||||
|
import { bundledExtensionInjectionToken } from "../extension-discovery/bundled-extension-injection-token";
|
||||||
|
import { extensionEntryPointNameInjectionToken } from "./extension-entry-point-name-injection-token";
|
||||||
|
|
||||||
const extensionLoaderInjectable = getInjectable({
|
const extensionLoaderInjectable = getInjectable({
|
||||||
id: "extension-loader",
|
id: "extension-loader",
|
||||||
@ -21,6 +23,8 @@ const extensionLoaderInjectable = getInjectable({
|
|||||||
createExtensionInstance: di.inject(createExtensionInstanceInjectionToken),
|
createExtensionInstance: di.inject(createExtensionInstanceInjectionToken),
|
||||||
extensionInstances: di.inject(extensionInstancesInjectable),
|
extensionInstances: di.inject(extensionInstancesInjectable),
|
||||||
getExtension: (instance: LensExtension) => di.inject(extensionInjectable, instance),
|
getExtension: (instance: LensExtension) => di.inject(extensionInjectable, instance),
|
||||||
|
bundledExtensions: di.injectMany(bundledExtensionInjectionToken),
|
||||||
|
extensionEntryPointName: di.inject(extensionEntryPointNameInjectionToken),
|
||||||
logger: di.inject(loggerInjectable),
|
logger: di.inject(loggerInjectable),
|
||||||
joinPaths: di.inject(joinPathsInjectable),
|
joinPaths: di.inject(joinPathsInjectable),
|
||||||
getDirnameOfPath: di.inject(getDirnameOfPathInjectable),
|
getDirnameOfPath: di.inject(getDirnameOfPathInjectable),
|
||||||
|
|||||||
@ -21,12 +21,15 @@ import type { Extension } from "./extension/extension.injectable";
|
|||||||
import type { Logger } from "../../common/logger";
|
import type { Logger } from "../../common/logger";
|
||||||
import type { JoinPaths } from "../../common/path/join-paths.injectable";
|
import type { JoinPaths } from "../../common/path/join-paths.injectable";
|
||||||
import type { GetDirnameOfPath } from "../../common/path/get-dirname.injectable";
|
import type { GetDirnameOfPath } from "../../common/path/get-dirname.injectable";
|
||||||
|
import type { BundledExtension } from "../extension-discovery/bundled-extension-injection-token";
|
||||||
|
|
||||||
const logModule = "[EXTENSIONS-LOADER]";
|
const logModule = "[EXTENSIONS-LOADER]";
|
||||||
|
|
||||||
interface Dependencies {
|
interface Dependencies {
|
||||||
readonly extensionInstances: ObservableMap<LensExtensionId, LensExtension>;
|
readonly extensionInstances: ObservableMap<LensExtensionId, LensExtension>;
|
||||||
|
readonly bundledExtensions: BundledExtension[];
|
||||||
readonly logger: Logger;
|
readonly logger: Logger;
|
||||||
|
readonly extensionEntryPointName: "main" | "renderer";
|
||||||
updateExtensionsState: (extensionsState: Record<LensExtensionId, LensExtensionState>) => void;
|
updateExtensionsState: (extensionsState: Record<LensExtensionId, LensExtensionState>) => void;
|
||||||
createExtensionInstance: CreateExtensionInstance;
|
createExtensionInstance: CreateExtensionInstance;
|
||||||
getExtension: (instance: LensExtension) => Extension;
|
getExtension: (instance: LensExtension) => Extension;
|
||||||
@ -34,6 +37,12 @@ interface Dependencies {
|
|||||||
getDirnameOfPath: GetDirnameOfPath;
|
getDirnameOfPath: GetDirnameOfPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface SemiLoadedExtension {
|
||||||
|
instance: LensExtension;
|
||||||
|
installedExtension: InstalledExtension;
|
||||||
|
activated: Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ExtensionLoading {
|
export interface ExtensionLoading {
|
||||||
isBundled: boolean;
|
isBundled: boolean;
|
||||||
loaded: Promise<void>;
|
loaded: Promise<void>;
|
||||||
@ -248,14 +257,84 @@ export class ExtensionLoader {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async loadExtensions(installedExtensions: Map<string, InstalledExtension>) {
|
protected async loadBundledExtensions() {
|
||||||
|
return this.dependencies.bundledExtensions
|
||||||
|
.map(extension => {
|
||||||
|
try {
|
||||||
|
const LensExtensionClass = extension[this.dependencies.extensionEntryPointName]();
|
||||||
|
|
||||||
|
if (!LensExtensionClass) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const installedExtension: InstalledExtension = {
|
||||||
|
absolutePath: "irrelavent",
|
||||||
|
id: extension.manifest.name,
|
||||||
|
isBundled: true,
|
||||||
|
isCompatible: true,
|
||||||
|
isEnabled: true,
|
||||||
|
manifest: extension.manifest,
|
||||||
|
manifestPath: "irrelavent",
|
||||||
|
};
|
||||||
|
const instance = this.dependencies.createExtensionInstance(
|
||||||
|
LensExtensionClass,
|
||||||
|
installedExtension,
|
||||||
|
);
|
||||||
|
|
||||||
|
this.dependencies.extensionInstances.set(extension.manifest.name, instance);
|
||||||
|
|
||||||
|
return {
|
||||||
|
instance,
|
||||||
|
installedExtension,
|
||||||
|
activated: instance.activate(),
|
||||||
|
} as SemiLoadedExtension;
|
||||||
|
} catch (err) {
|
||||||
|
this.dependencies.logger.error(`${logModule}: error loading extension`, { ext: extension, err });
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter(isDefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async loadExtensions(extensions: SemiLoadedExtension[]): Promise<ExtensionLoading[]> {
|
||||||
|
// We first need to wait until each extension's `onActivate` is resolved or rejected,
|
||||||
|
// as this might register new catalog categories. Afterwards we can safely .enable the extension.
|
||||||
|
await Promise.all(
|
||||||
|
extensions.map(extension =>
|
||||||
|
// If extension activation fails, log error
|
||||||
|
extension.activated.catch((error) => {
|
||||||
|
this.dependencies.logger.error(`${logModule}: activation extension error`, { ext: extension.installedExtension, error });
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
extensions.forEach(({ instance }) => {
|
||||||
|
const extension = this.dependencies.getExtension(instance);
|
||||||
|
|
||||||
|
extension.register();
|
||||||
|
});
|
||||||
|
|
||||||
|
return extensions.map(extension => {
|
||||||
|
const loaded = extension.instance.enable().catch((err) => {
|
||||||
|
this.dependencies.logger.error(`${logModule}: failed to enable`, { ext: extension, err });
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
isBundled: extension.installedExtension.isBundled,
|
||||||
|
loaded,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async loadUserExtensions(installedExtensions: Map<string, InstalledExtension>) {
|
||||||
// Steps of the function:
|
// Steps of the function:
|
||||||
// 1. require and call .activate for each Extension
|
// 1. require and call .activate for each Extension
|
||||||
// 2. Wait until every extension's onActivate has been resolved
|
// 2. Wait until every extension's onActivate has been resolved
|
||||||
// 3. Call .enable for each extension
|
// 3. Call .enable for each extension
|
||||||
// 4. Return ExtensionLoading[]
|
// 4. Return ExtensionLoading[]
|
||||||
|
|
||||||
const extensions = [...installedExtensions.entries()]
|
return [...installedExtensions.entries()]
|
||||||
.map(([extId, extension]) => {
|
.map(([extId, extension]) => {
|
||||||
const alreadyInit = this.dependencies.extensionInstances.has(extId) || this.nonInstancesByName.has(extension.manifest.name);
|
const alreadyInit = this.dependencies.extensionInstances.has(extId) || this.nonInstancesByName.has(extension.manifest.name);
|
||||||
|
|
||||||
@ -280,7 +359,7 @@ export class ExtensionLoader {
|
|||||||
instance,
|
instance,
|
||||||
installedExtension: extension,
|
installedExtension: extension,
|
||||||
activated: instance.activate(),
|
activated: instance.activate(),
|
||||||
};
|
} as SemiLoadedExtension;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.dependencies.logger.error(`${logModule}: error loading extension`, { ext: extension, err });
|
this.dependencies.logger.error(`${logModule}: error loading extension`, { ext: extension, err });
|
||||||
}
|
}
|
||||||
@ -290,52 +369,33 @@ export class ExtensionLoader {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
})
|
})
|
||||||
// Remove null values
|
|
||||||
.filter(isDefined);
|
.filter(isDefined);
|
||||||
|
|
||||||
// We first need to wait until each extension's `onActivate` is resolved or rejected,
|
|
||||||
// as this might register new catalog categories. Afterwards we can safely .enable the extension.
|
|
||||||
await Promise.all(
|
|
||||||
extensions.map(extension =>
|
|
||||||
// If extension activation fails, log error
|
|
||||||
extension.activated.catch((error) => {
|
|
||||||
this.dependencies.logger.error(`${logModule}: activation extension error`, { ext: extension.installedExtension, error });
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
extensions.forEach(({ instance }) => {
|
|
||||||
const extension = this.dependencies.getExtension(instance);
|
|
||||||
|
|
||||||
extension.register();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Return ExtensionLoading[]
|
|
||||||
return extensions.map(extension => {
|
|
||||||
const loaded = extension.instance.enable().catch((err) => {
|
|
||||||
this.dependencies.logger.error(`${logModule}: failed to enable`, { ext: extension, err });
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
isBundled: extension.installedExtension.isBundled,
|
|
||||||
loaded,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
autoInitExtensions() {
|
async autoInitExtensions() {
|
||||||
this.dependencies.logger.info(`${logModule}: auto initializing extensions`);
|
this.dependencies.logger.info(`${logModule}: auto initializing extensions`);
|
||||||
|
|
||||||
// Setup reaction to load extensions on JSON changes
|
const bundledExtensions = await this.loadBundledExtensions();
|
||||||
reaction(() => this.toJSON(), installedExtensions => this.loadExtensions(installedExtensions));
|
const userExtensions = await this.loadUserExtensions(this.toJSON());
|
||||||
|
const loadedExtensions = await this.loadExtensions([
|
||||||
|
...bundledExtensions,
|
||||||
|
...userExtensions,
|
||||||
|
]);
|
||||||
|
|
||||||
// Load initial extensions
|
// Setup reaction to load extensions on JSON changes
|
||||||
return this.loadExtensions(this.toJSON());
|
reaction(() => this.toJSON(), installedExtensions => {
|
||||||
|
void (async () => {
|
||||||
|
const userExtensions = await this.loadUserExtensions(installedExtensions);
|
||||||
|
|
||||||
|
await this.loadExtensions(userExtensions);
|
||||||
|
})();
|
||||||
|
});
|
||||||
|
|
||||||
|
return loadedExtensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected requireExtension(extension: InstalledExtension): LensExtensionConstructor | null {
|
protected requireExtension(extension: InstalledExtension): LensExtensionConstructor | null {
|
||||||
const entryPointName = ipcRenderer ? "renderer" : "main";
|
const extRelativePath = extension.manifest[this.dependencies.extensionEntryPointName];
|
||||||
const extRelativePath = extension.manifest[entryPointName];
|
|
||||||
|
|
||||||
if (!extRelativePath) {
|
if (!extRelativePath) {
|
||||||
return null;
|
return null;
|
||||||
@ -348,7 +408,7 @@ export class ExtensionLoader {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = (error instanceof Error ? error.stack : undefined) || error;
|
const message = (error instanceof Error ? error.stack : undefined) || error;
|
||||||
|
|
||||||
this.dependencies.logger.error(`${logModule}: can't load ${entryPointName} for "${extension.manifest.name}": ${message}`, { extension });
|
this.dependencies.logger.error(`${logModule}: can't load ${this.dependencies.extensionEntryPointName} for "${extension.manifest.name}": ${message}`, { extension });
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import { extensionEntryPointNameInjectionToken } from "../../extensions/extension-loader/extension-entry-point-name-injection-token";
|
||||||
|
|
||||||
|
const extensionEntryPointNameInjectable = getInjectable({
|
||||||
|
id: "extension-entry-point-name",
|
||||||
|
instantiate: () => "main" as const,
|
||||||
|
injectionToken: extensionEntryPointNameInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default extensionEntryPointNameInjectable;
|
||||||
@ -15,7 +15,6 @@ const di = getDi();
|
|||||||
try {
|
try {
|
||||||
await startApp({
|
await startApp({
|
||||||
di,
|
di,
|
||||||
extensions: [],
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
@ -5,36 +5,13 @@
|
|||||||
|
|
||||||
import type { DiContainer } from "@ogre-tools/injectable";
|
import type { DiContainer } from "@ogre-tools/injectable";
|
||||||
import startMainApplicationInjectable from "./start-main-application/start-main-application.injectable";
|
import startMainApplicationInjectable from "./start-main-application/start-main-application.injectable";
|
||||||
import readJsonFileInjectable from "../common/fs/read-json-file.injectable";
|
|
||||||
import joinPathsInjectable from "../common/path/join-paths.injectable";
|
|
||||||
import type { LensExtensionManifest } from "../extensions/lens-extension";
|
|
||||||
import bundledExtensionsInjectable from "../extensions/extension-discovery/bundled-extensions.injectable";
|
|
||||||
|
|
||||||
interface AppConfig {
|
interface AppConfig {
|
||||||
di: DiContainer;
|
di: DiContainer;
|
||||||
extensions: { path: string }[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function startApp(conf: AppConfig) {
|
export async function startApp(conf: AppConfig) {
|
||||||
const { di, extensions } = conf;
|
const { di } = conf;
|
||||||
|
|
||||||
const bundledExtensions = di.inject(bundledExtensionsInjectable);
|
|
||||||
const readJson = di.inject(readJsonFileInjectable);
|
|
||||||
const joinPaths = di.inject(joinPathsInjectable);
|
|
||||||
|
|
||||||
for (const extension of extensions) {
|
|
||||||
const manifestPath = joinPaths(extension.path, "package.json");
|
|
||||||
|
|
||||||
bundledExtensions.push({
|
|
||||||
id: manifestPath,
|
|
||||||
manifest: (await readJson(manifestPath)) as unknown as LensExtensionManifest,
|
|
||||||
manifestPath,
|
|
||||||
absolutePath: extension.path,
|
|
||||||
isCompatible: true,
|
|
||||||
isBundled: true,
|
|
||||||
isEnabled: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const startMainApplication = di.inject(startMainApplicationInjectable);
|
const startMainApplication = di.inject(startMainApplicationInjectable);
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import { extensionEntryPointNameInjectionToken } from "../../extensions/extension-loader/extension-entry-point-name-injection-token";
|
||||||
|
|
||||||
|
const extensionEntryPointNameInjectable = getInjectable({
|
||||||
|
id: "extension-entry-point-name",
|
||||||
|
instantiate: () => "renderer" as const,
|
||||||
|
injectionToken: extensionEntryPointNameInjectionToken,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default extensionEntryPointNameInjectable;
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { getGlobalOverride } from "../../common/test-utils/get-global-override";
|
||||||
|
import applicationInformationInjectable from "../../common/vars/application-information-injectable";
|
||||||
|
|
||||||
|
export default getGlobalOverride(applicationInformationInjectable, () => ({
|
||||||
|
name: "some-product-name",
|
||||||
|
productName: "some-product-name",
|
||||||
|
version: "6.0.0",
|
||||||
|
build: {} as any,
|
||||||
|
config: {
|
||||||
|
k8sProxyVersion: "0.2.1",
|
||||||
|
bundledKubectlVersion: "1.23.3",
|
||||||
|
bundledHelmVersion: "3.7.2",
|
||||||
|
sentryDsn: "",
|
||||||
|
contentSecurityPolicy: "script-src 'unsafe-eval' 'self'; frame-src http://*.localhost:*/; img-src * data:",
|
||||||
|
welcomeRoute: "/welcome",
|
||||||
|
},
|
||||||
|
copyright: "some-copyright-information",
|
||||||
|
description: "some-descriptive-text",
|
||||||
|
}));
|
||||||
Loading…
Reference in New Issue
Block a user