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:
parent
0c6a7ba9e4
commit
2445ea1d8a
@ -2,7 +2,9 @@ import AwaitLock from "await-lock";
|
||||
import child_process from "child_process";
|
||||
import fs from "fs-extra";
|
||||
import path from "path";
|
||||
import { autobind } from "../common/utils";
|
||||
import logger from "../main/logger";
|
||||
import { LensProtocolRouter } from "../main/protocol-handler";
|
||||
import { extensionPackagesRoot } from "./extension-loader";
|
||||
|
||||
const logModule = "[EXTENSION-INSTALLER]";
|
||||
@ -20,6 +22,13 @@ export type PackageJson = {
|
||||
* Installs dependencies for extensions
|
||||
*/
|
||||
export class ExtensionInstaller {
|
||||
|
||||
constructor() {
|
||||
const lpr = LensProtocolRouter.getInstance<LensProtocolRouter>();
|
||||
|
||||
lpr.on("/install-extension", this.protocolHandlerInstall);
|
||||
}
|
||||
|
||||
private installLock = new AwaitLock();
|
||||
|
||||
get extensionPackagesRoot() {
|
||||
@ -30,6 +39,11 @@ export class ExtensionInstaller {
|
||||
return __non_webpack_require__.resolve("npm/bin/npm-cli");
|
||||
}
|
||||
|
||||
@autobind()
|
||||
protocolHandlerInstall(): void {
|
||||
console.log("Installing");
|
||||
}
|
||||
|
||||
installDependencies(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
logger.info(`${logModule} installing dependencies at ${extensionPackagesRoot()}`);
|
||||
|
||||
@ -68,8 +68,6 @@ export class LensProtocolRouter extends Singleton {
|
||||
return this._route(this.internalRoutes, url);
|
||||
case "extension":
|
||||
return this._routeToExtension(url);
|
||||
case "main":
|
||||
return this._routeToMain(url);
|
||||
default:
|
||||
throw new RoutingError(RoutingErrorType.INVALID_HOST, url);
|
||||
|
||||
@ -93,19 +91,6 @@ export class LensProtocolRouter extends Singleton {
|
||||
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 {
|
||||
const matches = Array.from(routes.entries())
|
||||
.map(([schema, handler]): [match<Record<string, string>>, RouteHandler] => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user