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

Linux icon generation from icon.icns for non deb/similar packaging #8309

Open Covkie opened 2 months ago

Covkie commented 2 months ago

When building to unpacked no icons are generated from the specified icon.icns in the package.json resulting in missing or wrong icons used when building locally see vesktop/-git on the AUR. (unpacked is used in the -git package as it is much faster than compressing & installing) This also causes distributed tars of the application by the developer to be missing icons in the tar as instead they are generated to .icon-set externally which defeats the point of the tar.

Solution: move the generation of the .icon-set stage to the unpacked generation behind an argument for cases like the vesktop-git package and enable it by default for tar generation. See vencord/vesktop#691 for why generating the icons from the .icns file locally with icns2png isn't an adequate solution.

mmaietta commented 1 month ago

I took a quick look at the code and it looks like the linux packages execute https://github.com/develar/app-builder with a path to the icon-set. The icon-set itself is also generated by app-builder.

Out of curiosity, where would the icon-set go in the unpacked step? I'm not familiar with vesktop/-git or AUR.

Covkie commented 1 month ago

Ideally the icon-set would just be in the unpacked folder and packagers can deal with it from there.

mmaietta commented 1 month ago

If I'm understanding correctly, I think the afterPack could work nicely for you in this case. That or another one of the available hooks. This copies what the linux target is doing under-the-hood when calculating the desktop entries.

    async afterPack(context: AfterPackContext) {
        const packager = context.packager
        const { platformSpecificBuildOptions, config } = packager

        const sources = [platformSpecificBuildOptions.icon, config.mac?.icon ?? config.icon].filter(str => !!str) as string[]

        // If no explicit sources are defined, fallback to buildResources directory, then default framework icon
        let fallbackSources = [packager.getDefaultFrameworkIcon()!]
        const buildResources = config.directories?.buildResources
        if (buildResources && existsSync(join(buildResources, "icons"))) {
          fallbackSources = [buildResources, ...fallbackSources]
        }

        const result = await packager.resolveIcon(sources, fallbackSources, "set")

        // do something with result. output is in config.directories.output dir
    },
mmaietta commented 1 month ago

Let me know if the above ☝️ works for you and I can pull out a common helper function for fetching icons from the packager for all platforms

Covkie commented 1 month ago

I've finally gotten around to attempting your suggestion but I do not know what you want me to do with the provided snippet

mmaietta commented 1 month ago

It's an afterPack hook. You can either add it to an electron-builder js config file directly, or save it to a js script that you then set the path to from project root. https://www.electron.build/configuration/configuration#afterpack

Covkie commented 1 month ago

alr its working and generating the .icon-set