From 165733c8e3b10a30d0782e314d0d2caed6779493 Mon Sep 17 00:00:00 2001 From: John Lindquist Date: Wed, 20 Nov 2024 12:36:15 -0700 Subject: [PATCH] fix(prompt): attemptSelfFocus --- src/lib/desktop.ts | 16 ++++++++++++++++ src/types/platform.d.ts | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/src/lib/desktop.ts b/src/lib/desktop.ts index 41dd58c3..a89c94e8 100644 --- a/src/lib/desktop.ts +++ b/src/lib/desktop.ts @@ -330,6 +330,22 @@ global.getMousePosition = async () => global.getProcesses = async () => (await global.getDataFromApp(Channel.GET_PROCESSES)) .processes + + +global.attemptScriptFocus = async (): Promise => { + const prompts = await getPrompts() + const scriptName = global.path.basename(global.kitScript) + + for (const prompt of prompts) { + if (prompt.isVisible && prompt.name === scriptName) { + await prompt.focus() + return true + } + } + + return false +} + global.getPrompts = async () => { let { prompts } = await global.getDataFromApp( Channel.GET_PROMPTS diff --git a/src/types/platform.d.ts b/src/types/platform.d.ts index 9cabb504..6bde7ba7 100644 --- a/src/types/platform.d.ts +++ b/src/types/platform.d.ts @@ -205,9 +205,12 @@ export interface Prompt { isDestroyed: boolean bounds: Rectangle focus: () => Promise + scriptPath: string + name: string } type GetPrompts = () => Promise +type AttemptScriptFocus = () => Promise interface KitWindow { name: string id: string @@ -355,6 +358,7 @@ declare global { var getMousePosition: GetMousePosition var getProcesses: GetProcesses var getPrompts: GetPrompts + var attemptScriptFocus: AttemptScriptFocus var getKitWindows: GetKitWindows var focusKitWindow: FocusAppWindow var getScreens: GetScreens