Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

feat: add ydotool as required Linux dependency (#346)

Alcahest9e198a17a7ac
diff --git a/electron-builder.json b/electron-builder.json
index 6923e33c4..f6614cdeb 100644
--- a/electron-builder.json
+++ b/electron-builder.json
@@ -160,6 +160,7 @@
},
"deb": {
"afterRemove": "resources/linux/after-remove.sh",
+ "depends": ["ydotool"],
"fpm": [
"--deb-suggests",
"xdotool",
@@ -171,6 +172,8 @@
},
"rpm": {
"fpm": [
+ "--rpm-tag",
+ "Requires: ydotool",
"--rpm-tag",
"Suggests: xdotool",
"--rpm-tag",
diff --git a/main.js b/main.js
index 27cd0245c..7b8c24bc6 100644
--- a/main.js
+++ b/main.js
@@ -167,6 +167,7 @@ const WindowsKeyManager = require("./src/helpers/windowsKeyManager");
const TextEditMonitor = require("./src/helpers/textEditMonitor");
const WhisperCudaManager = require("./src/helpers/whisperCudaManager");
const { i18nMain, changeLanguage } = require("./src/helpers/i18nMain");
+const { ensureYdotool } = require("./src/helpers/ensureYdotool");
// Manager instances - initialized after app.whenReady()
let debugLogger = null;
@@ -269,6 +270,9 @@ function initializeCoreManagers() {
// Phase 2: Non-critical setup after windows are visible
function initializeDeferredManagers() {
+ ensureYdotool().catch((err) => {
+ require("./src/helpers/debugLogger").warn("ydotool setup error", { error: err?.message }, "clipboard");
+ });
clipboardManager.preWarmAccessibility();
trayManager = new TrayManager();
globeKeyManager = new GlobeKeyManager();
diff --git a/src/helpers/ensureYdotool.js b/src/helpers/ensureYdotool.js
new file mode 100644
index 000000000..650bdade6
--- /dev/null
+++ b/src/helpers/ensureYdotool.js
@@ -0,0 +1,119 @@
+const fs = require("fs");
+const path = require("path");
+const { app, dialog } = require("electron");
+
+const { installYdotool, setupUinputAccess, commandExists } = require("./ydotoolInstaller");
+const { isYdotooldRunning, tryStartYdotoold, ensureYdotooldDaemon } = require("./ydotoolService");
+
+function getLogger() {
+ return require("./debugLogger");
+}
+
+function getSetupFlagPath() {
+ return path.join(app.getPath("userData"), "ydotool-setup-done");
+}
+
+function isSetupDone() {
+ try {
+ return fs.existsSync(getSetupFlagPath());
+ } catch (error) {
+ getLogger().debug("isSetupDone check failed", { error: error.message }, "clipboard");
+ return false;
+ }
+}
+
+function markSetupDone() {
+ try {
+ fs.writeFileSync(getSetupFlagPath(), new Date().toISOString());
+ } catch (error) {
+ getLogger().debug("Failed to persist setup flag", { error: error.message }, "clipboard");
+ }
+}
+
+function isUinputAccessible() {
+ try {
+ fs.accessSync("/dev/uinput", fs.constants.W_OK);
+ return true;
+ } catch {
+ return false;
+ }
+}
+
+async function askUserConsent(needsInstall, needsUinput) {
+ const actions = [];
+ if (needsInstall) actions.push("Install ydotool (paste support for Wayland)");
+ if (needsUinput) actions.push("Configure /dev/uinput permissions");
+
+ const { response } = await dialog.showMessageBox({
+ type: "question",
+ buttons: ["Allow", "Skip"],
+ defaultId: 0,
+ cancelId: 1,
+ title: "Wayland Paste Setup",
+ message: "OpenWhispr needs to set up ydotool for reliable paste on Wayland.",
+ detail: `This requires administrator privileges to:\n${actions.map((a) => `\u2022 ${a}`).join("\n")}`,
+ });
+
+ return response === 0;
+}
+
+async function ensureYdotool() {
+ if (process.platform !== "linux") return;
+
+ const sessionType = (process.env.XDG_SESSION_TYPE || "").toLowerCase();
+ if (sessionType !== "wayland" && !process.env.WAYLAND_DISPLAY) return;
+
+ const log = getLogger();
+
+ // If setup already completed, just ensure daemon is running
+ if (isSetupDone()) {
+ if (!isYdotooldRunning()) {
+ await tryStartYdotoold(log);
+ }
+ return;
+ }
+
+ // If everything already works, persist flag and return
+ if (commandExists("ydotool") && isYdotooldRunning()) {
+ markSetupDone();
+ log.debug("ydotool already configured", {}, "clipboard");
+ return;
+ }
+
+ const needsInstall = !commandExists("ydotool");
+ const needsUinput = !isUinputAccessible();
+
+ // Ask user before any root escalation
+ if (needsInstall || needsUinput) {
+ const consent = await askUserConsent(needsInstall, needsUinput);
+ if (!consent) {
+ log.info("User declined ydotool setup", {}, "clipboard");
+ return;
+ }
+ }
+
+ try {
+ if (needsInstall) {
+ await installYdotool(log);
+ }
+
+ if (needsUinput) {
+ await setupUinputAccess(log);
+ }
+
+ const hasUserConsent = needsInstall || needsUinput;
+ await ensureYdotooldDaemon(log, { hasUserConsent });
+ markSetupDone();
+ log.info("ydotool setup completed", {}, "clipboard");
+ } catch (error) {
+ log.warn("ydotool setup failed", { error: error.message }, "clipboard");
+ dialog.showMessageBox({
+ type: "warning",
+ title: "ydotool Setup Incomplete",
+ message: "ydotool setup could not be completed.",
+ detail: `Paste on Wayland may not work reliably. You can install ydotool manually.\n\n${error.message}`,
+ });
+ }
+}
+
+module.exports = { ensureYdotool };
diff --git a/src/helpers/ydotoolInstaller.js b/src/helpers/ydotoolInstaller.js
new file mode 100644
index 000000000..1c1e07fe2
--- /dev/null
+++ b/src/helpers/ydotoolInstaller.js
@@ -0,0 +1,119 @@
+const { execFile, spawnSync } = require("child_process");
+const { promisify } = require("util");
+const fs = require("fs");
+const path = require("path");
+const os = require("os");
+
+const execFileAsync = promisify(execFile);
+
+const UDEV_RULE = 'KERNEL=="uinput", GROUP="input", MODE="0660", TAG+="uaccess"';
+const UDEV_RULE_PATH = "/etc/udev/rules.d/80-uinput.rules";
+
+function getLogger() {
+ return require("./debugLogger");
+}
+
+function commandExists(name) {
+ try {
+ const result = spawnSync("which", [name], { stdio: "pipe", timeout: 5000 });
+ return result.status === 0;
+ } catch (error) {
+ getLogger().debug(`commandExists(${name}) failed`, { error: error.message }, "clipboard");
+ return false;
+ }
+}
+
+function getInstallArgs() {
+ const managers = [
+ { bin: "dnf", args: ["dnf", "install", "-y", "ydotool"] },
+ { bin: "apt-get", args: ["apt-get", "install", "-y", "ydotool"] },
+ { bin: "pacman", args: ["pacman", "-S", "--noconfirm", "ydotool"] },
+ { bin: "zypper", args: ["zypper", "install", "-y", "ydotool"] },
+ ];
+
+ for (const { bin, args } of managers) {
+ if (commandExists(bin)) return args;
+ }
+ return null;
+}
+
+async function installYdotool(log) {
+ const args = getInstallArgs();
+ if (!args) {
+ log.warn("No supported package manager found for ydotool", {}, "clipboard");
+ return;
+ }
+
+ log.info(`Installing ydotool via: pkexec ${args.join(" ")}`, {}, "clipboard");
+ await execFileAsync("pkexec", args, { timeout: 120000 });
+ log.info("ydotool installed", {}, "clipboard");
+}
+
+function udevRuleExists() {
+ try {
+ const content = fs.readFileSync(UDEV_RULE_PATH, "utf8");
+ return content.includes("uinput");
+ } catch (error) {
+ getLogger().debug("udev rule check failed", { error: error.message }, "clipboard");
+ return false;
+ }
+}
+
+function userInInputGroup() {
+ try {
+ const result = spawnSync("groups", [], { stdio: "pipe", timeout: 5000 });
+ return result.stdout?.toString().includes("input") ?? false;
+ } catch (error) {
+ getLogger().debug("groups check failed", { error: error.message }, "clipboard");
+ return false;
+ }
+}
+
+async function setupUinputAccess(log) {
+ const needsRule = !udevRuleExists();
+ const needsGroup = !userInInputGroup();
+
+ if (!needsRule && !needsGroup) return;
+
+ const lines = ["#!/bin/sh", "set -e"];
+
+ if (needsRule) {
+ lines.push(`printf '%s\\n' '${UDEV_RULE}' > '${UDEV_RULE_PATH}'`);
+ }
+
+ if (needsGroup) {
+ const username = os.userInfo().username;
+ if (/^[a-z_][a-z0-9_-]*\$?$/.test(username)) {
+ lines.push(`usermod -aG input '${username}'`);
+ } else {
+ log.warn("Skipping group addition: invalid username", { username }, "clipboard");
+ }
+ }
+
+ if (needsRule) {
+ lines.push("udevadm control --reload-rules");
+ lines.push("udevadm trigger /dev/uinput");
+ }
+
+ if (lines.length <= 2) return;
+
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "openwhispr-"));
+ fs.chmodSync(tmpDir, 0o700);
+ const tmpScript = path.join(tmpDir, "uinput-setup.sh");
+ fs.writeFileSync(tmpScript, lines.join("\n") + "\n", { mode: 0o700 });
+
+ try {
+ log.info("Setting up /dev/uinput via pkexec", {}, "clipboard");
+ await execFileAsync("pkexec", [tmpScript], { timeout: 120000 });
+ log.info("uinput permissions configured", {}, "clipboard");
+ } finally {
+ try {
+ fs.unlinkSync(tmpScript);
+ fs.rmdirSync(tmpDir);
+ } catch (error) {
+ log.debug("Setup script cleanup failed", { error: error.message }, "clipboard");
+ }
+ }
+}
+
+module.exports = { installYdotool, setupUinputAccess, commandExists };
diff --git a/src/helpers/ydotoolService.js b/src/helpers/ydotoolService.js
new file mode 100644
index 000000000..7d372b788
--- /dev/null
+++ b/src/helpers/ydotoolService.js
@@ -0,0 +1,160 @@
+const { execFile, spawnSync } = require("child_process");
+const { promisify } = require("util");
+const fs = require("fs");
+const path = require("path");
+const os = require("os");
+
+const execFileAsync = promisify(execFile);
+
+function getLogger() {
+ return require("./debugLogger");
+}
+
+function findBinary(name) {
+ try {
+ const result = spawnSync("which", [name], { stdio: "pipe", timeout: 5000 });
+ if (result.status === 0) return result.stdout.toString().trim();
+ } catch (error) {
+ getLogger().debug(`findBinary(${name}) failed`, { error: error.message }, "clipboard");
+ }
+
+ for (const p of [`/usr/bin/${name}`, `/usr/local/bin/${name}`]) {
+ if (fs.existsSync(p)) return p;
+ }
+ return null;
+}
+
+function isYdotooldRunning() {
+ try {
+ const result = spawnSync("systemctl", ["--user", "is-active", "ydotoold"], {
+ stdio: "pipe",
+ timeout: 5000,
+ });
+ if (result.stdout?.toString().trim() === "active") return true;
+ } catch (error) {
+ getLogger().debug("systemctl user check failed", { error: error.message }, "clipboard");
+ }
+
+ try {
+ const result = spawnSync("systemctl", ["is-active", "ydotoold"], {
+ stdio: "pipe",
+ timeout: 5000,
+ });
+ if (result.stdout?.toString().trim() === "active") return true;
+ } catch (error) {
+ getLogger().debug("systemctl system check failed", { error: error.message }, "clipboard");
+ }
+
+ try {
+ const result = spawnSync("pgrep", ["-x", "ydotoold"], { stdio: "pipe", timeout: 5000 });
+ if (result.status === 0) return true;
+ } catch (error) {
+ getLogger().debug("pgrep check failed", { error: error.message }, "clipboard");
+ }
+
+ return false;
+}
+
+function createUserService(ydotooldPath, log) {
+ const serviceDir = path.join(os.homedir(), ".config", "systemd", "user");
+ const servicePath = path.join(serviceDir, "ydotoold.service");
+
+ if (fs.existsSync(servicePath)) {
+ log.debug("ydotoold user service already exists", {}, "clipboard");
+ return;
+ }
+
+ const serviceContent = [
+ "[Unit]",
+ "Description=ydotoold - ydotool daemon",
+ "Documentation=man:ydotoold(8)",
+ "After=graphical-session.target",
+ "",
+ "[Service]",
+ `ExecStart=${ydotooldPath}`,
+ "Restart=on-failure",
+ "RestartSec=3",
+ "",
+ "[Install]",
+ "WantedBy=default.target",
+ "",
+ ].join("\n");
+
+ try {
+ fs.mkdirSync(serviceDir, { recursive: true });
+ fs.writeFileSync(servicePath, serviceContent);
+ spawnSync("systemctl", ["--user", "daemon-reload"], { stdio: "pipe", timeout: 10000 });
+ log.info("ydotoold service file created", {}, "clipboard");
+ } catch (error) {
+ log.warn("Failed to create ydotoold service", { error: error.message }, "clipboard");
+ }
+}
+
+async function tryStartYdotoold(log) {
+ try {
+ await execFileAsync("systemctl", ["--user", "enable", "ydotoold"], { timeout: 10000 });
+ } catch (error) {
+ log.debug("ydotoold enable failed", { error: error.message }, "clipboard");
+ }
+
+ try {
+ await execFileAsync("systemctl", ["--user", "start", "ydotoold"], { timeout: 10000 });
+ log.info("ydotoold started", {}, "clipboard");
+ return;
+ } catch (error) {
+ log.debug("ydotoold start failed, retrying after cleanup", { error: error.message }, "clipboard");
+ }
+
+ // Cleanup stale state — scoped to current user via systemctl
+ try {
+ await execFileAsync("systemctl", ["--user", "stop", "ydotoold"], { timeout: 10000 });
+ } catch (error) {
+ log.debug("ydotoold stop failed", { error: error.message }, "clipboard");
+ }
+
+ const socketPath = path.join(os.tmpdir(), ".ydotool_socket");
+ try {
+ const stat = fs.statSync(socketPath);
+ if (stat.uid === process.getuid()) {
+ fs.unlinkSync(socketPath);
+ }
+ } catch (error) {
+ log.debug("Socket cleanup skipped", { error: error.message }, "clipboard");
+ }
+
+ try {
+ await execFileAsync("systemctl", ["--user", "start", "ydotoold"], { timeout: 10000 });
+ log.info("ydotoold started after cleanup", {}, "clipboard");
+ } catch (error) {
+ log.warn("ydotoold failed to start", { error: error.message }, "clipboard");
+ }
+}
+
+async function ensureYdotooldDaemon(log, { hasUserConsent = false } = {}) {
+ const { commandExists } = require("./ydotoolInstaller");
+
+ let ydotooldPath = findBinary("ydotoold");
+
+ // On some distros (Ubuntu 24.04) ydotoold is a separate package
+ if (!ydotooldPath && hasUserConsent && commandExists("apt-get")) {
+ log.info("Installing ydotoold package separately", {}, "clipboard");
+ try {
+ await execFileAsync("pkexec", ["apt-get", "install", "-y", "ydotoold"], {
+ timeout: 120000,
+ });
+ } catch (error) {
+ log.debug("ydotoold package install failed", { error: error.message }, "clipboard");
+ }
+ ydotooldPath = findBinary("ydotoold");
+ }
+
+ if (!ydotooldPath) {
+ log.warn("ydotoold binary not found", {}, "clipboard");
+ return;
+ }
+
+ createUserService(ydotooldPath, log);
+ await tryStartYdotoold(log);
+}
+
+module.exports = { isYdotooldRunning, tryStartYdotoold, ensureYdotooldDaemon };