Skip to content

Commit

Permalink
fix: list temporary AXDialog windows like activity monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Mar 10, 2020
1 parent 946d812 commit 51a8838
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/api-wrappers/AXUIElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ extension AXUIElement {
// Some non-windows have subrole: nil (e.g. some OS elements), "AXUnknown" (e.g. Bartender), "AXSystemDialog" (e.g. Intellij tooltips)
// Some non-windows have title: nil (e.g. some OS elements)
// Minimized windows or windows of a hidden app have subrole "AXDialog"
return title() != nil && (subrole() == "AXStandardWindow" || isMinimized() || isAppHidden) && isOnNormalLevel()
// Activity Monitor main window subrole is "AXDialog" for a brief moment at launch; it then becomes "AXStandardWindow"
return title() != nil && (["AXStandardWindow", "AXDialog"].contains(subrole()) || isMinimized() || isAppHidden) && isOnNormalLevel()
}

func isOnNormalLevel() -> Bool {
Expand Down
12 changes: 3 additions & 9 deletions src/logic/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,12 @@ class Application: NSObject {
}

func observeNewWindows() {
var newWindows = [AXUIElement]()
for window in getActualWindows() {
guard Windows.list.firstIndexThatMatches(window) == nil else { continue }
newWindows.append(window)
}
let newWindows = axUiElement!.windows()?
.filter { $0.isActualWindow(runningApplication.isHidden) }
.filter { Windows.list.firstIndexThatMatches($0) == nil } ?? []
addWindows(newWindows)
}

private func getActualWindows() -> [AXUIElement] {
return axUiElement!.windows()?.filter { $0.isActualWindow(runningApplication.isHidden) } ?? []
}

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
guard let isFinishedLaunching = change![.newKey], isFinishedLaunching as! Bool else { return }
removeObserver()
Expand Down

0 comments on commit 51a8838

Please sign in to comment.