#51424: fix: set XDG app ID and WM_CLASS based on normalized app name
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
- I have built and tested this change
- I have filled out the PR description
- I have reviewed and verified the changes
-
npm testpasses - tests are changed or added
- relevant API documentation, tutorials, and examples are updated and follow the documentation style guide
- PR release notes describe the change in a way relevant to app developers, and are capitalized, punctuated, and past tense.
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.
Backports
Semver Impact
Semantic Versioning helps users understand the impact of updates:
- Major (X.y.z): Breaking changes that may require code modifications
- Minor (x.Y.z): New features that maintain backward compatibility
- Patch (x.y.Z): Bug fixes that don't change the API
- None: Changes that don't affect using facing parts of Electron