首页 > 解决方案 > 通过 electron-builder 嵌入 Finder Sync 扩展的问题

问题描述

我有一个 Electron 应用程序,它通过 Finder Sync 扩展与 OS X Finder 集成。总体而言,该应用程序包含三个部分:

  1. 电子应用
  2. 迅捷应用
  3. FinderSync 扩展

Electron 应用程序是主要的入口点。在启动时,它会创建一个运行 Swift 应用程序的子进程。Swift 应用程序中嵌入了 FinderSync 扩展。Swift 应用程序和 FinderSync 扩展通过 ICP 进行通信,以便 FinderSync 扩展可以获取徽章和上下文菜单的正确信息。

我用电子制造商建造一切。它最终得到如下结构:

 - MyElectronApp.app
   - Contents
     - PlugIn
       -  MyExtension.appex
     - MacOS
       -  MySwiftApp.app
         - Contents
           - PlugIn
             - MyExtension.appdex
           - (All the other app contents)

当我安装应用程序并运行它时,我在 Console.app 中看到了这个

rejecting; Ignoring mis-configured plugin at [/Applications/MyElectronApp.app/Contents/MacOS/mySwiftApp.app/Contents/PlugIns/myFinderExtension.appex]: plug-ins must be sandboxed

该插件被标记为沙盒,这是插件的内部实例。我不明白这对于上层。

当我启动应用程序时,我可以看到我的插件正在 Finder 扩展首选项窗格中运行。如果我在 Preference Pane 中切换扩展程序,我可以在 Console.app 中看到扩展程序和 Swift 应用程序正在相互通信。但我在 Finder 中看不到我的上下文菜单或徽章。

我确实在我的 Swift 应用程序和 Finder 扩展的日志中看到了这一点:

LSExceptions shared instance invalidated for timeout.

该扩展是沙盒的,而 Swift 应用程序不是。我花了一段时间才让这些权利“正确”。我在 Electron 应用程序中列出了两次插件。我发现如果我不把它放在顶层PlugIn目录中,那么它就不会注册到操作系统。当我查询 pluginkit 时,我看到扩展的第一个实例正在运行。扩展程序和 Swift 应用程序具有相同的应用程序组,因此它们可以进行 IPC。

在这一点上,我不确定我能做什么。该插件似乎是随 Electron 应用程序启动的,而不是当我从 Electron 内启动 Swift 应用程序时启动的。

为了达到这一点,我解决了代码签名问题和沙盒问题。我没有使用配置文件。我确实有用于签名的 Apple 开发人员证书。

任何帮助将不胜感激。如果有一篇文章他们发布了带有电子生成器的 Finder 扩展,那也很棒。

以下是其他一些文件:

电子制造商权利文件:

...
<dict>
    <key>com.apple.security.cs.allow-jit</key>
    <true/>
    <key>com.apple.security.cs.disable-library-validation</key>
    <true/>
    <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
    <true/>
    <key>com.apple.security.automation.apple-events</key>
    <true/>
    <key>com.apple.security.files.user-selected.read-only</key>
    <true/>
    <key>com.apple.security.app-sandbox</key>
    <false/>
</dict>
...

package.json 中的电子构建设置

"build": {
    "appId": "com.myapp",
    "productName": "My App",
    "copyright": "Copyright © 2020 ${author}",
    "files": [
      "./index.js",
      "./modules/**/*",
      "./iconSmallTemplate.ico"
    ],
    "extraResources": [
      {
        "from": "./resources/",
        "to": "./",
        "filter": [
          "**/*"
        ]
      }
    ],
    "mac": {
      "appId": "com.myapp.mac",
      "category": "public.app-category.productivity",
      "type": "development",
      "identity": "Apple Development: ME (#####)",
      "extraFiles": [
        {
          "from": "mySwiftApp.app",
          "to": "MacOS/mySwiftApp.app"
        },
        {
          "from": "myFinderExtension.appex",
          "to": "PlugIns/myFinderExtension.appex"
        }
      ]
    }
  }

标签: swiftmacoselectronelectron-builderfindersync

解决方案


推荐阅读