@@ -2,7 +2,7 @@ console.log('preload')
2
2
const { contextBridge, ipcRenderer } = require ( 'electron' )
3
3
const path = require ( 'path' )
4
4
const shortcuts = require ( './backend/shortcuts.js' ) . shortcuts . global
5
- const { emit , platform } = require ( 'process' )
5
+ const { platform } = require ( 'process' )
6
6
const SerialBridge = require ( './backend/serial/serial-bridge.js' )
7
7
8
8
const Disk = {
@@ -85,6 +85,21 @@ const Window = {
85
85
getShortcuts : ( ) => shortcuts
86
86
}
87
87
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 )
88
103
contextBridge . exposeInMainWorld ( 'BridgeSerial' , SerialBridge )
89
104
contextBridge . exposeInMainWorld ( 'BridgeDisk' , Disk )
90
105
contextBridge . exposeInMainWorld ( 'BridgeWindow' , Window )
0 commit comments