Add IPC capabilities for Extensions (#2775)

* Add IPC capabilities for Extensions

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* revert onA|D change:

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Switch to pushing the disposer in the methods

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* improve documentation, switch to a singleton instead of extension methods

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix build

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* make exported class abstract, improve guide

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix docs

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix lint

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Change guide demo to initialization in constructor

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-05-18 12:24:43 +03:00
1 parent e188cf45e6
commit 6be465858b
14 files changed
+375 -52

No files matched your search

+16 -11
View File
@@ -23,7 +23,8 @@ import type { InstalledExtension } from "./extension-discovery";
import { action, observable, reaction } from "mobx";
import { FilesystemProvisionerStore } from "../main/extension-filesystem";
import logger from "../main/logger";
import { ProtocolHandlerRegistration } from "./registries/protocol-handler-registry";
import { ProtocolHandlerRegistration } from "./registries";
import { disposer } from "../common/utils";
export type LensExtensionId = string; // path to manifest (package.json)
export type LensExtensionConstructor = new (...args: ConstructorParameters<typeof LensExtension>) => LensExtension;
@@ -37,6 +38,8 @@ export interface LensExtensionManifest {
lens?: object; // fixme: add more required fields for validation
}
export const Disposers = Symbol();
export class LensExtension {
readonly id: LensExtensionId;
readonly manifest: LensExtensionManifest;
@@ -46,6 +49,7 @@ export class LensExtension {
protocolHandlers: ProtocolHandlerRegistration[] = [];
@observable private isEnabled = false;
[Disposers] = disposer();
constructor({ id, manifest, manifestPath, isBundled }: InstalledExtension) {
this.id = id;
@@ -62,6 +66,10 @@ export class LensExtension {
return this.manifest.version;
}
get description() {
return this.manifest.description;
}
/**
* getExtensionFileFolder returns the path to an already created folder. This
* folder is for the sole use of this extension.
@@ -73,15 +81,11 @@ export class LensExtension {
return FilesystemProvisionerStore.getInstance().requestDirectory(this.id);
}
get description() {
return this.manifest.description;
}
@action
async enable() {
if (this.isEnabled) return;
this.isEnabled = true;
this.onActivate();
this.onActivate?.();
logger.info(`[EXTENSION]: enabled ${this.name}@${this.version}`);
}
@@ -89,7 +93,8 @@ export class LensExtension {
async disable() {
if (!this.isEnabled) return;
this.isEnabled = false;
this.onDeactivate();
this.onDeactivate?.();
this[Disposers]();
logger.info(`[EXTENSION]: disabled ${this.name}@${this.version}`);
}
@@ -125,12 +130,12 @@ export class LensExtension {
};
}
protected onActivate() {
// mock
protected onActivate(): void {
return;
}
protected onDeactivate() {
// mock
protected onDeactivate(): void {
return;
}
}