From 51a88382d1655204f23ec1ba6400bb5c824f231a Mon Sep 17 00:00:00 2001 From: Louis Pontoise Date: Fri, 6 Mar 2020 11:17:58 +0900 Subject: [PATCH] fix: list temporary AXDialog windows like activity monitor --- src/api-wrappers/AXUIElement.swift | 3 ++- src/logic/Application.swift | 12 +++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/api-wrappers/AXUIElement.swift b/src/api-wrappers/AXUIElement.swift index 81855ff3..9a98d1f8 100644 --- a/src/api-wrappers/AXUIElement.swift +++ b/src/api-wrappers/AXUIElement.swift @@ -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 { diff --git a/src/logic/Application.swift b/src/logic/Application.swift index 6a645e96..d2d5d9b1 100644 --- a/src/logic/Application.swift +++ b/src/logic/Application.swift @@ -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()