1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Make sure that extensions have been initialized before exposing them as enabled extensions

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2021-12-09 07:41:43 +02:00
parent 41837e86bb
commit f9cf08b4a8
No known key found for this signature in database
GPG Key ID: 5F465B5672372402
3 changed files with 18 additions and 11 deletions

View File

@ -46,7 +46,7 @@ const logModule = "[EXTENSIONS-LOADER]";
*/
export class ExtensionLoader extends Singleton {
protected extensions = observable.map<LensExtensionId, InstalledExtension>();
instances = observable.map<LensExtensionId, LensExtension>();
protected instances = observable.map<LensExtensionId, LensExtension>();
/**
* This is the set of extensions that don't come with either
@ -96,6 +96,10 @@ export class ExtensionLoader extends Singleton {
});
}
@computed get enabledExtensionInstances() : LensExtension[] {
return [...this.instances.values()].filter(extension => extension.isEnabled);
}
@computed get userExtensions(): Map<LensExtensionId, InstalledExtension> {
const extensions = this.toJSON();

View File

@ -28,15 +28,13 @@ const extensionsInjectable: Injectable<
{ extensionLoader: ExtensionLoader }
> = {
getDependencies: () => ({
extensionLoader: ExtensionLoader.createInstance(),
extensionLoader: ExtensionLoader.getInstance(),
}),
lifecycle: lifecycleEnum.singleton,
instantiate: ({ extensionLoader }) =>
computed(() =>
[...extensionLoader.instances.values()],
),
computed(() => extensionLoader.enabledExtensionInstances),
};
export default extensionsInjectable;

View File

@ -20,7 +20,7 @@
*/
import type { InstalledExtension } from "./extension-discovery";
import { action, observable, makeObservable } from "mobx";
import { action, observable, makeObservable, computed } from "mobx";
import { FilesystemProvisionerStore } from "../main/extension-filesystem";
import logger from "../main/logger";
import type { ProtocolHandlerRegistration } from "./registries";
@ -47,7 +47,12 @@ export class LensExtension {
protocolHandlers: ProtocolHandlerRegistration[] = [];
@observable private isEnabled = false;
@observable private _isEnabled = false;
@computed get isEnabled() {
return this._isEnabled;
}
[Disposers] = disposer();
constructor({ id, manifest, manifestPath, isBundled }: InstalledExtension) {
@ -83,13 +88,13 @@ export class LensExtension {
@action
async enable(register: (ext: LensExtension) => Promise<Disposer[]>) {
if (this.isEnabled) {
if (this._isEnabled) {
return;
}
try {
await this.onActivate();
this.isEnabled = true;
this._isEnabled = true;
this[Disposers].push(...await register(this));
logger.info(`[EXTENSION]: enabled ${this.name}@${this.version}`);
@ -100,11 +105,11 @@ export class LensExtension {
@action
async disable() {
if (!this.isEnabled) {
if (!this._isEnabled) {
return;
}
this.isEnabled = false;
this._isEnabled = false;
try {
await this.onDeactivate();