From 90abae0c3b111d1ecdc7cb3e66f2e9685081cb07 Mon Sep 17 00:00:00 2001 From: Johannes Millan Date: Sat, 9 May 2026 16:11:30 +0200 Subject: [PATCH] fix(linux): align wrapper wm class with desktop entry --- build/linux/snap-wrapper.sh | 25 +++++++++++++++++-------- tools/afterPack.js | 7 ++++--- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/build/linux/snap-wrapper.sh b/build/linux/snap-wrapper.sh index 8e843470be..a3195c46fa 100755 --- a/build/linux/snap-wrapper.sh +++ b/build/linux/snap-wrapper.sh @@ -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 diff --git a/tools/afterPack.js b/tools/afterPack.js index c1246ad3a1..d25f92d0b8 100644 --- a/tools/afterPack.js +++ b/tools/afterPack.js @@ -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