From 1cb4f8a1e7b6e945718fbfcbef9d3a3cde51ce93 Mon Sep 17 00:00:00 2001 From: Mark McDowell Date: Wed, 17 Jun 2020 17:14:29 +0100 Subject: [PATCH] feat(core): launching applications that come in through open-url url is registered and launched. --- .../events/openUrlApplicationEventsHandler.ts | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/packages/desktop-core/src/main/events/openUrlApplicationEventsHandler.ts b/packages/desktop-core/src/main/events/openUrlApplicationEventsHandler.ts index a875a9e9..ae2c6356 100644 --- a/packages/desktop-core/src/main/events/openUrlApplicationEventsHandler.ts +++ b/packages/desktop-core/src/main/events/openUrlApplicationEventsHandler.ts @@ -1,12 +1,31 @@ +import { ConfigurationKind } from "@reactivemarkets/desktop-types"; import { App } from "electron"; - -import { ReservedChannels } from "../../common"; -import { routerService } from "../router"; +import { uniqueNamesGenerator, adjectives, colors, animals } from "unique-names-generator"; +import { registryService } from "../registry"; +import { logger } from "../logging"; +import { configurationGenerator } from "../configuration"; +import { launcherService } from "../launcher"; export const registerOpenUrlEventsHandler = (app: App) => { - app.on("open-url", (_, url) => { - routerService.send(ReservedChannels.application_openUrl, { - url, - }); + app.on("open-url", async (event, url) => { + try { + event.preventDefault(); + + const configUrl = url.replace("desktop://", "https://"); + + const name = uniqueNamesGenerator({ + dictionaries: [adjectives, colors, animals], + }); + + const configuration = await configurationGenerator.generate(ConfigurationKind.Application, name, configUrl); + + await registryService.register(configuration); + + const instance = await launcherService.launch(configuration); + + logger.info(`Launched ${instance.kind}: ${instance.metadata.name}`); + } catch (error) { + logger.error(`Failed to launch from the protocol handler: ${error}`); + } }); };