mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
extensions-api -- in-progress - PoC: activate all loading extensions
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
14fb185792
commit
7f646da312
@ -1,13 +1,13 @@
|
|||||||
import { LensExtension, LensRendererRuntimeEnv } from "@lens/extensions"; // fixme: map to generated types from "extension-api.d.ts"
|
import { LensExtension } from "@lens/extensions"; // fixme: map to generated types from "extension-api.d.ts"
|
||||||
|
|
||||||
export default class ExampleExtension extends LensExtension {
|
export default class ExampleExtension extends LensExtension {
|
||||||
async activate(runtime: LensRendererRuntimeEnv): Promise<any> {
|
async activate(): Promise<any> {
|
||||||
await super.activate(runtime);
|
await super.activate();
|
||||||
console.log('Example extension: activate');
|
console.warn('EXAMPLE EXTENSION: ACTIVATE'.padStart(10, "-"));
|
||||||
}
|
}
|
||||||
|
|
||||||
async deactivate(): Promise<any> {
|
async deactivate(): Promise<any> {
|
||||||
console.log('Example extension: deactivate')
|
console.warn('EXAMPLE EXTENSION: DEACTIVATE'.padStart(10, "-"))
|
||||||
await super.deactivate();
|
await super.deactivate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
// Lens-extensions api developer's kit
|
// Lens-extensions api developer's kit
|
||||||
|
|
||||||
export type { LensRendererRuntimeEnv } from "./extension-api.runtime";
|
export type { LensRendererRuntimeEnv } from "./extension-api.runtime";
|
||||||
|
|
||||||
export * from "./extension"
|
export * from "./extension"
|
||||||
|
|||||||
@ -25,7 +25,7 @@ export interface InstalledExtension<T extends ExtensionModel = any> {
|
|||||||
manifest: ExtensionManifest;
|
manifest: ExtensionManifest;
|
||||||
extensionModule: {
|
extensionModule: {
|
||||||
[name: string]: any;
|
[name: string]: any;
|
||||||
default: new (model: T, manifest?: ExtensionManifest) => LensExtension
|
default: new (model: ExtensionModel, manifest?: ExtensionManifest) => LensExtension
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,6 +75,13 @@ export class ExtensionStore extends BaseStore<ExtensionStoreModel> {
|
|||||||
async loadInstalledExtensions() {
|
async loadInstalledExtensions() {
|
||||||
const extensions = await this.loadExtensions(this.folderPath);
|
const extensions = await this.loadExtensions(this.folderPath);
|
||||||
this.installed.replace(extensions.map(ext => [ext.manifestPath, ext]));
|
this.installed.replace(extensions.map(ext => [ext.manifestPath, ext]));
|
||||||
|
|
||||||
|
// todo: remove
|
||||||
|
extensions.forEach(({ extensionModule, manifest }) => {
|
||||||
|
const LensExtension = extensionModule.default;
|
||||||
|
const instance = new LensExtension({ ...manifest }, manifest);
|
||||||
|
instance.activate();
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadExtensions(folderPath: string): Promise<InstalledExtension[]> {
|
async loadExtensions(folderPath: string): Promise<InstalledExtension[]> {
|
||||||
|
|||||||
@ -38,14 +38,12 @@ export class LensExtension implements ExtensionModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async activate(params: LensRendererRuntimeEnv) {
|
async activate() {
|
||||||
logger.info(`[EXTENSION]: activate ${this.name}@${this.version}`, this.getMeta());
|
logger.info(`[EXTENSION]: activate ${this.name}@${this.version}`, this.getMeta());
|
||||||
this.runtime = params;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async deactivate() {
|
async deactivate() {
|
||||||
logger.info(`[EXTENSION]: deactivate ${this.name}@${this.version}`, this.getMeta());
|
logger.info(`[EXTENSION]: deactivate ${this.name}@${this.version}`, this.getMeta());
|
||||||
this.runtime = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async enable() {
|
async enable() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user