Electron-Linux-如何从web浏览器设置深度链接?

Electron-Linux-如何从web浏览器设置深度链接?,electron,electron-builder,Electron,Electron Builder,我想要实现什么 在浏览器中输入这样的URL方案myApp://someData,应该会打开我的应用程序并传递URL(在Linux中)。 我发现的所有示例都适用于Windows/Mac操作系统,在Linux中不起作用 我使用electron builder捆绑我的electron应用程序,以便配置一个方案,我在我的package.json中添加了以下内容 "protocols": [ { "name": "m

我想要实现什么

在浏览器中输入这样的URL方案
myApp://someData
,应该会打开我的应用程序并传递URL(在Linux中)。 我发现的所有示例都适用于Windows/Mac操作系统,在Linux中不起作用

我使用electron builder捆绑我的electron应用程序,以便配置一个方案,我在我的package.json中添加了以下内容

"protocols": [
        {
            "name": "myApp",
            "role": "Viewer",
            "schemes": [
                "myApp"
            ]
        }
    ]
让我们假设这是可行的-我不知道如何测试它

如何在我的电子应用程序中拦截
myApp://someData
URL? 我试过:
app.on('open-url',…。
但这仅适用于Mac OS

我尝试了
protocol.registerFileProtocol('myApp',(请求,回调)=>{…})
这不太管用


这在Linux机器上可能吗?如果可能,怎么可能?

你需要在应用程序的“第二个实例”事件中处理这个问题-

const gotTheLock = app.requestSingleInstanceLock();

app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required');

if (!gotTheLock) {
    console.warn("Two app instances running");
    app.quit();
} else {
    app.on("second-instance", (event, argv, workingDirectory) => {
        let url;
        // Protocol handler for win and linux
        // argv: An array of the second instance’s (command line / deep linked) arguments
        if (process.platform == 'win32' || process.platform === "linux") {
            // Keep only command line / deep linked arguments
            url = argv.slice(1);
            console.info("Args = " + url);
        }
    })
}