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 nircmd for faster windows pasting

Gabriel Steina594ed400366
diff --git a/.claude/settings.local.json b/.claude/settings.local.json
new file mode 100644
index 000000000..2f339c578
--- /dev/null
+++ b/.claude/settings.local.json
@@ -0,0 +1,9 @@
+{
+ "permissions": {
+ "allow": [
+ "Bash(curl:*)"
+ ],
+ "deny": [],
+ "ask": []
+ }
+}
diff --git a/.github/workflows/build-and-notarize.yml b/.github/workflows/build-and-notarize.yml
index 0cac7ebfd..4c740baec 100644
--- a/.github/workflows/build-and-notarize.yml
+++ b/.github/workflows/build-and-notarize.yml
@@ -37,6 +37,9 @@ jobs:
- name: Download whisper.cpp binaries
run: node scripts/download-whisper-cpp.js
+ - name: Download nircmd.exe (Windows only)
+ run: node scripts/download-nircmd.js
+
# Cache Electron downloads
- name: Cache Electron
uses: actions/cache@v4
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 0570d40bb..19cd6925b 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -44,6 +44,9 @@ jobs:
- name: Download whisper.cpp binaries
run: node scripts/download-whisper-cpp.js
+ - name: Download nircmd.exe (Windows only)
+ run: node scripts/download-nircmd.js
+
# macOS code signing setup (same as build workflow)
- name: Setup macOS Code Signing
if: matrix.os == 'macos-latest'
diff --git a/electron-builder.json b/electron-builder.json
index 233ca9b26..e9662aba1 100644
--- a/electron-builder.json
+++ b/electron-builder.json
@@ -65,7 +65,13 @@
"nsis",
"portable"
],
- "icon": "src/assets/icon.ico"
+ "icon": "src/assets/icon.ico",
+ "extraResources": [
+ {
+ "from": "resources/bin/nircmd.exe",
+ "to": "bin/nircmd.exe"
+ }
+ ]
},
"linux": {
"target": [
diff --git a/scripts/download-nircmd.js b/scripts/download-nircmd.js
new file mode 100644
index 000000000..509ee88f5
--- /dev/null
+++ b/scripts/download-nircmd.js
@@ -0,0 +1,181 @@
+#!/usr/bin/env node
+/**
+ * Downloads nircmd.exe for Windows builds.
+ *
+ * nircmd is a small utility for Windows that allows sending keyboard input
+ * and other system commands. Used for fast clipboard paste operations.
+ *
+ * Source: https://www.nirsoft.net/utils/nircmd.html
+ * License: Free for non-commercial use
+ */
+
+const https = require("https");
+const fs = require("fs");
+const path = require("path");
+const { execSync } = require("child_process");
+
+const NIRCMD_URL = "https://www.nirsoft.net/utils/nircmd-x64.zip";
+const BIN_DIR = path.join(__dirname, "..", "resources", "bin");
+const NIRCMD_PATH = path.join(BIN_DIR, "nircmd.exe");
+
+const REQUEST_TIMEOUT = 30000; // 30 seconds
+const MAX_RETRIES = 3;
+const RETRY_DELAY = 2000;
+
+function sleep(ms) {
+ return new Promise((resolve) => setTimeout(resolve, ms));
+}
+
+function downloadFile(url, dest, retryCount = 0) {
+ return new Promise((resolve, reject) => {
+ const file = fs.createWriteStream(dest);
+ let activeRequest = null;
+
+ const cleanup = () => {
+ if (activeRequest) {
+ activeRequest.destroy();
+ activeRequest = null;
+ }
+ file.close();
+ };
+
+ const request = (currentUrl, redirectCount = 0) => {
+ if (redirectCount > 5) {
+ cleanup();
+ reject(new Error("Too many redirects"));
+ return;
+ }
+
+ activeRequest = https.get(currentUrl, (response) => {
+ if (response.statusCode === 302 || response.statusCode === 301) {
+ const redirectUrl = response.headers.location;
+ if (!redirectUrl) {
+ cleanup();
+ reject(new Error("Redirect without location header"));
+ return;
+ }
+ request(redirectUrl, redirectCount + 1);
+ return;
+ }
+
+ if (response.statusCode !== 200) {
+ cleanup();
+ reject(new Error(`Failed to download: HTTP ${response.statusCode}`));
+ return;
+ }
+
+ const total = parseInt(response.headers["content-length"], 10);
+ let downloaded = 0;
+
+ response.on("data", (chunk) => {
+ downloaded += chunk.length;
+ const pct = total ? Math.round((downloaded / total) * 100) : 0;
+ process.stdout.write(`\r Downloading: ${pct}%`);
+ });
+
+ response.on("error", (err) => {
+ cleanup();
+ reject(err);
+ });
+
+ response.pipe(file);
+ file.on("finish", () => {
+ file.close();
+ console.log(" Done");
+ resolve();
+ });
+
+ file.on("error", (err) => {
+ cleanup();
+ reject(err);
+ });
+ });
+
+ activeRequest.on("error", (err) => {
+ cleanup();
+ reject(err);
+ });
+
+ activeRequest.setTimeout(REQUEST_TIMEOUT, () => {
+ cleanup();
+ reject(new Error("Connection timed out"));
+ });
+ };
+
+ request(url);
+ }).catch(async (error) => {
+ if (retryCount < MAX_RETRIES) {
+ console.log(`\n Retry ${retryCount + 1}/${MAX_RETRIES}: ${error.message}`);
+ await sleep(RETRY_DELAY);
+ if (fs.existsSync(dest)) {
+ fs.unlinkSync(dest);
+ }
+ return downloadFile(url, dest, retryCount + 1);
+ }
+ throw error;
+ });
+}
+
+function extractZip(zipPath, destDir) {
+ if (process.platform === "win32") {
+ execSync(
+ `powershell -command "Expand-Archive -Path '${zipPath}' -DestinationPath '${destDir}' -Force"`,
+ { stdio: "inherit" }
+ );
+ } else {
+ execSync(`unzip -o "${zipPath}" -d "${destDir}"`, { stdio: "inherit" });
+ }
+}
+
+async function main() {
+ // Skip if not Windows and not building for all platforms
+ if (process.platform !== "win32" && !process.argv.includes("--all")) {
+ console.log("\nSkipping nircmd.exe download (Windows-only utility)\n");
+ return;
+ }
+
+ console.log("\nDownloading nircmd.exe for Windows...\n");
+
+ // Create bin directory
+ fs.mkdirSync(BIN_DIR, { recursive: true });
+
+ // Check if already exists
+ if (fs.existsSync(NIRCMD_PATH)) {
+ console.log(" nircmd.exe already exists, skipping\n");
+ return;
+ }
+
+ const zipPath = path.join(BIN_DIR, "nircmd-x64.zip");
+
+ try {
+ console.log(` Downloading from ${NIRCMD_URL}`);
+ await downloadFile(NIRCMD_URL, zipPath);
+
+ console.log(" Extracting...");
+ const extractDir = path.join(BIN_DIR, "temp-nircmd");
+ fs.mkdirSync(extractDir, { recursive: true });
+ extractZip(zipPath, extractDir);
+
+ // Copy nircmd.exe to bin directory
+ const extractedPath = path.join(extractDir, "nircmd.exe");
+ if (fs.existsSync(extractedPath)) {
+ fs.copyFileSync(extractedPath, NIRCMD_PATH);
+ const stats = fs.statSync(NIRCMD_PATH);
+ console.log(` ✓ nircmd.exe downloaded (${Math.round(stats.size / 1024)}KB)\n`);
+ } else {
+ console.error(" ✗ nircmd.exe not found in archive\n");
+ process.exit(1);
+ }
+
+ // Cleanup
+ fs.rmSync(extractDir, { recursive: true, force: true });
+ fs.unlinkSync(zipPath);
+
+ } catch (error) {
+ console.error(` ✗ Failed to download nircmd.exe: ${error.message}\n`);
+ if (fs.existsSync(zipPath)) fs.unlinkSync(zipPath);
+ process.exit(1);
+ }
+}
+
+main().catch(console.error);
diff --git a/src/helpers/clipboard.js b/src/helpers/clipboard.js
index 2d00028b1..cfdfbd548 100644
--- a/src/helpers/clipboard.js
+++ b/src/helpers/clipboard.js
@@ -1,6 +1,8 @@
-const { clipboard } = require("electron");
+const { clipboard, app } = require("electron");
const { spawn, spawnSync } = require("child_process");
const { killProcess } = require("../utils/process");
+const path = require("path");
+const fs = require("fs");
// Cache TTL constants - these mirror CACHE_CONFIG.AVAILABILITY_CHECK_TTL in src/config/constants.ts
const CACHE_TTL_MS = 30000;
@@ -11,6 +13,45 @@ class ClipboardManager {
constructor() {
this.accessibilityCache = { value: null, expiresAt: 0 };
this.commandAvailabilityCache = new Map();
+ this.nircmdPath = null;
+ this.nircmdChecked = false;
+ }
+
+ // Get path to nircmd.exe (Windows only)
+ getNircmdPath() {
+ if (this.nircmdChecked) {
+ return this.nircmdPath;
+ }
+
+ this.nircmdChecked = true;
+
+ if (process.platform !== "win32") {
+ return null;
+ }
+
+ // Try multiple paths for nircmd.exe
+ const possiblePaths = [
+ // Production: extraResources
+ path.join(process.resourcesPath, "bin", "nircmd.exe"),
+ // Development: resources/bin
+ path.join(__dirname, "..", "..", "resources", "bin", "nircmd.exe"),
+ path.join(process.cwd(), "resources", "bin", "nircmd.exe"),
+ ];
+
+ for (const nircmdPath of possiblePaths) {
+ try {
+ if (fs.existsSync(nircmdPath)) {
+ this.safeLog(`✅ Found nircmd.exe at: ${nircmdPath}`);
+ this.nircmdPath = nircmdPath;
+ return nircmdPath;
+ }
+ } catch (error) {
+ // Continue checking other paths
+ }
+ }
+
+ this.safeLog("⚠️ nircmd.exe not found, will use PowerShell fallback");
+ return null;
}
// Safe logging method - only log in development
@@ -122,13 +163,91 @@ class ClipboardManager {
}
async pasteWindows(originalClipboard) {
+ // Try nircmd first if available, fallback to PowerShell
+ const nircmdPath = this.getNircmdPath();
+
+ if (nircmdPath) {
+ return this.pasteWithNircmd(nircmdPath, originalClipboard);
+ } else {
+ return this.pasteWithPowerShell(originalClipboard);
+ }
+ }
+
+ async pasteWithNircmd(nircmdPath, originalClipboard) {
+ return new Promise((resolve, reject) => {
+ // Minimal delay for nircmd - it's very fast
+ setTimeout(() => {
+ let hasTimedOut = false;
+ const startTime = Date.now();
+
+ this.safeLog("⚡ Starting nircmd paste operation...");
+
+ // nircmd sendkey ctrl+v
+ const pasteProcess = spawn(nircmdPath, ["sendkeypress", "ctrl+v"]);
+
+ let errorOutput = "";
+
+ pasteProcess.stderr.on("data", (data) => {
+ errorOutput += data.toString();
+ });
+
+ pasteProcess.on("close", (code) => {
+ if (hasTimedOut) return;
+ clearTimeout(timeoutId);
+
+ const elapsed = Date.now() - startTime;
+
+ if (code === 0) {
+ this.safeLog(`✅ nircmd paste completed successfully in ${elapsed}ms`);
+ // Restore original clipboard quickly
+ setTimeout(() => {
+ clipboard.writeText(originalClipboard);
+ this.safeLog("🔄 Original clipboard content restored");
+ }, 50);
+ resolve();
+ } else {
+ this.safeLog(
+ `❌ nircmd paste failed with code ${code} after ${elapsed}ms`,
+ errorOutput
+ );
+ // Fallback to PowerShell
+ this.safeLog("🔄 Falling back to PowerShell...");
+ this.pasteWithPowerShell(originalClipboard).then(resolve).catch(reject);
+ }
+ });
+
+ pasteProcess.on("error", (error) => {
+ if (hasTimedOut) return;
+ clearTimeout(timeoutId);
+ const elapsed = Date.now() - startTime;
+ this.safeLog(`❌ nircmd error after ${elapsed}ms:`, error.message);
+ // Fallback to PowerShell
+ this.safeLog("🔄 Falling back to PowerShell...");
+ this.pasteWithPowerShell(originalClipboard).then(resolve).catch(reject);
+ });
+
+ const timeoutId = setTimeout(() => {
+ hasTimedOut = true;
+ const elapsed = Date.now() - startTime;
+ this.safeLog(`⏱️ nircmd paste timed out after ${elapsed}ms`);
+ killProcess(pasteProcess, "SIGKILL");
+ pasteProcess.removeAllListeners();
+ // Fallback to PowerShell
+ this.safeLog("🔄 Falling back to PowerShell...");
+ this.pasteWithPowerShell(originalClipboard).then(resolve).catch(reject);
+ }, 2000); // Shorter timeout for fast nircmd
+ }, 5); // Very short delay for nircmd
+ });
+ }
+
+ async pasteWithPowerShell(originalClipboard) {
return new Promise((resolve, reject) => {
// Reduce delay - clipboard.writeText is synchronous so no need to wait
setTimeout(() => {
let hasTimedOut = false;
const startTime = Date.now();
- this.safeLog("🪟 Starting Windows paste operation...");
+ this.safeLog("🪟 Starting PowerShell paste operation...");
// Optimized PowerShell command:
// - Uses [void] to suppress output (faster)
@@ -160,7 +279,7 @@ class ClipboardManager {
const elapsed = Date.now() - startTime;
if (code === 0) {
- this.safeLog(`✅ Windows paste completed successfully in ${elapsed}ms`);
+ this.safeLog(`✅ PowerShell paste completed successfully in ${elapsed}ms`);
// Text pasted successfully - restore original clipboard
// Use shorter delay since paste is already complete
setTimeout(() => {
@@ -170,7 +289,7 @@ class ClipboardManager {
resolve();
} else {
this.safeLog(
- `❌ Windows paste failed with code ${code} after ${elapsed}ms`,
+ `❌ PowerShell paste failed with code ${code} after ${elapsed}ms`,
errorOutput
);
reject(
@@ -185,7 +304,7 @@ class ClipboardManager {
if (hasTimedOut) return;
clearTimeout(timeoutId);
const elapsed = Date.now() - startTime;
- this.safeLog(`❌ Windows paste error after ${elapsed}ms:`, error.message);
+ this.safeLog(`❌ PowerShell paste error after ${elapsed}ms:`, error.message);
reject(
new Error(
`Windows paste failed: ${error.message}. Text is copied to clipboard - please paste manually with Ctrl+V.`
@@ -196,7 +315,7 @@ class ClipboardManager {
const timeoutId = setTimeout(() => {
hasTimedOut = true;
const elapsed = Date.now() - startTime;
- this.safeLog(`⏱️ Windows paste operation timed out after ${elapsed}ms`);
+ this.safeLog(`⏱️ PowerShell paste operation timed out after ${elapsed}ms`);
killProcess(pasteProcess, "SIGKILL");
pasteProcess.removeAllListeners();
reject(