mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-27 09:46:25 +02:00
add quick-ask IPC channel and shortcut module
This commit is contained in:
parent
59e7f8f068
commit
801c07291e
2 changed files with 30 additions and 0 deletions
29
surfsense_desktop/src/modules/quick-ask.ts
Normal file
29
surfsense_desktop/src/modules/quick-ask.ts
Normal file
|
|
@ -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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue