nw.js icon indicating copy to clipboard operation
nw.js copied to clipboard

Custom icon in taskbar not showing with 0.73.0 - grey default icon only

Open vankasteelj opened this issue 3 years ago • 42 comments

The custom icon in the windows 11's taskbar is a grey default icon, with 0.73.0-sdk (or 'normal' non-sdk). It works flawlessly with 0.72.0 (and previous).

The odd thing with 0.73.0 is that the icon in the top-left corner (favico equivalent?) is there. The icon also is present in Task Manager (for the binary and all sub-processes spawned by nwjs too). And the icon also is fine with the Tray. But not on the main taskbar.

FYI: Disabling/enabling nw2 doesnt change the icon issue.

Attached: a printscreen of the nwjs icon (right) and the devtools icon (left). They used to both be my custom icon. WId9322LtC

  • Operating System: Windows 11 x64
  • NW.js Version: 0.73.0 (sdk/normal)
  • Code snippet: In package.json :
  "window": {
    "width": 1024,
    "height": 654,
    "title": "My App",
    "icon": "foo/bar.png",
    "min_width": 885,
    "min_height": 518,
    "show": false
  },

in the js files after some background checks for the app to prepare to strat:

require('nw.gui').Window.get().show(true)

vankasteelj avatar Mar 04 '23 15:03 vankasteelj

0.74 the same bug.

Sunvas avatar Mar 14 '23 00:03 Sunvas

Hi! I'd like to work on this issue

EduardoMtz1 avatar Mar 15 '23 02:03 EduardoMtz1

I can confirm this happens in both Windows 10 and Windows 11 with 0.73.0 and 0.74.0 (both "normal" and SDK builds).

sysrage avatar Mar 26 '23 01:03 sysrage

This issue does not occur in Linux (tried Ubuntu 22.04). It does seem to fail in macOS, but I might be doing something wrong there.

@EduardoMtz1 if you have a PR, please submit one.

@rogerwang please look into this for the next build.

sysrage avatar Mar 26 '23 14:03 sysrage

has anyone had a look at the diff for 0.73.0 and 0.72.0 to see what changed?

zkrige avatar Mar 29 '23 07:03 zkrige

0.75 the same bug. Seems nobody cares... ☹️

Sunvas avatar Apr 05 '23 19:04 Sunvas

@rogerwang please provide an update. This prevents us from updating NW.js in our applications.

sysrage avatar Apr 05 '23 21:04 sysrage

I confirm it's a regression since 0.73 (included)

bschmitlin avatar Apr 07 '23 09:04 bschmitlin

I started digging into this and I noticed that the .ico file that you see is located here: %UserProfile%\AppData\Local\<app-name>\User Data\Default\Web Applications\_nwjs_<jibberish>\<app-name>.ico

You can find the Windows .lnk file that points to this icon by:

  1. Right-click the taskbar icon
  2. On the pop-up menu, right-click on the name of the application
  3. Select Properties
  4. You'll see in the Shortcut file's (.lnk file) properties window, the .lnk file is located in %UserProfile%\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\ImplicitAppShortcuts\<some hex id>\<app-name>.lnk
  5. If you navigate to the Shortut tab, and click the Change Icon button you'll see the above-mentioned .ico file.

I'm guessing it has something to do with which Chromium version we're using?

I found some other interesting things in the Chromium source code, talking about these ImplicitAppShortcuts here: https://chromium.googlesource.com/chromium/src/+/main/docs/windows_shortcut_and_taskbar_handling.md

UPDATE: I dug through the Chromium source, and it looks like Chromium manages its own icon and "Relaunch details" See Chromium source here

The problem is GetIconFilePath() tries to find an icon by looking at the icons property in the chrome extension's manifest. If there is nothing there, then Chromium will use the default icon. The nw.js code supposedly populates the manifest by copying the icon path from the package.json's, but for some reason, in v0.73.0 and above, it seems this property doesn't end up in the nw.js-constructed manifest. I found that if force it by putting this in package.json, then Chromium will copy the icon to the AppData path as expected:

"icons": {
  "256": "path/to/icon.png"
}

nhogle avatar Apr 25 '23 19:04 nhogle

0.75.1 the same bug. 🤬

Sunvas avatar Apr 27 '23 19:04 Sunvas

@nhogle your proposed workaround doesnt work for me on 0.75.1 anyway, but thanks for looking into it, maybe someone will be able to patch the issue

vankasteelj avatar Apr 28 '23 19:04 vankasteelj

It's obviously not ideal and hopefully the issue can be addressed soon, but the workaround does work for me.

old

  "window": {
    "icon": "./build/my-icon.png"
  },

new

  "window": {
    "icon": "./build/my-icon.png"
  },
  "icons": {
    "256": "./build/my-icon.png"
  },

sysrage avatar Apr 29 '23 02:04 sysrage

Thanks! That does work*, I think I was using a .ico, not a .png.

* it works with nwjs window, not the devtool window, but I believe that's actually a good thing to have a nwjs icon for devtool and a custom icon for the app itself.

vankasteelj avatar Apr 29 '23 08:04 vankasteelj

thanks @sysrage - this works for me as well

zkrige avatar May 04 '23 07:05 zkrige

@rogerwang : I believe I have a fix for this issue: in nw::LoadNWAppAsExtensionHook(), the call to:

manifest->FindString("window.icon");

should actually be:

manifest->FindStringByDottedPath("window.icon");

I confirmed this by actually getting the source to compile on Windows (no easy feat!), and checking that we are getting an empty icon_path, but if we use FindStringByDottedPath, then we get the expected value from the manifest, and NW.js will tell Chromium what to do with the icon.

https://github.com/nwjs/nw.js/blob/25f89d17a8886776e3de62ae2f4a931ed13bf2de/src/browser/nw_extensions_browser_hooks.cc#L289

Would you like me to create a pull request with the changes?

nhogle avatar May 07 '23 10:05 nhogle

@nhogle do it :) Best case scenario it's merged and it's 1-click for rogerwang, worse case you've put some effort into helping others

vankasteelj avatar May 07 '23 18:05 vankasteelj

Another workaround that would replicate the full behavior (Set icon on both DevTools and the main window):

in package.json:

"window": {
    "icon": "./build/my-icon.png"
    "<other>": "<window-settings>"
    "<...>": "<...>"
},
"window.icon": {
    "icon": "./build/my-icon.png"
},

The bug is caused by NW.js using the wrong API call to look up the window.icon property path in the Manifest.

nhogle avatar May 09 '23 16:05 nhogle

0.76 the same bug.

Sunvas avatar May 09 '23 21:05 Sunvas

I have a pull-request open that should fix this issue. @rogerwang : Do you think you'll be merging my pull request to fix this bug before the next release? Thanks!

nhogle avatar May 17 '23 18:05 nhogle

0.77 the same bug. 🤬

Sunvas avatar Jun 05 '23 23:06 Sunvas