fix(linux): align wrapper wm class with desktop entry

This commit is contained in:
Johannes Millan 2026-05-09 16:11:30 +02:00
parent 7b34820b74
commit 90abae0c3b
2 changed files with 21 additions and 11 deletions

View file

@ -13,10 +13,10 @@
# Same mechanism used by Signal Desktop and Mattermost Desktop snaps
# (snapcrafters/signal-desktop, snapcrafters/mattermost-desktop).
#
# Non-Snap launches (AppImage, .deb, .rpm) hit the passthrough branch so
# behavior for those targets is unchanged. The SNAP_NAME gate also protects
# .deb/.rpm installs invoked via xdg-open from *another* snap (where $SNAP
# leaks into the child env).
# All Linux launches pass through this wrapper so the app can set a stable
# WM_CLASS for desktop-file matching. Only our Snap on Wayland receives the
# extra ozone flag. The SNAP_NAME gate protects .deb/.rpm installs invoked via
# xdg-open from *another* snap (where $SNAP leaks into the child env).
#
# See docs/research/snap-wayland-gpu-fix-research.md §18.
@ -33,17 +33,26 @@ else
BIN_DIR=$(dirname "$SELF")
fi
BIN="$BIN_DIR/superproductivity-bin"
# Must match linux.desktop.entry.StartupWMClass in electron-builder.yaml.
APP_CLASS="superproductivity"
# If the user already supplied --ozone-platform on argv, don't override.
# Stop scanning at -- so positional args aren't misread as flags.
# If the user already supplied --ozone-platform or --class on argv, don't
# override. Stop scanning at -- so positional args aren't misread as flags.
HAS_OZONE_PLATFORM=
HAS_APP_CLASS=
for arg in "$@"; do
case "$arg" in
--) break ;;
--ozone-platform=* | --ozone-platform) exec "$BIN" "$@" ;;
--ozone-platform=* | --ozone-platform) HAS_OZONE_PLATFORM=1 ;;
--class=* | --class) HAS_APP_CLASS=1 ;;
esac
done
if [ -n "$IS_OUR_SNAP" ] && { [ "$XDG_SESSION_TYPE" = "wayland" ] || [ -n "$WAYLAND_DISPLAY" ]; }; then
if [ -z "$HAS_APP_CLASS" ]; then
set -- "--class=$APP_CLASS" "$@"
fi
if [ -n "$IS_OUR_SNAP" ] && [ -z "$HAS_OZONE_PLATFORM" ] && { [ "$XDG_SESSION_TYPE" = "wayland" ] || [ -n "$WAYLAND_DISPLAY" ]; }; then
exec "$BIN" --ozone-platform=x11 "$@"
fi

View file

@ -2,9 +2,10 @@
//
// Renames the main Electron binary to `superproductivity-bin` and installs
// a shell wrapper at the original name. The wrapper forces
// --ozone-platform=x11 when running in our Snap sandbox on a Wayland
// session; non-Snap launches (AppImage, .deb, .rpm) and X11 sessions hit
// a no-op passthrough, so behavior for those targets is unchanged.
// --class=superproductivity for stable desktop-file matching and forces
// --ozone-platform=x11 when running in our Snap sandbox on a Wayland session.
// Non-Snap launches (AppImage, .deb, .rpm) and X11 sessions only receive the
// stable class flag.
//
// Context: field reports on issue #7270 (v18.2.4/v18.2.5) show that
// app.commandLine.appendSwitch('ozone-platform','x11') from inside the