Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

Commit

Permalink
feat(core): launching applications that come in through open-url
Browse files Browse the repository at this point in the history
url is registered and launched.
  • Loading branch information
markmcdowell committed Jun 17, 2020
1 parent d92c674 commit 1cb4f8a
Showing 1 changed file with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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}`);
}
});
};

0 comments on commit 1cb4f8a

Please sign in to comment.