This repository has been archived by the owner on Jul 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): launching applications that come in through open-url
url is registered and launched.
- Loading branch information
1 parent
d92c674
commit 1cb4f8a
Showing
1 changed file
with
26 additions
and
7 deletions.
There are no files selected for viewing
33 changes: 26 additions & 7 deletions
33
packages/desktop-core/src/main/events/openUrlApplicationEventsHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
}); | ||
}; |