From 5bb4f5c08422260cbebd29d9d08ee78ba0c9d6ef Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Thu, 26 Mar 2026 20:12:33 +0200 Subject: [PATCH] implement replace handler with clipboard swap and paste-back --- surfsense_desktop/src/modules/quick-ask.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/surfsense_desktop/src/modules/quick-ask.ts b/surfsense_desktop/src/modules/quick-ask.ts index 59246e946..3bee2bbc2 100644 --- a/surfsense_desktop/src/modules/quick-ask.ts +++ b/surfsense_desktop/src/modules/quick-ask.ts @@ -118,6 +118,23 @@ export function registerQuickAsk(): void { pendingText = ''; return text; }); + + ipcMain.handle(IPC_CHANNELS.REPLACE_TEXT, async (_event, text: string) => { + if (process.platform !== 'darwin' || !sourceApp) return; + + clipboard.writeText(text); + hideQuickAsk(); + + try { + execSync(`osascript -e 'tell application "${sourceApp}" to activate'`); + await new Promise((r) => setTimeout(r, 100)); + execSync('osascript -e \'tell application "System Events" to keystroke "v" using command down\''); + await new Promise((r) => setTimeout(r, 100)); + clipboard.writeText(savedClipboard); + } catch { + clipboard.writeText(savedClipboard); + } + }); } export function unregisterQuickAsk(): void {