Skip to content

Commit 10f9bf5

Browse files
committed
Expose function to launch app in main world
1 parent 6497fc9 commit 10f9bf5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

preload.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ console.log('preload')
22
const { contextBridge, ipcRenderer } = require('electron')
33
const path = require('path')
44
const shortcuts = require('./backend/shortcuts.js').shortcuts.global
5-
const { emit, platform } = require('process')
5+
const { platform } = require('process')
66
const SerialBridge = require('./backend/serial/serial-bridge.js')
77

88
const Disk = {
@@ -85,6 +85,21 @@ const Window = {
8585
getShortcuts: () => shortcuts
8686
}
8787

88+
/**
89+
* Launches an app using the provided URL scheme (e.g. myapp://). If the app is not installed, it will
90+
* fallback to open the provided fallback URL.
91+
* @param {string} url The URL scheme to use to launch the app
92+
* @param {string} fallbackUrl The URL to open if the app is not installed
93+
*/
94+
async function launchApp(url, fallbackUrl) {
95+
const success = await ipcRenderer.invoke('launch-app', url);
96+
97+
if (!success) {
98+
await ipcRenderer.invoke('open-url', fallbackUrl); // Fallback to open a URL in the default browser
99+
}
100+
}
101+
102+
contextBridge.exposeInMainWorld('launchApp', launchApp)
88103
contextBridge.exposeInMainWorld('BridgeSerial', SerialBridge)
89104
contextBridge.exposeInMainWorld('BridgeDisk', Disk)
90105
contextBridge.exposeInMainWorld('BridgeWindow', Window)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy