mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-04 22:02:16 +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 { BrowserWindow, clipboard, globalShortcut, ipcMain, screen, shell } from 'electron';
|
||||||
|
import { execSync } from 'child_process';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { IPC_CHANNELS } from '../ipc/channels';
|
import { IPC_CHANNELS } from '../ipc/channels';
|
||||||
import { getServerPort } from './server';
|
import { getServerPort } from './server';
|
||||||
|
|
@ -6,6 +7,18 @@ import { getServerPort } from './server';
|
||||||
const SHORTCUT = 'CommandOrControl+Option+S';
|
const SHORTCUT = 'CommandOrControl+Option+S';
|
||||||
let quickAskWindow: BrowserWindow | null = null;
|
let quickAskWindow: BrowserWindow | null = null;
|
||||||
let pendingText = '';
|
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 {
|
function hideQuickAsk(): void {
|
||||||
if (quickAskWindow && !quickAskWindow.isDestroyed()) {
|
if (quickAskWindow && !quickAskWindow.isDestroyed()) {
|
||||||
|
|
@ -83,6 +96,8 @@ export function registerQuickAsk(): void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sourceApp = getFrontmostApp();
|
||||||
|
|
||||||
const text = clipboard.readText().trim();
|
const text = clipboard.readText().trim();
|
||||||
if (!text) return;
|
if (!text) return;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue