Skip to content

Commit

Permalink
fix(prompt): attemptSelfFocus
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlindquist committed Nov 20, 2024
1 parent cc7bb61 commit 165733c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/lib/desktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,22 @@ global.getMousePosition = async () =>
global.getProcesses = async () =>
(await global.getDataFromApp(Channel.GET_PROCESSES))
.processes


global.attemptScriptFocus = async (): Promise<boolean> => {
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
Expand Down
4 changes: 4 additions & 0 deletions src/types/platform.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,12 @@ export interface Prompt {
isDestroyed: boolean
bounds: Rectangle
focus: () => Promise<void>
scriptPath: string
name: string
}

type GetPrompts = () => Promise<Prompt[]>
type AttemptScriptFocus = () => Promise<boolean>
interface KitWindow {
name: string
id: string
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 165733c

Please sign in to comment.