mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-27 09:46:25 +02:00
track frontmost app on shortcut trigger
This commit is contained in:
parent
6619f9598c
commit
0f846cd9c4
1 changed files with 15 additions and 0 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue