【问题标题】:'Second-instance' fires instead of 'open-url' in electron on macMac上电子中的“第二个实例”而不是“open-url”触发
【发布时间】: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.

【问题讨论】:

标签: macos electron


【解决方案1】:
  • 您应该在 info.plist 中将 LSMultipleInstancesProhibited 设置为 true。
  • 如果您使用的是 electron builder,您可以在 mac.extendInfo 设置 'LSMultipleInstancesProhibited: true' 例如
mac: {
  ...
  extendInfo: {
    LSMultipleInstancesProhibited: true,
  }
}

【讨论】:

  • 这个去哪儿了?在package.json?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-06
  • 2022-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多