From 0f846cd9c4a2da279bc2f721cfc414dc92697809 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Thu, 26 Mar 2026 20:06:01 +0200 Subject: [PATCH] track frontmost app on shortcut trigger --- surfsense_desktop/src/modules/quick-ask.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/surfsense_desktop/src/modules/quick-ask.ts b/surfsense_desktop/src/modules/quick-ask.ts index 9009099a3..0779b514f 100644 --- a/surfsense_desktop/src/modules/quick-ask.ts +++ b/surfsense_desktop/src/modules/quick-ask.ts @@ -1,4 +1,5 @@ import { BrowserWindow, clipboard, globalShortcut, ipcMain, screen, shell } from 'electron'; +import { execSync } from 'child_process'; import path from 'path'; import { IPC_CHANNELS } from '../ipc/channels'; import { getServerPort } from './server'; @@ -6,6 +7,18 @@ import { getServerPort } from './server'; const SHORTCUT = 'CommandOrControl+Option+S'; let quickAskWindow: BrowserWindow | null = null; let pendingText = ''; +let sourceApp = ''; + +function getFrontmostApp(): string { + if (process.platform !== 'darwin') return ''; + try { + return execSync( + 'osascript -e \'tell application "System Events" to get name of first application process whose frontmost is true\'' + ).toString().trim(); + } catch { + return ''; + } +} function hideQuickAsk(): void { if (quickAskWindow && !quickAskWindow.isDestroyed()) { @@ -83,6 +96,8 @@ export function registerQuickAsk(): void { return; } + sourceApp = getFrontmostApp(); + const text = clipboard.readText().trim(); if (!text) return;