-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.js
39 lines (29 loc) · 1.18 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const electron = require('electron');
const { electronAppUniversalProtocolClient } = require('electron-app-universal-protocol-client');
// Usually you want to run only one instance of your app to handle all requests in one context
if (!electron.app.requestSingleInstanceLock()) {
electron.app.exit(0);
}
electron.app.on('ready', async () => {
// Prepare your application, create windows etc.
const window = new electron.BrowserWindow();
window.loadURL('https://google.com');
// When you're ready to handle protocol requests, register the handler and initialize the client
electronAppUniversalProtocolClient.on(
'request',
async (requestUrl) => {
// Handle the request
await electron.dialog.showMessageBox(
window,
{
message: `Request received: ${requestUrl}`,
}
);
},
);
await electronAppUniversalProtocolClient.initialize({
protocol: 'your-app-id3',
mode: 'development', // Make sure to use 'production' when script is executed in bundled app
});
// At this point accessing URLs like your-app-id://test?foo=bar should open your app and trigger the 'request' event
});