diff --git a/src/api-wrappers/AXUIElement.swift b/src/api-wrappers/AXUIElement.swift index 2d7ebd51..18195fcb 100644 --- a/src/api-wrappers/AXUIElement.swift +++ b/src/api-wrappers/AXUIElement.swift @@ -145,14 +145,7 @@ extension AXUIElement { private func androidEmulator(_ runningApp: NSRunningApplication, _ title: String?) -> Bool { // android emulator small vertical menu is a "window" with empty title; we exclude it - if title != "", - // NSRunningApplication provides no way to identify the emulator; we pattern match on its KERN_PROCARGS - runningApp.bundleIdentifier == nil, - let executablePath = Sysctl.run([CTL_KERN, KERN_PROCARGS, runningApp.processIdentifier]) { - // example path: ~/Library/Android/sdk/emulator/qemu/darwin-x86_64/qemu-system-x86_64 - return executablePath.range(of: "qemu-system[^/]*$", options: .regularExpression, range: nil, locale: nil) != nil - } - return false + return title != "" && Applications.isAndroidEmulator(runningApp) } func isOnNormalLevel(_ wid: CGWindowID) -> Bool { diff --git a/src/logic/Application.swift b/src/logic/Application.swift index 3a69666e..74ded6f4 100644 --- a/src/logic/Application.swift +++ b/src/logic/Application.swift @@ -83,7 +83,6 @@ class Application: NSObject { let subrole = try $0.subrole() let role = try $0.role() let isOnNormalLevel = $0.isOnNormalLevel(wid) - debugPrint(self.runningApplication.bundleIdentifier, wid, isOnNormalLevel, title, subrole, role) if $0.isActualWindow(self.runningApplication, wid, isOnNormalLevel, title, subrole, role) { return ($0, wid, title, try $0.isFullscreen(), try $0.isMinimized(), try $0.position()) } diff --git a/src/logic/Applications.swift b/src/logic/Applications.swift index 547621ac..e55e39ab 100644 --- a/src/logic/Applications.swift +++ b/src/logic/Applications.swift @@ -102,7 +102,7 @@ class Applications { private static func isActualApplication(_ app: NSRunningApplication) -> Bool { // an app can be both activationPolicy == .accessory and XPC (e.g. com.apple.dock.etci) - return app.activationPolicy != .prohibited && isNotXpc(app) && !app.processIdentifier.isZombie() + return (app.activationPolicy != .prohibited || isAndroidEmulator(app)) && isNotXpc(app) && !app.processIdentifier.isZombie() } private static func isNotXpc(_ app: NSRunningApplication) -> Bool { @@ -111,7 +111,6 @@ class Applications { GetProcessForPID(app.processIdentifier, &psn) var info = ProcessInfoRec() GetProcessInformation(&psn, &info) - debugPrint(app.bundleIdentifier, String(info.processType)) return String(info.processType) != "XPC!" } @@ -120,4 +119,14 @@ class Applications { private static func notAltTab(_ app: NSRunningApplication) -> Bool { return app.processIdentifier != ProcessInfo.processInfo.processIdentifier } + + static func isAndroidEmulator(_ app: NSRunningApplication) -> Bool { + // NSRunningApplication provides no way to identify the emulator; we pattern match on its KERN_PROCARGS + if app.bundleIdentifier == nil, + let executablePath = Sysctl.run([CTL_KERN, KERN_PROCARGS, app.processIdentifier]) { + // example path: ~/Library/Android/sdk/emulator/qemu/darwin-x86_64/qemu-system-x86_64 + return executablePath.range(of: "qemu-system[^/]*$", options: .regularExpression, range: nil, locale: nil) != nil + } + return false + } }