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

add waiting for extension to be enabled

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2020-12-09 15:16:18 -05:00
parent b6a17eb1be
commit 28b49cc8f2
3 changed files with 12 additions and 3 deletions

View File

@ -73,7 +73,7 @@ export class ExtensionLoader {
}
await Promise.all([this.whenLoaded, extensionsStore.whenLoaded]);
// save state on change `extension.isEnabled`
reaction(() => this.storeState, extensionsState => {
extensionsStore.mergeState(extensionsState);
@ -149,7 +149,7 @@ export class ExtensionLoader {
this.syncExtensions(extensions);
const receivedExtensionIds = extensions.map(([lensExtensionId]) => lensExtensionId);
// Remove deleted extensions in renderer side only
this.extensions.forEach((_, lensExtensionId) => {
if (!receivedExtensionIds.includes(lensExtensionId)) {
@ -301,6 +301,10 @@ export class ExtensionLoader {
return this.extensions.get(extId);
}
public async instanceToBeEnabled(extId: LensExtensionId): Promise<void> {
return when(() => this.instances.get(extId)?.isEnabled);
}
/**
* Get url to the tarball of the extension package. Assumes package is found from npm regisry.
* @param packageName e.g. "@mirantis/lens-extension-cc"

View File

@ -22,7 +22,7 @@ export class LensExtension {
readonly manifestPath: string;
readonly isBundled: boolean;
@observable private isEnabled = false;
@observable isEnabled = false;
constructor({ id, manifest, manifestPath, isBundled }: InstalledExtension) {
this.id = id;

View File

@ -4,6 +4,8 @@ import { match, matchPath } from "react-router";
import { pathToRegexp } from "path-to-regexp";
import { subscribeToBroadcast } from "../../common/ipc";
import logger from "../logger";
import { extensionLoader } from "../../extensions/extension-loader";
import { sanitizeExtensionName } from "../../extensions/lens-extension";
export enum RoutingErrorType {
INVALID_PROTOCOL = "invalid-protocol",
@ -117,10 +119,13 @@ export class LensProtocolRouter extends Singleton {
if (!routes) {
if (this.missingExtensionHandler) {
const enabledPromise = extensionLoader.instanceToBeEnabled(sanitizeExtensionName(name));
if (!await this.missingExtensionHandler(name)) {
return;
}
await enabledPromise;
routes = this.extentionRoutes.get(name);
if (!routes) {