Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions electron-builder.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"appId": "com.herotools.openwispr",
"afterPack": "scripts/afterPack.js",
"productName": "OpenWhispr",
"protocols": {
"name": "OpenWhispr Protocol",
Expand Down
7 changes: 3 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
44 changes: 44 additions & 0 deletions scripts/afterPack.js
Original file line number Diff line number Diff line change
@@ -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 });
};
Loading