I'm developing an app in Electron and I need to handle a custom protocol inside this app.
I'm using app.setAsDefaultProtocolClient(PROTOCOL)
for that.
I am using "open-url" for macOS to handle the URL with my custom protocol and it is working smoothly but I can't figure it out on Windows. I'm sending some data in the URL so just opening the window won't work.
I checked this answer, but this was answered in 2016 and the method makeSingleInstance
is now deprecated. In the docs, it suggests to use requestSingleInstanceLock
but it doesn't take any callbacks or return URL.
So how can I enable the same feature in both macOS and Windows?
Code
index.js
app.on('ready', () => createWindow(`file://${__dirname}/views/welcome.html`));
app.on('activate', () => {
// eslint-disable-next-line no-shadow,global-require
const { mainWindow } = require('./utils/createWindow');
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createWindow(`file://${__dirname}/views/welcome.html`);
}
});
app.on('open-url', handleOpenURL);
app.setAsDefaultProtocolClient(PROTOCOL);
handleOpenURL.js
module.exports = (e, data) => {
e.preventDefault();
// Some other Logic
createWindow(URL);
}