diff --git a/electron-builder.json b/electron-builder.json index e743b9309..204767707 100644 --- a/electron-builder.json +++ b/electron-builder.json @@ -1,5 +1,6 @@ { "appId": "com.herotools.openwispr", + "afterPack": "scripts/afterPack.js", "productName": "OpenWhispr", "protocols": { "name": "OpenWhispr Protocol", diff --git a/main.js b/main.js index e7a5f2fd1..02d7c8a04 100644 --- a/main.js +++ b/main.js @@ -75,10 +75,9 @@ if (process.platform === "win32") { app.commandLine.appendSwitch("disable-gpu-compositing"); } -// Enable native Wayland support: Ozone platform for native rendering. -// KDE uses XWayland for reliable clipboard access, with KGlobalAccel D-Bus -// for global shortcuts. GNOME and Hyprland run native Wayland with their -// own D-Bus shortcut managers. +// Wayland: packaged builds use the wrapper script (scripts/afterPack.js) to +// force --ozone-platform=x11 before Electron starts. appendSwitch below is a +// best-effort fallback for unpackaged dev mode (may not take effect on E39+). if (process.platform === "linux" && process.env.XDG_SESSION_TYPE === "wayland") { const desktop = (process.env.XDG_CURRENT_DESKTOP || "").toLowerCase(); if (desktop.includes("kde")) { diff --git a/scripts/afterPack.js b/scripts/afterPack.js new file mode 100644 index 000000000..3f3cd882f --- /dev/null +++ b/scripts/afterPack.js @@ -0,0 +1,44 @@ +// electron-builder afterPack hook +// Wraps the Linux Electron binary in a shell script that: +// 1. Forces XWayland on Wayland sessions (overlay positioning requires X11) +// 2. Reads user flags from ~/.config/open-whispr-flags.conf + +const fs = require("fs"); +const path = require("path"); + +exports.default = async function (context) { + if (context.electronPlatformName !== "linux") return; + + const appDir = context.appOutDir; + const binaryName = context.packager.executableName; + const binaryPath = path.join(appDir, binaryName); + const realBinaryPath = path.join(appDir, binaryName + "-app"); + + fs.renameSync(binaryPath, realBinaryPath); + + const wrapper = `#!/bin/bash +# OpenWhispr launcher +# User flags: ~/.config/${binaryName}-flags.conf (one per line, # = comment) + +HERE="\${BASH_SOURCE%/*}" +FLAGS=() + +# Wayland: forces XWayland (overlay positioning requires X11) +if [ "$XDG_SESSION_TYPE" = "wayland" ]; then + FLAGS+=(--ozone-platform=x11) +fi + +# User flags +FLAGS_FILE="\${XDG_CONFIG_HOME:-$HOME/.config}/${binaryName}-flags.conf" +if [ -f "$FLAGS_FILE" ]; then + while IFS= read -r line || [[ -n "$line" ]]; do + [[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue + FLAGS+=("$line") + done < "$FLAGS_FILE" +fi + +exec -a "$0" "$HERE/${binaryName}-app" "\${FLAGS[@]}" "$@" +`; + + fs.writeFileSync(binaryPath, wrapper, { mode: 0o755 }); +};