Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix(linux): force XWayland on KDE/GNOME Wayland, fix hotkey startup race
Gabriel Steindc4ac9d69fe5
diff --git a/main.js b/main.jsindex edb060f34..b4139870a 100644--- a/main.js+++ b/main.js@@ -1,3 +1,21 @@+// KDE/GNOME Wayland: self-relaunch with --ozone-platform=x11 to force XWayland.+// Chromium picks the display backend before JS runs, so appendSwitch is too late.+if (+ process.platform === "linux" &&+ process.env.XDG_SESSION_TYPE === "wayland" &&+ !process.argv.includes("--ozone-platform=x11")+) {+ const desktop = (process.env.XDG_CURRENT_DESKTOP || "").toLowerCase();+ if (desktop.includes("kde") || /gnome|ubuntu|unity/.test(desktop)) {+ const { spawn } = require("child_process");+ spawn(process.execPath, [...process.argv.slice(1), "--ozone-platform=x11"], {+ stdio: "inherit",+ detached: true,+ }).unref();+ process.exit(0);+ }+}+const {app,globalShortcut,@@ -62,6 +80,13 @@ function configureChannelUserDataPath() {configureChannelUserDataPath();+// Load userData .env (contains DICTATION_KEY, API keys, etc.) early — before+// hotkey registration, which needs DICTATION_KEY before the renderer loads.+require("dotenv").config({+ path: path.join(app.getPath("userData"), ".env"),+ override: false,+});+// Fix transparent window flickering on Linux: --enable-transparent-visuals requires// the compositor to set up an ARGB visual before any windows are created.// --disable-gpu-compositing prevents GPU compositing conflicts with the compositor.@@ -75,17 +100,10 @@ if (process.platform === "win32") {app.commandLine.appendSwitch("disable-gpu-compositing");}-// Wayland backend: KDE and GNOME use XWayland (KDE for clipboard, GNOME-// because Wayland forbids app-initiated window positioning). wlroots-// compositors (Hyprland, Sway) run native. D-Bus shortcuts work either way.+// Wayland window decorations for native Wayland sessions (wlroots compositors).+// KDE/GNOME use XWayland via the self-relaunch guard at the top of this file.if (process.platform === "linux" && process.env.XDG_SESSION_TYPE === "wayland") {- const desktop = (process.env.XDG_CURRENT_DESKTOP || "").toLowerCase();- if (desktop.includes("kde") || /gnome|ubuntu|unity/.test(desktop)) {- app.commandLine.appendSwitch("ozone-platform-hint", "x11");- } else {- app.commandLine.appendSwitch("ozone-platform-hint", "auto");- }- app.commandLine.appendSwitch("enable-features", "UseOzonePlatform,WaylandWindowDecorations");+ app.commandLine.appendSwitch("enable-features", "WaylandWindowDecorations");}// Set desktop filename so Wayland compositors can match windows to the .desktop entry.diff --git a/scripts/run-electron.js b/scripts/run-electron.jsindex 8bb7ae72e..68ec180cd 100644--- a/scripts/run-electron.js+++ b/scripts/run-electron.js@@ -25,8 +25,24 @@ console.log("[run-electron] Electron path:", electronPath);console.log("[run-electron] App dir:", appDir);console.log("[run-electron] Args:", args);-// Spawn electron with the cleaned environment-const child = spawn(electronPath, [appDir, ...args], {+// On KDE/GNOME Wayland, force XWayland so globalShortcut and window positioning work.+// Adding it here avoids the self-relaunch in main.js which kills concurrently in dev mode.+if (+ process.platform === "linux" &&+ process.env.XDG_SESSION_TYPE === "wayland" &&+ !args.includes("--ozone-platform=x11")+) {+ const desktop = (process.env.XDG_CURRENT_DESKTOP || "").toLowerCase();+ if (desktop.includes("kde") || /gnome|ubuntu|unity/.test(desktop)) {+ args.push("--ozone-platform=x11");+ console.log("[run-electron] KDE/GNOME Wayland detected, forcing XWayland");+ }+}++// Chromium flags must come before the app path, app args after.+const chromiumFlags = args.filter((a) => a.startsWith("--ozone-platform="));+const appArgs = args.filter((a) => !a.startsWith("--ozone-platform="));+const child = spawn(electronPath, [...chromiumFlags, appDir, ...appArgs], {stdio: "inherit",env: process.env,cwd: appDir,diff --git a/src/helpers/clipboard.js b/src/helpers/clipboard.jsindex 03b3f8cae..9ccf6028b 100644--- a/src/helpers/clipboard.js+++ b/src/helpers/clipboard.js@@ -57,6 +57,7 @@ const RESTORE_DELAYS = {win32_nircmd: 80,win32_pwsh: 80,linux: 200,+ linux_kde_wayland: 600,};function writeClipboardInRenderer(webContents, text) {@@ -1028,13 +1029,14 @@ class ClipboardManager {const restoreClipboard = () => {if (originalClipboard == null) return;+ const delay = isKde && isWayland ? RESTORE_DELAYS.linux_kde_wayland : RESTORE_DELAYS.linux;setTimeout(() => {if (isWayland) {this._writeClipboardWayland(originalClipboard, webContents);} else {clipboard.writeText(originalClipboard);}- }, RESTORE_DELAYS.linux);+ }, delay);};const terminalClasses = [diff --git a/src/helpers/hotkeyManager.js b/src/helpers/hotkeyManager.jsindex 3409d600d..a2a8119ef 100644--- a/src/helpers/hotkeyManager.js+++ b/src/helpers/hotkeyManager.js@@ -559,7 +559,9 @@ class HotkeyManager {this.mainWindow = mainWindow;this.hotkeyCallback = callback;- if (process.platform === "linux" && GnomeShortcutManager.isWayland()) {+ // On XWayland, skip D-Bus shortcut managers — globalShortcut works via X11.+ const isXWayland = process.argv.includes("--ozone-platform=x11");+ if (process.platform === "linux" && GnomeShortcutManager.isWayland() && !isXWayland) {const gnomeOk = await this.initializeGnomeShortcuts(callback);if (gnomeOk) {@@ -679,9 +681,24 @@ class HotkeyManager {globalShortcut.unregisterAll();}- setTimeout(() => {- this.loadSavedHotkeyOrDefault(mainWindow, callback);- }, HOTKEY_REGISTRATION_DELAY_MS);+ // Register from env var immediately if available, otherwise wait for page load.+ const envHotkey = process.env.DICTATION_KEY || "";+ if (envHotkey) {+ const result = this.setupShortcuts(envHotkey, callback);+ if (result.success) {+ debugLogger.log(`[HotkeyManager] Hotkey "${envHotkey}" registered from env`);+ } else {+ debugLogger.log(`[HotkeyManager] Env hotkey "${envHotkey}" failed, waiting for page`);+ this.loadSavedHotkeyOrDefault(mainWindow, callback);+ }+ } else {+ const loadHotkey = () => this.loadSavedHotkeyOrDefault(mainWindow, callback);+ if (mainWindow.webContents.isLoading()) {+ mainWindow.webContents.once("did-finish-load", loadHotkey);+ } else {+ loadHotkey();+ }+ }this.isInitialized = true;}@@ -693,9 +710,14 @@ class HotkeyManager {// Fall back to localStorage if env var is emptyif (!savedHotkey) {- savedHotkey = await mainWindow.webContents.executeJavaScript(`- localStorage.getItem("dictationKey") || ""- `);+ try {+ savedHotkey = await mainWindow.webContents.executeJavaScript(`+ localStorage.getItem("dictationKey") || ""+ `);+ } catch (jsErr) {+ debugLogger.log(`[HotkeyManager] executeJavaScript failed: ${jsErr.message}`);+ savedHotkey = "";+ }// If we found a hotkey in localStorage but not in env, migrate it to .env fileif (savedHotkey && savedHotkey.trim() !== "") {diff --git a/src/helpers/kdeShortcut.js b/src/helpers/kdeShortcut.jsindex e1d511030..d8f8fb5dc 100644--- a/src/helpers/kdeShortcut.js+++ b/src/helpers/kdeShortcut.js@@ -220,9 +220,10 @@ class KDEShortcutManager {const actionId = [COMPONENT_NAME, "OpenWhispr", slotName, `OpenWhispr ${slotName}`];try {- // Register action then set shortcut+ // Flag 0: always overwrite. 0x02 keeps stale saved values that+ // silently prevent the hotkey from firing on startup.await this.kglobalaccel.doRegister(actionId);- const result = await this.kglobalaccel.setShortcut(actionId, [qtKey], 0x02);+ const result = await this.kglobalaccel.setShortcut(actionId, [qtKey], 0);if (callback) this.callbacks.set(slotName, callback);this.registeredSlots.add(slotName);