diff --git a/src/common/protocol-handler/error.ts b/src/common/protocol-handler/error.ts index d25516bb22..ebe7adccd7 100644 --- a/src/common/protocol-handler/error.ts +++ b/src/common/protocol-handler/error.ts @@ -27,8 +27,6 @@ export class RoutingError extends Error { return "invalid protocol"; case RoutingErrorType.INVALID_PATHNAME: return "invalid pathname"; - case RoutingErrorType.NO_HANDLER: - return "no handler"; case RoutingErrorType.NO_EXTENSION_ID: return "no extension ID"; case RoutingErrorType.MISSING_EXTENSION: diff --git a/src/common/protocol-handler/router.ts b/src/common/protocol-handler/router.ts index e99f291e9e..d533a87723 100644 --- a/src/common/protocol-handler/router.ts +++ b/src/common/protocol-handler/router.ts @@ -110,11 +110,17 @@ export abstract class LensProtocolRouter extends Singleton { * @param routes the array of (path schemas, handler) paris to match against * @param url the url (in its current state) */ - protected _route(routes: [string, RouteHandler][], url: Url): void { + protected _route(routes: [string, RouteHandler][], url: Url, extensionName?: string): void { const route = this._findMatchingRoute(routes, url); if (!route) { - throw new RoutingError(RoutingErrorType.NO_HANDLER, url); + const data: Record = { url: url.toString() }; + + if (extensionName) { + data.extensionName = extensionName; + } + + return void logger.info(`${LensProtocolRouter.LoggingPrefix}: No handler found`, data); } const [match, handler] = route; @@ -198,7 +204,7 @@ export abstract class LensProtocolRouter extends Singleton { .map<[string, RouteHandler]>(({ pathSchema, handler }) => [pathSchema, handler]); try { - this._route(handlers, url); + this._route(handlers, url, extension.name); } catch (error) { if (error instanceof RoutingError) { error.extensionName = extension.name; diff --git a/src/main/protocol-handler/router.ts b/src/main/protocol-handler/router.ts index 57f2223919..fb9fc173c0 100644 --- a/src/main/protocol-handler/router.ts +++ b/src/main/protocol-handler/router.ts @@ -70,12 +70,16 @@ export class LensProtocolRouterMain extends proto.LensProtocolRouter { } protected _routeToInternal(url: Url): void { + const rawUrl = url.toString(); // for sending to renderer + super._routeToInternal(url); - broadcastMessage(proto.ProtocolHandlerInternal, url); + broadcastMessage(proto.ProtocolHandlerInternal, rawUrl); } protected async _routeToExtension(url: Url): Promise { + const rawUrl = url.toString(); // for sending to renderer + /** * This needs to be done first, so that the missing extension handlers can * be called before notifying the renderer. @@ -85,7 +89,7 @@ export class LensProtocolRouterMain extends proto.LensProtocolRouter { */ await super._routeToExtension(new Url(url.toString(), true)); - broadcastMessage(proto.ProtocolHandlerExtension, url); + broadcastMessage(proto.ProtocolHandlerExtension, rawUrl); } /** diff --git a/src/renderer/lens-app.tsx b/src/renderer/lens-app.tsx index 5c0dd79a95..d588206c01 100644 --- a/src/renderer/lens-app.tsx +++ b/src/renderer/lens-app.tsx @@ -12,11 +12,13 @@ import { ConfirmDialog } from "./components/confirm-dialog"; import { extensionLoader } from "../extensions/extension-loader"; import { broadcastMessage } from "../common/ipc"; import { CommandContainer } from "./components/command-palette/command-container"; +import { LensProtocolRouterRenderer } from "./protocol-handler/router"; @observer export class LensApp extends React.Component { static async init() { extensionLoader.loadOnClusterManagerRenderer(); + LensProtocolRouterRenderer.getInstance().init(); window.addEventListener("offline", () => { broadcastMessage("network:offline"); }); diff --git a/src/renderer/protocol-handler/router.ts b/src/renderer/protocol-handler/router.ts index c267e42977..d1dc0ceafd 100644 --- a/src/renderer/protocol-handler/router.ts +++ b/src/renderer/protocol-handler/router.ts @@ -1,6 +1,9 @@ import { ipcRenderer } from "electron"; import * as proto from "../../common/protocol-handler"; import logger from "../../main/logger"; +import Url from "url-parse"; +import { autobind } from "../utils"; + export class LensProtocolRouterRenderer extends proto.LensProtocolRouter { /** * This function is needed to be called early on in the renderers lifetime. @@ -11,19 +14,27 @@ export class LensProtocolRouterRenderer extends proto.LensProtocolRouter { .on(proto.ProtocolHandlerExtension, this.ipcExtensionHandler); } + @autobind() private ipcInternalHandler(event: Electron.IpcRendererEvent, ...args: any[]): void { if (args.length !== 1) { return void logger.warn(`${proto.LensProtocolRouter.LoggingPrefix}: unexpected number of args`, { args }); } - console.log(args[0]); + const [rawUrl] = args; + const url = new Url(rawUrl, true); + + this._routeToInternal(url); } + @autobind() private ipcExtensionHandler(event: Electron.IpcRendererEvent, ...args: any[]): void { if (args.length !== 1) { return void logger.warn(`${proto.LensProtocolRouter.LoggingPrefix}: unexpected number of args`, { args }); } - console.log(args[0]); + const [rawUrl] = args; + const url = new Url(rawUrl, true); + + this._routeToExtension(url); } }