Repository navigation
fix: set XDG app ID and WM_CLASS based on normalized app name - #51424
Conversation
|
Release Notes Persisted
|
|
I have automatically backported this PR to "42-x-y", please check out #51479 |
|
I have automatically backported this PR to "41-x-y", please check out #51480 |
Electron 41.6.1 (backport of electron/electron#51424) changed the X11 WM_CLASS path in native_window_views.cc to derive from the XDG App ID (set via app.setDesktopName) rather than Browser::Get()->GetName() (set via app.setName). The X11 --class path that previously worked happened to work because app.setName fed WM_CLASS directly; that relationship is gone in 41.6.1+. The Wayland app_id path has always read from the XDG App ID, which is why --class was never honoured on Wayland regardless of Electron version. Calling app.setDesktopName(config.class + '.desktop') alongside the existing app.setName(config.class) fixes both platforms with a single line. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
|
@mitchchn I am deep into the rabbit hole. Have a question for you, Per documentation comment in electron/lib/browser/desktop-name.ts Lines 8 to 9 in 1652d8e Am I correct to assume the "desktopName" set in the package.json should also be lower-case? To avoid potential issues with different linux-distro-opinions on desktop files and build-tool quirks? Or is that specifically a sanitization only needed if you're not setting "desktopName" in the package.json already? Based on spec upper-case characters are allowed. Am confused if lower-casing your desktopName helps compatibility issues or is something done for edge-cases specific to deriving a default desktop name. |
Electron now derives a window's Wayland app ID and X11 WM_CLASS from the product name, lowercased: "losslesscut" (electron/electron#49988, electron/electron#51424). Without desktopName, electron-builder still writes StartupWMClass=LosslessCut into the AppImage's desktop entry, and warns about it in every Linux build. When the launcher is installed under another file name, as AppImageLauncher does, GNOME then can't link the running window to it, and the dock shows a generic icon. Setting desktopName to the name Electron already defaults to makes electron-builder write StartupWMClass=losslesscut, the value the Flathub desktop file already uses. The app's own app ID and WM_CLASS don't change. Changelog: Linux: docks show LosslessCut's own icon for the AppImage when its launcher is installed under another name (e.g. by AppImageLauncher) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Description of Change
Fixes #51375.
This PR is an improvement to the logic in #49988, which set a default XDG App ID based on the app's executable path if a
desktopNameis not provided by the developer.The exec name is usually good for compatibility but it has an important edge case: it cannot distinguish apps which do not rename their
electronbinary. This is a common practice for packages on Arch Linux which use "shared" copies of a single version of Electron as dependencies.My solution is to restore the original logic to base the ID on productName/app.name, but to normalize the value so that it conforms to the FreeDesktop spec and so that it is likely to match the name of the .desktop file which would be created by packaging tools such as Forge/Fiddle. (Unfortunately there is no way to be 100% sure, since this is a packaging concern -- for best results, developers should set
desktopNamein package.json and not rely on a generated default value.) If it is not possible for Electron to derive a suitable name, it falls back to the executable name as in #49988.In practice, most apps will have the same XDG app ID as in #49988, either because the normalized slug has the same value as the binary name, or because the developer is already setting
desktopNameproperly.String normalization can be messy, so I've added a table test for the kinds of values I've seen in Electron app names, as well as some names that cannot be normalized. The test did to not fit into any of the existing spec files because it is unit testing a non-public API, similar to the
parse-features-stringspec.Finally, I made a change to set the same value for XDG app ID and WM_CLASS, which is a best practice to support both Wayland and X11. This fully solves #48391 and is a pre-req for #45866.
Checklist
npm testpassesRelease Notes
Notes: Improved the way Electron determines the default XDG App ID and WM_CLASS on Linux for better platform compatibility if
desktopNameis not provided inpackage.json.