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

switch to registering the handler

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2020-12-08 10:21:44 -05:00
parent 0c6a7ba9e4
commit 2445ea1d8a
2 changed files with 14 additions and 15 deletions

View File

@ -2,7 +2,9 @@ import AwaitLock from "await-lock";
import child_process from "child_process"; import child_process from "child_process";
import fs from "fs-extra"; import fs from "fs-extra";
import path from "path"; import path from "path";
import { autobind } from "../common/utils";
import logger from "../main/logger"; import logger from "../main/logger";
import { LensProtocolRouter } from "../main/protocol-handler";
import { extensionPackagesRoot } from "./extension-loader"; import { extensionPackagesRoot } from "./extension-loader";
const logModule = "[EXTENSION-INSTALLER]"; const logModule = "[EXTENSION-INSTALLER]";
@ -20,6 +22,13 @@ export type PackageJson = {
* Installs dependencies for extensions * Installs dependencies for extensions
*/ */
export class ExtensionInstaller { export class ExtensionInstaller {
constructor() {
const lpr = LensProtocolRouter.getInstance<LensProtocolRouter>();
lpr.on("/install-extension", this.protocolHandlerInstall);
}
private installLock = new AwaitLock(); private installLock = new AwaitLock();
get extensionPackagesRoot() { get extensionPackagesRoot() {
@ -30,6 +39,11 @@ export class ExtensionInstaller {
return __non_webpack_require__.resolve("npm/bin/npm-cli"); return __non_webpack_require__.resolve("npm/bin/npm-cli");
} }
@autobind()
protocolHandlerInstall(): void {
console.log("Installing");
}
installDependencies(): Promise<void> { installDependencies(): Promise<void> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
logger.info(`${logModule} installing dependencies at ${extensionPackagesRoot()}`); logger.info(`${logModule} installing dependencies at ${extensionPackagesRoot()}`);

View File

@ -68,8 +68,6 @@ export class LensProtocolRouter extends Singleton {
return this._route(this.internalRoutes, url); return this._route(this.internalRoutes, url);
case "extension": case "extension":
return this._routeToExtension(url); return this._routeToExtension(url);
case "main":
return this._routeToMain(url);
default: default:
throw new RoutingError(RoutingErrorType.INVALID_HOST, url); throw new RoutingError(RoutingErrorType.INVALID_HOST, url);
@ -93,19 +91,6 @@ export class LensProtocolRouter extends Singleton {
this._route(routes, url, true); this._route(routes, url, true);
} }
private _routeToMain(url: Url): void {
if (url.pathname === "/install-extension") {
// .query is e.g. {"@mirantis/lens-extension-cc": ""}, convert it to "@mirantis/lens-extension-cc"
const packageName = Object.keys(url.query)[0];
console.log(`Installing ${packageName} from lens:// url`);
// TODO: Open extensions page
} else {
throw new RoutingError(RoutingErrorType.INVALID_PATHNAME, url);
}
}
private _route(routes: Map<string, RouteHandler>, url: Url, matchExtension = false): void { private _route(routes: Map<string, RouteHandler>, url: Url, matchExtension = false): void {
const matches = Array.from(routes.entries()) const matches = Array.from(routes.entries())
.map(([schema, handler]): [match<Record<string, string>>, RouteHandler] => { .map(([schema, handler]): [match<Record<string, string>>, RouteHandler] => {