Skip to content

Commit

Permalink
fix(deps): move mac-windows to optional
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlindquist committed Sep 13, 2024
1 parent 8ffe26a commit b7d8c85
Showing 1 changed file with 67 additions and 62 deletions.
129 changes: 67 additions & 62 deletions src/main/focus-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,69 +7,74 @@ import "@johnlindquist/kit"
import { escapeShortcut } from "../core/utils.js"
import type { Choice } from "../types/core.js"

type MacWindows = {
getWindows: (options: {
showAllWindows: boolean
onScreenOnly: boolean
}) => Promise<
{
name: string
ownerName: string
number: number
pid: number
}[]
>
}
let { getWindows } = (await import("mac-windows")) as MacWindows
let isMac = process.platform === "darwin"

if (isMac) {
type MacWindows = {
getWindows: (options: {
showAllWindows: boolean
onScreenOnly: boolean
}) => Promise<
{
name: string
ownerName: string
number: number
pid: number
}[]
>
}
let importKey = isMac ? "mac-windows" : ""
let { getWindows } = (await import(importKey)) as MacWindows

let apps = await db<{ choices: Choice[] }>(kitPath("db", "apps.json"))
let apps = await db<{ choices: Choice[] }>(kitPath("db", "apps.json"))

let windows = await getWindows({
showAllWindows: true,
onScreenOnly: false
})
let windows = await getWindows({
showAllWindows: true,
onScreenOnly: false
})

let ignore = [
"Notification Center",
"Dock",
"AvatarPickerMemojiPicker",
"com.apple.preference.security.r"
]
let ignore = [
"Notification Center",
"Dock",
"AvatarPickerMemojiPicker",
"com.apple.preference.security.r"
]

let selectedWindow = await arg<{
name: string
ownerName: string
number: number
pid: number
}>(
{
placeholder: "Focus Window",
enter: "Focus",
shortcuts: [escapeShortcut],
resize: true,
searchKeys: [
"slicedName",
"friendlyShortcut",
"tag",
"group",
"command",
"description"
]
},
windows
.filter((w) => !ignore.includes(w.ownerName) && w.name !== "")
.map((w) => {
let img =
(apps?.choices?.length ? apps.choices : []).find(
(a) => a.name == w.ownerName || a.name.includes(w.ownerName)
)?.img || ""
return {
name: w.ownerName,
description: w.name,
img,
value: w
}
})
)
await hide()
await focusWindow(selectedWindow.ownerName, selectedWindow.name)
let selectedWindow = await arg<{
name: string
ownerName: string
number: number
pid: number
}>(
{
placeholder: "Focus Window",
enter: "Focus",
shortcuts: [escapeShortcut],
resize: true,
searchKeys: [
"slicedName",
"friendlyShortcut",
"tag",
"group",
"command",
"description"
]
},
windows
.filter((w) => !ignore.includes(w.ownerName) && w.name !== "")
.map((w) => {
let img =
(apps?.choices?.length ? apps.choices : []).find(
(a) => a.name == w.ownerName || a.name.includes(w.ownerName)
)?.img || ""
return {
name: w.ownerName,
description: w.name,
img,
value: w
}
})
)
await hide()
await focusWindow(selectedWindow.ownerName, selectedWindow.name)
}

0 comments on commit b7d8c85

Please sign in to comment.