0

我正在尝试让我的电子应用程序的文件图标在 mac 上正常工作。

我的 package.json 有:

"fileAssociations": {
  "ext": [ "x" ],
  "name": "X",
  "description": "An x file",
  "icon": "xFile.icns",
  "role": "Editor",
  "isPackage": false
},

而且我在 package.json 中也有:

"extend-info": "Info.plist"

其中包含:

...<plist version="1.0">
<dict>
  <key>CFBundleDocumentTypes</key>
  <array>
    <dict>
      <key>CFBundleTypeExtensions</key>
      <array>
        <string>sql</string>
      </array>
      <key>CFBundleTypeIconFile</key>
      <string>xFile.icns</string>
      <key>CFBundleTypeName</key>
      <string>X File</string>
      <key>CFBundleTypeOSTypes</key>
      <array>
        <string>X</string>
      </array>
      <key>CFBundleTypeRole</key>
      <string>Editor</string>
      <key>NSDocumentClass</key>
      <string>SPDocumentController</string>
    </dict>
  </array>
  <key>CFBundleURLTypes</key>
  <array>
  </array>
</dict>
</plist>

打包并将其移动到我的 Applications 文件夹后,我检查了应用程序的内容,并且 Info.plist 没有使用上述信息进行扩展。

双击启动 .x 文件虽然有效,但没有图标替换。

谁能确认我的 .icns 文件和 .plist 文件的路径是否正确?它是相对于构建文件夹还是其他东西?

我的文件结构是根据指南:

app folder:
 > package.json, main.js, etc.
 > build
   > icons & Info.plist
4

1 回答 1

1

我自己遇到了这个问题。首先,您在 package.json 中的第一个片段与 Electron Builder而不是Electron Packager 相关。

So if you plan to use electron-packager make sure that your npm run build script uses it and not builder.

Here is how I fixed the icon issue with Electron Packager:

In you config for electron-packager you'll point to the plist file, as well as add an entry to copy the icon file into the resources folder of the app.

In your electron-packager config you need these two entries:

extraResource: "app/icons/document-icon.icns",
extendInfo: "build-files/Info.plist"

Then in your plist you can just use the icon name:

<key>CFBundleTypeIconFile</key>
<string>document-icon.icns</string>

Finally, you might need to relaunch the Finder for it to take effect if you've already associated the file before.

Hope this helps!

于 2018-01-26T00:45:56.823 回答