electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.7k stars 1.74k forks source link

Cannot reuse icon for different file associations #8404

Open SleepyLeslie opened 3 months ago

SleepyLeslie commented 3 months ago

On macOS, electron-builder fails when multiple file associations use the same icon file. Here is a sample configuration snippet:

    "fileAssociations": [
      {
        "ext": "grist",
        "name": "Grist Document",
        "role": "Editor",
        "icon": "core/static/icons/gristdoc",
        "rank": "Owner"
      },
      {
        "ext": "csv",
        "name": "Comma-Separated Values",
        "role": "Viewer",
        "icon": "core/static/icons/gristdoc",
        "rank": "Alternate"
      }
    ]

The resulting error is:

⨯ EEXIST: file already exists, link '/Users/runner/work/grist-desktop/grist-desktop/core/static/icons/gristdoc.icns' -> '/Users/runner/work/grist-desktop/grist-desktop/dist/mac/Electron.app/Contents/Resources/gristdoc.icns'  failedTask=build stackTrace=Error: EEXIST: file already exists, link '/Users/runner/work/grist-desktop/grist-desktop/core/static/icons/gristdoc.icns' -> '/Users/runner/work/grist-desktop/grist-desktop/dist/mac/Electron.app/Contents/Resources/gristdoc.icns'

This has been mentioned in #3204, opening a separate issue since it was off-topic.

mmaietta commented 2 months ago

Thank you for opening a new issue to keep discussions streamlined 🙂

I took a quick look and it seems the var fileAssociations is used in a LOT of places, but I think this may be the logic you're encountering. https://github.com/electron-userland/electron-builder/blob/d5d9f3f9aaac0385cc943e30a0841669133afde8/packages/app-builder-lib/src/electron/electronMac.ts#L208-L211

If so, this might be an easy fix! (I'm not sure if MacOS allows multiple file associations to use the same icon file, but if it does, we'll find out if you're willing to test a patch-package to hotpatch your current version of electron-builder)

As a workaround for the interim, you could have multiple copies of the icon in your repo so that each different name/icon is copied separately.