fix: crash when windows changed between the CG and the AX calls

This commit is contained in:
Louis Pontoise committed 2019-09-16 19:55:27 +09:00
1 parent 6f613547c4
commit 2fa140f027
1 file changed
+6 -3
+6 -3
View File
@@ -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))
}
}
}