Skip to content

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

fix: move ydotool setup to post-install scripts for deb/rpm

Alcahest34d6f89eb229
diff --git a/electron-builder.json b/electron-builder.json
index f6614cdeb..ee33f8bcd 100644
--- a/electron-builder.json
+++ b/electron-builder.json
@@ -159,9 +159,12 @@
]
},
"deb": {
+ "afterInstall": "resources/linux/after-install.sh",
"afterRemove": "resources/linux/after-remove.sh",
"depends": ["ydotool"],
"fpm": [
+ "--deb-recommends",
+ "ydotoold",
"--deb-suggests",
"xdotool",
"--deb-suggests",
@@ -172,6 +175,8 @@
},
"rpm": {
"fpm": [
+ "--after-install",
+ "resources/linux/after-install.sh",
"--rpm-tag",
"Requires: ydotool",
"--rpm-tag",
diff --git a/resources/linux/after-install.sh b/resources/linux/after-install.sh
new file mode 100755
index 000000000..cc6ae1398
--- /dev/null
+++ b/resources/linux/after-install.sh
@@ -0,0 +1,77 @@
+#!/bin/bash
+# Post-install script for OpenWhispr (deb/rpm)
+# Sets up ydotool daemon prerequisites for Wayland paste support
+
+set -euo pipefail
+
+UDEV_RULE='KERNEL=="uinput", GROUP="input", MODE="0660", TAG+="uaccess"'
+UDEV_RULE_PATH="/etc/udev/rules.d/80-uinput.rules"
+SERVICE_PATH="/usr/lib/systemd/user/ydotoold.service"
+
+# Detect the real user (not root) who triggered the install
+REAL_USER="${SUDO_USER:-}"
+if [ -z "$REAL_USER" ] || [ "$REAL_USER" = "root" ]; then
+ REAL_USER=$(logname 2>/dev/null || echo "")
+fi
+
+# 1. udev rule for /dev/uinput
+if [ ! -f "$UDEV_RULE_PATH" ] || ! grep -q uinput "$UDEV_RULE_PATH" 2>/dev/null; then
+ echo "$UDEV_RULE" > "$UDEV_RULE_PATH"
+ udevadm control --reload-rules 2>/dev/null || true
+ udevadm trigger /dev/uinput 2>/dev/null || true
+fi
+
+# 2. Add user to input group
+if [ -n "$REAL_USER" ]; then
+ if ! id -nG "$REAL_USER" 2>/dev/null | grep -qw input; then
+ usermod -aG input "$REAL_USER" 2>/dev/null || true
+ fi
+fi
+
+# 3. systemd user service for ydotoold
+# Skip if a service already exists (e.g. Fedora ships one with the ydotool package)
+if [ ! -f "$SERVICE_PATH" ] && [ ! -f "/usr/lib/systemd/user/ydotool.service" ]; then
+ YDOTOOLD_BIN=$(command -v ydotoold 2>/dev/null || echo "/usr/bin/ydotoold")
+ if [ -x "$YDOTOOLD_BIN" ] || [ -f "$YDOTOOLD_BIN" ]; then
+ mkdir -p "$(dirname "$SERVICE_PATH")"
+ cat > "$SERVICE_PATH" << SERVICEEOF
+[Unit]
+Description=ydotoold - ydotool daemon
+After=graphical-session.target
+PartOf=graphical-session.target
+
+[Service]
+ExecStartPre=/usr/bin/sleep 2
+ExecStart=$YDOTOOLD_BIN
+Restart=on-failure
+RestartSec=1s
+
+[Install]
+WantedBy=graphical-session.target
+SERVICEEOF
+ fi
+fi
+
+# 4. Enable the service for the installing user
+if [ -n "$REAL_USER" ]; then
+ REAL_UID=$(id -u "$REAL_USER" 2>/dev/null || echo "")
+ if [ -n "$REAL_UID" ]; then
+ # systemctl --user requires XDG_RUNTIME_DIR
+ export XDG_RUNTIME_DIR="/run/user/$REAL_UID"
+ if [ -d "$XDG_RUNTIME_DIR" ]; then
+ # Determine the correct service name
+ SERVICE_NAME=""
+ if [ -f "/usr/lib/systemd/user/ydotoold.service" ]; then
+ SERVICE_NAME="ydotoold"
+ elif [ -f "/usr/lib/systemd/user/ydotool.service" ]; then
+ SERVICE_NAME="ydotool"
+ fi
+ if [ -n "$SERVICE_NAME" ]; then
+ su - "$REAL_USER" -c "XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR systemctl --user daemon-reload" 2>/dev/null || true
+ su - "$REAL_USER" -c "XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR systemctl --user enable $SERVICE_NAME" 2>/dev/null || true
+ fi
+ fi
+ fi
+fi
+
+exit 0
diff --git a/resources/linux/after-remove.sh b/resources/linux/after-remove.sh
index 5aaadee50..045cc04ae 100755
--- a/resources/linux/after-remove.sh
+++ b/resources/linux/after-remove.sh
@@ -1,7 +1,18 @@
#!/bin/bash
set -euo pipefail
-CACHE_DIR="$HOME/.cache/openwhispr"
+REAL_USER="${SUDO_USER:-}"
+if [ -z "$REAL_USER" ] || [ "$REAL_USER" = "root" ]; then
+ REAL_USER=$(logname 2>/dev/null || echo "")
+fi
+
+if [ -n "$REAL_USER" ]; then
+ REAL_HOME=$(getent passwd "$REAL_USER" | cut -d: -f6)
+else
+ REAL_HOME="$HOME"
+fi
+
+CACHE_DIR="$REAL_HOME/.cache/openwhispr"
MODELS_DIR="$CACHE_DIR/models"
if [ -d "$MODELS_DIR" ]; then
diff --git a/src/helpers/ensureYdotool.js b/src/helpers/ensureYdotool.js
index 650bdade6..1e7626076 100644
--- a/src/helpers/ensureYdotool.js
+++ b/src/helpers/ensureYdotool.js
@@ -1,33 +1,51 @@
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");
+const os = require("os");
+const { spawnSync } = require("child_process");
+const { dialog } = require("electron");
function getLogger() {
return require("./debugLogger");
}
-function getSetupFlagPath() {
- return path.join(app.getPath("userData"), "ydotool-setup-done");
-}
-
-function isSetupDone() {
+function commandExists(name) {
try {
- return fs.existsSync(getSetupFlagPath());
- } catch (error) {
- getLogger().debug("isSetupDone check failed", { error: error.message }, "clipboard");
+ return spawnSync("which", [name], { stdio: "pipe", timeout: 5000 }).status === 0;
+ } catch {
return false;
}
}
-function markSetupDone() {
+function isYdotooldRunning() {
try {
- fs.writeFileSync(getSetupFlagPath(), new Date().toISOString());
- } catch (error) {
- getLogger().debug("Failed to persist setup flag", { error: error.message }, "clipboard");
- }
+ const result = spawnSync("systemctl", ["--user", "is-active", "ydotoold"], {
+ stdio: "pipe",
+ timeout: 5000,
+ });
+ if (result.stdout?.toString().trim() === "active") return true;
+ } catch {}
+
+ try {
+ const result = spawnSync("systemctl", ["--user", "is-active", "ydotool"], {
+ stdio: "pipe",
+ timeout: 5000,
+ });
+ if (result.stdout?.toString().trim() === "active") return true;
+ } catch {}
+
+ try {
+ return spawnSync("pgrep", ["-x", "ydotoold"], { stdio: "pipe", timeout: 5000 }).status === 0;
+ } catch {}
+
+ return false;
+}
+
+function serviceFileExists() {
+ const paths = [
+ "/usr/lib/systemd/user/ydotoold.service",
+ "/usr/lib/systemd/user/ydotool.service",
+ `${os.homedir()}/.config/systemd/user/ydotoold.service`,
+ ];
+ return paths.some((p) => fs.existsSync(p));
}
function isUinputAccessible() {
@@ -39,22 +57,13 @@ function isUinputAccessible() {
}
}
-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;
+function userInInputGroup() {
+ try {
+ const result = spawnSync("groups", [], { stdio: "pipe", timeout: 5000 });
+ return result.stdout?.toString().includes("input") ?? false;
+ } catch {
+ return false;
+ }
}
async function ensureYdotool() {
@@ -65,53 +74,84 @@ async function ensureYdotool() {
const log = getLogger();
- // If setup already completed, just ensure daemon is running
- if (isSetupDone()) {
- if (!isYdotooldRunning()) {
- await tryStartYdotoold(log);
- }
+ const hasYdotool = commandExists("ydotool");
+ const hasYdotoold = commandExists("ydotoold");
+ const daemonRunning = isYdotooldRunning();
+ const hasService = serviceFileExists();
+ const hasUinput = isUinputAccessible();
+ const hasGroup = userInInputGroup();
+
+ log.debug(
+ "ydotool check",
+ { hasYdotool, hasYdotoold, daemonRunning, hasService, hasUinput, hasGroup },
+ "clipboard"
+ );
+
+ // Everything is fine
+ if (hasYdotool && hasYdotoold && daemonRunning && hasUinput) {
+ log.debug("ydotool fully configured", {}, "clipboard");
return;
}
- // If everything already works, persist flag and return
- if (commandExists("ydotool") && isYdotooldRunning()) {
- markSetupDone();
- log.debug("ydotool already configured", {}, "clipboard");
- return;
+ // If the service exists and daemon is just not running, try to start it
+ if (hasYdotoold && hasService && !daemonRunning) {
+ try {
+ spawnSync("systemctl", ["--user", "start", "ydotoold"], { stdio: "pipe", timeout: 10000 });
+ if (isYdotooldRunning()) {
+ log.info("ydotoold daemon started", {}, "clipboard");
+ return;
+ }
+ } catch {}
+ try {
+ spawnSync("systemctl", ["--user", "start", "ydotool"], { stdio: "pipe", timeout: 10000 });
+ if (isYdotooldRunning()) {
+ log.info("ydotool daemon started", {}, "clipboard");
+ return;
+ }
+ } catch {}
}
- const needsInstall = !commandExists("ydotool");
- const needsUinput = !isUinputAccessible();
+ // Something is missing — build an informative message
+ const missing = [];
- // 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;
- }
+ if (!hasYdotool) {
+ missing.push("- ydotool is not installed. Install it with your package manager.");
+ }
+ if (!hasYdotoold) {
+ missing.push(
+ "- ydotoold (daemon) is not installed. On Ubuntu/Pop!_OS: sudo apt install ydotoold"
+ );
+ }
+ if (!hasUinput) {
+ missing.push(
+ '- /dev/uinput is not accessible. Add a udev rule:\n echo \'KERNEL=="uinput", GROUP="input", MODE="0660", TAG+="uaccess"\' | sudo tee /etc/udev/rules.d/80-uinput.rules\n sudo udevadm control --reload-rules && sudo udevadm trigger /dev/uinput'
+ );
+ }
+ if (!hasGroup) {
+ missing.push(
+ "- Your user is not in the 'input' group. Run: sudo usermod -aG input $USER\n (requires logout/login to take effect)"
+ );
+ }
+ if (hasYdotoold && !hasService) {
+ missing.push(
+ "- No systemd service found for ydotoold. Enable it with:\n systemctl --user enable ydotoold && systemctl --user start ydotoold"
+ );
+ }
+ if (hasYdotoold && hasService && !daemonRunning) {
+ missing.push(
+ "- ydotoold service exists but is not running. Start it with:\n systemctl --user start ydotoold"
+ );
}
- 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");
+ if (missing.length > 0) {
+ const detail = missing.join("\n\n");
+ log.warn("ydotool setup incomplete", { missing: missing.length }, "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}`,
+ title: "Wayland Paste Setup",
+ message: "ydotool is not fully configured. Auto-paste on Wayland may not work.",
+ detail: `The following issues were detected:\n\n${detail}\n\nAfter fixing, restart OpenWhispr.`,
});
}
}
diff --git a/src/helpers/ydotoolInstaller.js b/src/helpers/ydotoolInstaller.js
deleted file mode 100644
index 1c1e07fe2..000000000
--- a/src/helpers/ydotoolInstaller.js
+++ /dev/null
@@ -1,119 +0,0 @@
-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
deleted file mode 100644
index 3bf65a054..000000000
--- a/src/helpers/ydotoolService.js
+++ /dev/null
@@ -1,164 +0,0 @@
-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 };