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.58k stars 1.73k forks source link

Linux .deb icon requires packing/making for MacOS #6905

Open troywweber7 opened 2 years ago

troywweber7 commented 2 years ago

My electron-builder.config.json looks something like this:

{
  "appId": "com.yourdoamnin.yourapp",
  "directories": {
    "buildResources": "resources"
  },
  "files": [
    "assets/**/*",
    "build/**/*",
    "capacitor.config.*",
    "app/**/*"
  ],
  "linux": {
    "target": ["deb"],
    "category": "Education",
    "icon": "dist/.icon-icns/icon.icns"
  },
  "mac": {
    "target": ["zip"],
    "icon": "assets/appIcon.png"
  },
  "win": {
    "icon": "assets/appIcon.ico"
  }
}

My package.json scripts look like this:

  "scripts": {
    "build": "tsc",
    "electron.start-live": "node ./live-runner.js",
    "electron.start": "npm run build && electron --inspect=5858 ./",
    "electron.pack": "npm run build && electron-builder build -lmw --dir -c ./electron-builder.config.json",
    "electron.make": "npm run build && electron-builder build -l -c ./electron-builder.config.json",
    "postinstall": "electron-builder install-app-deps"
  },

assets/appIcon.png is a valid file.

If I run electron.make, it never generates the .icns file whether I set linux.icon to undefined, "assets/appIcon.png", or "dist/.icon-icns/icon.icns". So when I install the generated .deb file, it is either the blank gear icon or the default electron icon.

However, if I run electon.pack, it will create the .icns file because it builds for mac, then if I set linux.icon to "dist/.icon-icns/icon.icns" and run electron.make again, the installed .deb file will have the correct icon. Why should I have to pack it for mac in order for the linux debian icon to work? This seems like an undesireable workflow.

burgil commented 2 years ago

Well, I think the source of this issue is just confusion, I could be wrong but as far as I'm aware, and I did it before:

1) You can not use a .png as mac icons: image

2) (And don't catch me on this) Electron builder does not generate the icons for you, You have to pre generate them (only once) [just once] - and put them wherever needed, Electron Builder simply use the files you specify in that config, so change it to something like this:

{
  "appId": "com.yourdoamnin.yourapp",
  "directories": {
    "buildResources": "resources"
  },
  "files": [
    "assets/**/*",
    "build/**/*",
    "capacitor.config.*",
    "app/**/*"
  ],
  "linux": {
    "target": ["deb"],
    "category": "Education",
    "icon": "./dist/.icon-icns"
  },
  "mac": {
    "target": ["zip"],
    "icon": "./assets/appIcon.icns"
  },
  "win": {
    "icon": "./assets/appIcon.ico"
  }
}

and make sure all of the above are valid path it looks weird that mac and win is using assets and linux is using dist in my opinion, but again I am no expert just another guy like you

troywweber7 commented 2 years ago

@burgil I just want to make sure I'm understanding you correctly:

You are saying to point mac.icon to ./assets/appIcon.png one time, run electron-builder to let it create the ./dist/.icon-icns/icon.icns at least once, move that icon.icns to ./assets/appIcon.icns, then finally change mac.icon and linux.icon to point to the new ./assets/appIcon.icns?

If so, I'd say I'm still not too stoked by the workflow, but I suppose that may work as a temporary fix. Also, to your point that You cannot use a .png as mac icons, this documentation seems to disagree with you.

Also, the documentation seems to agree that Linux depends on the .icns icon for MacOS.

So I think my question is still relevant and not a misunderstanding, but I'm open to further discussion on that point.

For now I'll just reiterate that if you want a workflow that depends on a single icon source while the rest are generated, it seems that you have to point to appIcon.png. Building for MacOS will automatically generate the icon.icns, which Linux depends on to generate it's icons (unless you specify those icons all manually). However, if you don't build for MacOS, and only for Linux, Linux fails to generate the required icons. So why, when building only for Linux, shouldn't the default be to generate a .icns just as MacOS would, then generate the required Linux icons from that?

Anyway, I have a couple workarounds in the meantime, but they all seem an inferior work flow to having a single icon as the source from which all the remaining icons are generated. Any thoughts or insights from someone with more experience (than @burgil and myself) on how we can be doing this better are very welcome.

burgil commented 2 years ago

You are saying to point mac.icon to ./assets/appIcon.png one time, run electron-builder to let it create the ./dist/.icon-icns/icon.icns at least once, move that icon.icns to ./assets/appIcon.icns, then finally change mac.icon and linux.icon to point to the new ./assets/appIcon.icns?

Yes that is what I meant I guess, I just used an online icon generator lol

Any thoughts or insights from someone with more experience (than @burgil and myself)

Haha I agree, I'm not a contributor just trying to help :)

Building for MacOS will automatically generate the icon.icns

I did not know that, thank you I've learned something new 👍

Also, to your point that You cannot use a .png as mac icons, this documentation seems to disagree with you.

Well I see that just now, I guess that I didn't know they were generating that icons in that case,

I would like to point out that when I made an app for Mac once using xCode it did not let me put a png as the favicon, and I had to generate the .icns manually using a terminal command that was only available in mac os to convert a png to icns, did that years ago

So why, when building only for Linux, shouldn't the default be to generate a .icns just as MacOS would, then generate the required Linux icons from that?

Are you building from Windows, Mac or Linux?

this article talks about cross platform builds and how you can only build from mac to windows but not vice versa I think..

image

https://www.electron.build/multi-platform-build

Free public Electron Build Service is used to build Electron app for Linux on Windows. On macOS/Linux you can build Electron app for Windows locally, except Appx for Windows Store (in the future (feel free to file issue) electron-build-service will support Appx target).

Anywho good luck 😄

troywweber7 commented 2 years ago

@burgil thanks for all the clarification.

I'm building on Linux for other platforms. I'm able to build Linux and Windows executables/installers from Linux using docker. I'm also able to build the --dir unpacked file formats for all of them. I'm hitting a wall at MacOS so I may have to rely on my fellow Mac developers, but I'm going to take a look at the builder service you mentioned from their docs.

burgil commented 2 years ago

Well I researched a lot about that topic actually and I believe the answer is that you can only generate a mac build from mac, or through a build server (that is running mac lol), So I believe the answer is that you can't generate a mac build from linux

but let's keep it open to see what the actual contributors say :)

troywweber7 commented 2 years ago

@burgil yep, that's my conclusion as well.

But just to be super clear for anyone who comes across this issue, while this extra information about building for MacOS is helpful, it is not relevant to my original question.

On Linux you can build the unpacked MacOS files with --dir, which generates the .icns, which the build for Linux can then use to generate its PNG files. But if you want to generate only for Linux, there is no option to leave out the MacOS dir build and generate all the necessary Linux icons automatically from a single PNG.

There are workarounds, but obviously they're not an ideal workflow.