mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-03 21:02:40 +02:00
30 lines
728 B
TypeScript
30 lines
728 B
TypeScript
|
|
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);
|
||
|
|
}
|