Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions internal/findmy/findmy.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,33 @@ func SwitchTab(name string) error {

func MainWindow() (*Window, error) {
ls := GetAppStrings()
out, err := runHelper("window", "--owner", ls.WindowOwner)
if err != nil {
return nil, fmt.Errorf("helper window: %w", err)
}
var wins []Window
if err := json.Unmarshal(out, &wins); err != nil {
return nil, fmt.Errorf("decode windows: %w", err)
}
for _, w := range wins {
if w.Layer == 0 && w.OnScreen && w.Height > 100 {
return &w, nil
for _, owner := range windowOwnerCandidates(ls.WindowOwner) {
out, err := runHelper("window", "--owner", owner)
if err != nil {
return nil, fmt.Errorf("helper window: %w", err)
}
var wins []Window
if err := json.Unmarshal(out, &wins); err != nil {
return nil, fmt.Errorf("decode windows: %w", err)
}
for _, w := range wins {
if w.Layer == 0 && w.OnScreen && w.Height > 100 {
return &w, nil
}
}
}
return nil, fmt.Errorf("no visible %s window (open the app first)", ls.WindowOwner)
}

// windowOwnerCandidates accounts for macOS builds where Spotlight reports the
// bundle name "FindMy" while CGWindowList reports the visible owner as "Find My".
func windowOwnerCandidates(owner string) []string {
if owner == "FindMy" {
return []string{"FindMy", "Find My"}
}
return []string{owner}
}

// Capture writes the FindMy window's content to dest using `screencapture -l`,
// which targets the window by ID and captures actual content rather than the
// screen rect. Region capture (`-R x,y,w,h`) would grab whatever is topmost at
Expand Down
22 changes: 22 additions & 0 deletions internal/findmy/window_owner_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package findmy

import (
"reflect"
"testing"
)

func TestWindowOwnerCandidatesAcceptsMacOSDisplayNameVariant(t *testing.T) {
got := windowOwnerCandidates("FindMy")
want := []string{"FindMy", "Find My"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("windowOwnerCandidates(FindMy) = %#v, want %#v", got, want)
}
}

func TestWindowOwnerCandidatesLeavesLocalizedNameUntouched(t *testing.T) {
got := windowOwnerCandidates("Localiser")
want := []string{"Localiser"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("windowOwnerCandidates(Localiser) = %#v, want %#v", got, want)
}
}