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:
parent
b6a17eb1be
commit
28b49cc8f2
@ -73,7 +73,7 @@ export class ExtensionLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all([this.whenLoaded, extensionsStore.whenLoaded]);
|
await Promise.all([this.whenLoaded, extensionsStore.whenLoaded]);
|
||||||
|
|
||||||
// save state on change `extension.isEnabled`
|
// save state on change `extension.isEnabled`
|
||||||
reaction(() => this.storeState, extensionsState => {
|
reaction(() => this.storeState, extensionsState => {
|
||||||
extensionsStore.mergeState(extensionsState);
|
extensionsStore.mergeState(extensionsState);
|
||||||
@ -149,7 +149,7 @@ export class ExtensionLoader {
|
|||||||
this.syncExtensions(extensions);
|
this.syncExtensions(extensions);
|
||||||
|
|
||||||
const receivedExtensionIds = extensions.map(([lensExtensionId]) => lensExtensionId);
|
const receivedExtensionIds = extensions.map(([lensExtensionId]) => lensExtensionId);
|
||||||
|
|
||||||
// Remove deleted extensions in renderer side only
|
// Remove deleted extensions in renderer side only
|
||||||
this.extensions.forEach((_, lensExtensionId) => {
|
this.extensions.forEach((_, lensExtensionId) => {
|
||||||
if (!receivedExtensionIds.includes(lensExtensionId)) {
|
if (!receivedExtensionIds.includes(lensExtensionId)) {
|
||||||
@ -301,6 +301,10 @@ export class ExtensionLoader {
|
|||||||
return this.extensions.get(extId);
|
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.
|
* Get url to the tarball of the extension package. Assumes package is found from npm regisry.
|
||||||
* @param packageName e.g. "@mirantis/lens-extension-cc"
|
* @param packageName e.g. "@mirantis/lens-extension-cc"
|
||||||
|
|||||||
@ -22,7 +22,7 @@ export class LensExtension {
|
|||||||
readonly manifestPath: string;
|
readonly manifestPath: string;
|
||||||
readonly isBundled: boolean;
|
readonly isBundled: boolean;
|
||||||
|
|
||||||
@observable private isEnabled = false;
|
@observable isEnabled = false;
|
||||||
|
|
||||||
constructor({ id, manifest, manifestPath, isBundled }: InstalledExtension) {
|
constructor({ id, manifest, manifestPath, isBundled }: InstalledExtension) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|||||||
@ -4,6 +4,8 @@ import { match, matchPath } from "react-router";
|
|||||||
import { pathToRegexp } from "path-to-regexp";
|
import { pathToRegexp } from "path-to-regexp";
|
||||||
import { subscribeToBroadcast } from "../../common/ipc";
|
import { subscribeToBroadcast } from "../../common/ipc";
|
||||||
import logger from "../logger";
|
import logger from "../logger";
|
||||||
|
import { extensionLoader } from "../../extensions/extension-loader";
|
||||||
|
import { sanitizeExtensionName } from "../../extensions/lens-extension";
|
||||||
|
|
||||||
export enum RoutingErrorType {
|
export enum RoutingErrorType {
|
||||||
INVALID_PROTOCOL = "invalid-protocol",
|
INVALID_PROTOCOL = "invalid-protocol",
|
||||||
@ -117,10 +119,13 @@ export class LensProtocolRouter extends Singleton {
|
|||||||
|
|
||||||
if (!routes) {
|
if (!routes) {
|
||||||
if (this.missingExtensionHandler) {
|
if (this.missingExtensionHandler) {
|
||||||
|
const enabledPromise = extensionLoader.instanceToBeEnabled(sanitizeExtensionName(name));
|
||||||
|
|
||||||
if (!await this.missingExtensionHandler(name)) {
|
if (!await this.missingExtensionHandler(name)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await enabledPromise;
|
||||||
routes = this.extentionRoutes.get(name);
|
routes = this.extentionRoutes.get(name);
|
||||||
|
|
||||||
if (!routes) {
|
if (!routes) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user