@@ -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' ) . 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 = {
@@ -80,6 +80,21 @@ const Window = {
80
80
getShortcuts : ( ) => shortcuts
81
81
}
82
82
83
+ /**
84
+ * Launches an app using the provided URL scheme (e.g. myapp://). If the app is not installed, it will
85
+ * fallback to open the provided fallback URL.
86
+ * @param {string } url The URL scheme to use to launch the app
87
+ * @param {string } fallbackUrl The URL to open if the app is not installed
88
+ */
89
+ async function launchApp ( url , fallbackUrl ) {
90
+ const success = await ipcRenderer . invoke ( 'launch-app' , url ) ;
91
+
92
+ if ( ! success ) {
93
+ await ipcRenderer . invoke ( 'open-url' , fallbackUrl ) ; // Fallback to open a URL in the default browser
94
+ }
95
+ }
96
+
97
+ contextBridge . exposeInMainWorld ( 'launchApp' , launchApp )
83
98
contextBridge . exposeInMainWorld ( 'BridgeSerial' , SerialBridge )
84
99
contextBridge . exposeInMainWorld ( 'BridgeDisk' , Disk )
85
100
contextBridge . exposeInMainWorld ( 'BridgeWindow' , Window )
0 commit comments