Skip to content

Commit

Permalink
fix: crash when windows changed between the CG and the AX calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis Pontoise committed Sep 16, 2019
1 parent 6f61354 commit 2fa140f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions alt-tab-macos/ui/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ class Application: NSApplication, NSApplicationDelegate, NSWindowDelegate, NSCol
let cgTitle = String(cgWindow[kCGWindowName] as! NSString)
let cgOwnerPid = cgWindow[kCGWindowOwnerPID] as! pid_t
let i = pidAndCurrentIndex.index(forKey: cgOwnerPid)
pidAndCurrentIndex[cgOwnerPid] = i == nil ? 0 : pidAndCurrentIndex[i!].value + 1
let axWindow = axWindows(cgOwnerPid)[pidAndCurrentIndex[cgOwnerPid]!]
openWindows.append(OpenWindow(target: axWindow, ownerPid: cgOwnerPid, cgId: cgId, cgTitle: cgTitle))
pidAndCurrentIndex[cgOwnerPid] = (i == nil ? 0 : pidAndCurrentIndex[i!].value + 1)
let axWindow = axWindows(cgOwnerPid)
// windows may have changed between the CG and the AX calls
if axWindow.count > pidAndCurrentIndex[cgOwnerPid]! {
openWindows.append(OpenWindow(target: axWindow[pidAndCurrentIndex[cgOwnerPid]!], ownerPid: cgOwnerPid, cgId: cgId, cgTitle: cgTitle))
}
}
}

Expand Down

0 comments on commit 2fa140f

Please sign in to comment.