apache / cordova-electron

Apache Cordova Electron
Apache License 2.0
125 stars 58 forks source link

Windows icons not set #97

Open buu700 opened 5 years ago

buu700 commented 5 years ago

Bug Report

Problem

What is expected to happen?

The appx (Windows Store) package should have my app icon set as its icon.

If what's below isn't the correct way to configure this for Electron, the correct solution should ideally be documented.

What does actually happen?

My configuration below and icons are ignored; the default Electron icons are used instead.

<icon src="res/icon/windows/StoreLogo.png" target="StoreLogo" />
<icon src="res/icon/windows/SmallLogo.png" target="Square30x30Logo" />
<icon src="res/icon/windows/Square44x44Logo.png" target="Square44x44Logo" />
<icon src="res/icon/windows/Square70x70Logo.png" target="Square70x70Logo" />
<icon src="res/icon/windows/Square71x71Logo.png" target="Square71x71Logo" />
<icon src="res/icon/windows/Square150x150Logo.png" target="Square150x150Logo" />
<icon src="res/icon/windows/Square310x310Logo.png" target="Square310x310Logo" />
<icon src="res/icon/windows/Wide310x150Logo.png" target="Wide310x150Logo" />

Information

You can unzip the appx file and see that only the default Electron icons appear under assets.

Command or Code

cordova build electron

Environment, Platform, Device

macOS 10.14.6

Version information

Cordova 9.0.0

Checklist

buu700 commented 5 years ago

Until this is fixed, as a workaround, you can copy those icons into platforms/electron/build-res/appx/.

pjoriginal commented 4 years ago

@buu700 When I copy those icons to the folder appx, I get the following error

The path (/p) parameter is: "my-project-location\platforms\electron\build\app.appx"
The mapping file (/f) parameter is: "my-project-location\platforms\electron\build\__appx-x64\mapping.txt"
Reading mapping file "my-project-location\platforms\electron\build\__appx-x64\mapping.txt"
MakeAppx : error: You can't add both "my-project-location\platforms\electron\build-res\appx\Square44X44Logo.png" and "C:\Users\{user}\AppData\Local\electron-builder\Cache\winCodeSign\winCodeSign-2.4.0\appxAssets\SampleAppx.44x44.png" to the output file as "assets\Square44x44Logo.png".

Am I missing something?

Jahrenski commented 3 years ago

To fix this problem I use this custom hook :

module.exports = function(context) {

  console.log('[HACK] Copy of all electron icons');

  //Prevent this running for other platforms.
  if ( context.opts.platforms.indexOf('electron') < 0 ) {
    return;
  }

  var fs   = require('fs'),
      path = require('path')

  const iconsPath = path.join(context.opts.projectRoot, 'resources/electron/icon/icon.png');
  const destination = path.join(context.opts.projectRoot, 'platforms/electron/build-res/icon.png');

  fs.createReadStream(iconsPath).pipe(fs.createWriteStream(destination));
};

And then call it from your Config.xml file

<platform name="electron">
        <hook src="hooks/copy-icons.js" type="after_prepare" />
        <icon src="resources/electron/icon/icon.png" />
</platform>