diff --git a/surfsense_desktop/src/ipc/channels.ts b/surfsense_desktop/src/ipc/channels.ts index 8ae21cfcf..18002b520 100644 --- a/surfsense_desktop/src/ipc/channels.ts +++ b/surfsense_desktop/src/ipc/channels.ts @@ -2,4 +2,5 @@ export const IPC_CHANNELS = { OPEN_EXTERNAL: 'open-external', GET_APP_VERSION: 'get-app-version', DEEP_LINK: 'deep-link', + QUICK_ASK_TEXT: 'quick-ask-text', } as const; diff --git a/surfsense_desktop/src/modules/quick-ask.ts b/surfsense_desktop/src/modules/quick-ask.ts new file mode 100644 index 000000000..e38b0d693 --- /dev/null +++ b/surfsense_desktop/src/modules/quick-ask.ts @@ -0,0 +1,29 @@ +import { clipboard, globalShortcut } from 'electron'; +import { IPC_CHANNELS } from '../ipc/channels'; +import { getMainWindow } from './window'; + +const SHORTCUT = 'CommandOrControl+Option+S'; + +export function registerQuickAsk(): void { + const ok = globalShortcut.register(SHORTCUT, () => { + const win = getMainWindow(); + if (!win) return; + + const text = clipboard.readText().trim(); + if (!text) return; + + if (win.isMinimized()) win.restore(); + win.show(); + win.focus(); + + win.webContents.send(IPC_CHANNELS.QUICK_ASK_TEXT, text); + }); + + if (!ok) { + console.log(`Quick-ask: failed to register ${SHORTCUT}`); + } +} + +export function unregisterQuickAsk(): void { + globalShortcut.unregister(SHORTCUT); +}