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

lens:// routing shouldn't ignore intree extensions (#3091)

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-06-18 10:19:13 -04:00 committed by GitHub
parent 8a0cb2602b
commit 4ff5a722a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 25 deletions

View File

@ -179,7 +179,7 @@ export abstract class LensProtocolRouter extends Singleton {
const { [EXTENSION_PUBLISHER_MATCH]: publisher, [EXTENSION_NAME_MATCH]: partialName } = match.params; const { [EXTENSION_PUBLISHER_MATCH]: publisher, [EXTENSION_NAME_MATCH]: partialName } = match.params;
const name = [publisher, partialName].filter(Boolean).join("/"); const name = [publisher, partialName].filter(Boolean).join("/");
const extension = ExtensionLoader.getInstance().userExtensionsByName.get(name); const extension = ExtensionLoader.getInstance().getInstanceByName(name);
if (!extension) { if (!extension) {
logger.info(`${LensProtocolRouter.LoggingPrefix}: Extension ${name} matched, but not installed`); logger.info(`${LensProtocolRouter.LoggingPrefix}: Extension ${name} matched, but not installed`);

View File

@ -22,7 +22,7 @@
import { app, ipcRenderer, remote } from "electron"; import { app, ipcRenderer, remote } from "electron";
import { EventEmitter } from "events"; import { EventEmitter } from "events";
import { isEqual } from "lodash"; import { isEqual } from "lodash";
import { action, computed, makeObservable, observable, reaction, when } from "mobx"; import { action, computed, makeObservable, observable, observe, reaction, when } from "mobx";
import path from "path"; import path from "path";
import { getHostedCluster } from "../common/cluster-store"; import { getHostedCluster } from "../common/cluster-store";
import { broadcastMessage, ipcMainOn, ipcRendererOn, requestMain, ipcMainHandle } from "../common/ipc"; import { broadcastMessage, ipcMainOn, ipcRendererOn, requestMain, ipcMainHandle } from "../common/ipc";
@ -48,6 +48,11 @@ export class ExtensionLoader extends Singleton {
protected extensions = observable.map<LensExtensionId, InstalledExtension>(); protected extensions = observable.map<LensExtensionId, InstalledExtension>();
protected instances = observable.map<LensExtensionId, LensExtension>(); protected instances = observable.map<LensExtensionId, LensExtension>();
/**
* This is updated by the `observe` in the constructor. DO NOT write directly to it
*/
protected instancesByName = observable.map<string, LensExtension>();
// IPC channel to broadcast changes to extensions from main // IPC channel to broadcast changes to extensions from main
protected static readonly extensionsMainChannel = "extensions:main"; protected static readonly extensionsMainChannel = "extensions:main";
@ -65,8 +70,23 @@ export class ExtensionLoader extends Singleton {
constructor() { constructor() {
super(); super();
makeObservable(this); makeObservable(this);
observe(this.instances, change => {
switch (change.type) {
case "add":
if (this.instancesByName.has(change.newValue.name)) {
throw new TypeError("Extension names must be unique");
}
this.instancesByName.set(change.newValue.name, change.newValue);
break;
case "delete":
this.instancesByName.delete(change.oldValue.name);
break;
case "update":
throw new Error("Extension instances shouldn't be updated");
}
});
} }
@computed get userExtensions(): Map<LensExtensionId, InstalledExtension> { @computed get userExtensions(): Map<LensExtensionId, InstalledExtension> {
@ -81,28 +101,8 @@ export class ExtensionLoader extends Singleton {
return extensions; return extensions;
} }
@computed get userExtensionsByName(): Map<string, LensExtension> { getInstanceByName(name: string): LensExtension | undefined {
const extensions = new Map(); return this.instancesByName.get(name);
for (const [, val] of this.instances.toJSON()) {
if (val.isBundled) {
continue;
}
extensions.set(val.manifest.name, val);
}
return extensions;
}
getExtensionByName(name: string): LensExtension | null {
for (const [, val] of this.instances) {
if (val.name === name) {
return val;
}
}
return null;
} }
// Transform userExtensions to a state object for storing into ExtensionsStore // Transform userExtensions to a state object for storing into ExtensionsStore