【发布时间】:2020-01-04 02:27:50
【问题描述】:
我们有一个电子应用程序,我们正在设置它从协议链接启动,遵循此处描述的结构:https://github.com/oikonomopo/electron-deep-linking-mac-win(来自Open app and pass parameters with deep linking using Electron (macOS))
安装应用程序后,我们可以从 finder/launchpad 打开应用程序,也可以使用 myapp://someparams 从浏览器调用应用程序。
如果我在应用程序关闭时调用myapp://someparams,应用程序将打开并且主进程按预期为mac 触发open-url 事件,我可以从url 中获取参数。如果应用最初是通过此方法打开的,则重新调用 myapp://someparams 会继续聚焦应用并按预期触发 open-url。
但是,如果应用程序最初是从查找器、启动板或命令行打开的,则调用 myapp://someparams 会导致触发 second-instance 事件,而我无法找到获取 URL 的方法用于调用应用程序。 Windows 按预期工作,因为second-instance 事件的第二个参数包含协议作为参数,但 mac 并非如此。
所以问题是 - 有没有办法从 mac 上的second-instance 事件中获取协议/url?还是有其他方法可以解决这个问题?
我确实从文档中看到了这个 sn-p:https://electronjs.org/docs/api/app#apprequestsingleinstancelock
On macOS, the system enforces single instance automatically when users try to open a second instance of your app in Finder, and the open-file and open-url events will be emitted for that. However when users start your app in command line, the system's single instance mechanism will be bypassed, and you have to use this method to ensure single instance.
【问题讨论】:
-
你能解决这个问题吗?我遇到了完全相同的问题
-
我不是。我最终在电子回购中提出了一个问题(github.com/electron/electron/issues/20088),但我从未收到回复。