Skip to content

fix: set XDG app ID and WM_CLASS based on normalized app name - #51424

Merged
ckerr merged 1 commit into
electron:mainfrom
mitchchn:mitch/xdg-app-id
May 4, 2026
Merged

ckerr merged 1 commit into
electron:mainfrom
mitchchn:mitch/xdg-app-id

Conversation

@mitchchn

@mitchchn mitchchn commented Apr 30, 2026 •

Copy link
Copy Markdown
Member

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 desktopName is 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 electron binary. 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 desktopName in 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 desktopName properly.

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-string spec.

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

Release Notes

Notes: Improved the way Electron determines the default XDG App ID and WM_CLASS on Linux for better platform compatibility if desktopName is not provided in package.json.

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Apr 30, 2026
@mitchchn mitchchn mentioned this pull request Apr 30, 2026
3 tasks done
@ckerr
ckerr self-requested a review April 30, 2026 23:41
@ckerr ckerr added platform/linux semver/patch backwards-compatible bug fixes labels Apr 30, 2026
@nikwen nikwen added target/41-x-y PR should also be added to the "41-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. labels Apr 30, 2026
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label May 1, 2026
@ckerr
ckerr merged commit 95722ef into electron:main May 4, 2026
95 checks passed
@release-clerk

release-clerk Bot commented May 4, 2026

Copy link
Copy Markdown

Release Notes Persisted

Improved the way Electron determines the default XDG App ID and WM_CLASS on Linux for better platform compatibility if desktopName is not provided in package.json.

@trop

trop Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "42-x-y", please check out #51479

@trop

trop Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "41-x-y", please check out #51480

IsmaelMartinez added a commit to IsmaelMartinez/teams-for-linux that referenced this pull request May 26, 2026
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]>
@Bug-Reaper

Bug-Reaper commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

@mitchchn I am deep into the rabbit hole. Have a question for you,

Per documentation comment in defaultDesktopName:

// The name is lowercased and hyphenated so it is more likely to match the .desktop file created
// when the app is packaged, which is important for desktop integration and matching icons on Wayland.

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.

mifi pushed a commit to mifi/lossless-cut that referenced this pull request Oct 23, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged/41-x-y PR was merged to the "41-x-y" branch. merged/42-x-y PR was merged to the "42-x-y" branch. platform/linux semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty wm_class (Regression)

4 participants