diff --git a/surfsense_desktop/src/modules/keyboard.ts b/surfsense_desktop/src/modules/platform.ts similarity index 62% rename from surfsense_desktop/src/modules/keyboard.ts rename to surfsense_desktop/src/modules/platform.ts index 1fca34b79..37e126799 100644 --- a/surfsense_desktop/src/modules/keyboard.ts +++ b/surfsense_desktop/src/modules/platform.ts @@ -19,6 +19,28 @@ export function getFrontmostApp(): string { return ''; } +export function getSelectedText(): string { + try { + if (process.platform === 'darwin') { + return execSync( + 'osascript -e \'tell application "System Events" to get value of attribute "AXSelectedText" of focused UI element of first application process whose frontmost is true\'' + ).toString().trim(); + } + // Windows: no reliable accessibility API for selected text across apps + } catch { + return ''; + } + return ''; +} + +export function simulateCopy(): void { + if (process.platform === 'darwin') { + execSync('osascript -e \'tell application "System Events" to keystroke "c" using command down\''); + } else if (process.platform === 'win32') { + execSync('powershell -command "Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SendKeys]::SendWait(\'^c\')"'); + } +} + export function simulatePaste(): void { if (process.platform === 'darwin') { execSync('osascript -e \'tell application "System Events" to keystroke "v" using command down\''); diff --git a/surfsense_desktop/src/modules/quick-ask.ts b/surfsense_desktop/src/modules/quick-ask.ts index b3aa10e3a..4aa930d4f 100644 --- a/surfsense_desktop/src/modules/quick-ask.ts +++ b/surfsense_desktop/src/modules/quick-ask.ts @@ -1,7 +1,7 @@ import { BrowserWindow, clipboard, globalShortcut, ipcMain, screen, shell } from 'electron'; import path from 'path'; import { IPC_CHANNELS } from '../ipc/channels'; -import { checkAccessibilityPermission, getFrontmostApp, simulatePaste } from './keyboard'; +import { checkAccessibilityPermission, getFrontmostApp, simulatePaste } from './platform'; import { getServerPort } from './server'; const SHORTCUT = 'CommandOrControl+Option+S';