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 committed 2021-12-09 07:41:43 +02:00
1 parent 41837e86bb
commit f9cf08b4a8
3 files changed
+18 -11

No files matched your search

+11 -6
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();