feat: add autocomplete module with keystroke monitoring and IPC wiring

This commit is contained in:
CREDO23 2026-04-02 14:29:12 +02:00
parent eaabad38fc
commit b2706b00a1
5 changed files with 330 additions and 0 deletions

View file

@ -53,3 +53,43 @@ export function checkAccessibilityPermission(): boolean {
if (process.platform !== 'darwin') return true;
return systemPreferences.isTrustedAccessibilityClient(true);
}
export function hasAccessibilityPermission(): boolean {
if (process.platform !== 'darwin') return true;
return systemPreferences.isTrustedAccessibilityClient(false);
}
export interface FieldContent {
text: string;
cursorPosition: number;
}
export function getFieldContent(): FieldContent | null {
if (process.platform !== 'darwin') return null;
try {
const text = execSync(
'osascript -e \'tell application "System Events" to get value of attribute "AXValue" of focused UI element of first application process whose frontmost is true\'',
{ timeout: 500 }
).toString().trim();
let cursorPosition = text.length;
try {
const rangeStr = execSync(
'osascript -e \'tell application "System Events" to get value of attribute "AXSelectedTextRange" of focused UI element of first application process whose frontmost is true\'',
{ timeout: 500 }
).toString().trim();
const locationMatch = rangeStr.match(/location[:\s]*(\d+)/i);
if (locationMatch) {
cursorPosition = parseInt(locationMatch[1], 10);
}
} catch {
// Fall back to end of text
}
return { text, cursorPosition };
} catch {
return null;
}
}