Change icon of running firefox profile

后端 未结 3 1922
情话喂你
情话喂你 2020-12-19 04:40

I\'m using Win7 but looking for a cross os solution, but this isnt even working in my Win7. I\'m trying to change the icon of just the current profile. So what i did was:

3条回答
  •  萌比男神i
    2020-12-19 05:08

    Well, there are some ways that spring to mind, but all with their own issues:

    1. Using Window Icons provided by an add-on you install into the profile (the docs talk about bundles, but add-on can also use this technique). The add-on must be em:unpack and have the icon(s) in chrome/default/icons exactly. It is possible that the Firefox in question has an own set of icons bundled in the $appdir/chrome/default/icons, in particular on *nix and since they are checked first, they will be used instead of the add-on provided add-ons. So while this approach works for custom add-on windows, it might not for built-in ones.
    2. Copy and patch Firefox itself, aka. the sledgehammer approach. Different for each platform (e.g. under Windows you'd have to swap out the icon resource of the firefox.exe).
    3. Create a tool that will switch out the icons of a running window. There is no code to do so in Firefox that would be accessible from javascript, so you need to go binary and platform-specific, e.g. WM_SETICON on Windows.

    Edit 1: Actually, thinking more about it, I'd install an add-on with some platform-specific js-ctypes code that would then switch out the icons, e.g. the already mentioned WM_SETICON on Windows.

    Usually you'll need a window handle for the platform APIs, which Firefox refuses to provide to JS. But as a workaround for that:

    1. Store the window title.
    2. Set the window title to a new uuid.
    3. Call a platform API to find the new uuid titled window handle (FindWindow on Windows). mintrayr uses this scheme for Windows/Gnome(GTK/GDK), also not in js-ctypes.
    4. Restore the window title.
    5. Load/transform the icon file to something the platform supports (HICON on windows). I once had a patch somewhere on bugzilla that enabled loading of arbitrary images as window icons FWIW, but let it slide. Should be still somewhere and could give pointers.
    6. Switch the icon using the obtained handle. E.g. Sending two WM_SETICON for small/big icon on Windows.

    Edit 2 Turns out nsIBaseWindow exposes a nativeHandle these days, as I learned from your other question. so the window-title–hack isn't needed any longer. However, nativeHandle might be an 64-bit pointer, which isn't really supported in JS land without some trickery... Better not parseInt it... Also js numbers are floats.

    ctypes.voidptr_t(ctypes.UInt64(nativeHandle)) should work, though.

提交回复
热议问题