diff --git a/src/logic/Application.swift b/src/logic/Application.swift index 516a1fd5..d5c4eeec 100644 --- a/src/logic/Application.swift +++ b/src/logic/Application.swift @@ -81,13 +81,6 @@ class Application: NSObject { executableURL = runningApplication.executableURL debugId = "(pid:\(pid) \(bundleIdentifier ?? bundleURL?.absoluteString ?? executableURL?.absoluteString ?? localizedName))" super.init() - BackgroundWork.screenshotsQueue.addOperation { [weak self] in - guard let self else { return } - let r = Application.appIconWithoutPadding(runningApplication.icon) - DispatchQueue.main.async { [weak self] in - self?.icon = r - } - } Logger.info { self.debugId } observeEventsIfEligible() kvObservers = [ @@ -122,6 +115,17 @@ class Application: NSObject { } } + func fetchAppIcon() { + guard icon == nil else { return } + BackgroundWork.screenshotsQueue.addOperation { [weak self] in + guard let self, self.icon == nil else { return } + let r = Application.appIconWithoutPadding(runningApplication.icon) + DispatchQueue.main.async { [weak self] in + self?.icon = r + } + } + } + private func observeEvents() { guard let axObserver else { return } AXUIElement.retryAxCallUntilTimeout(context: debugId, pid: pid, callType: .subscribeToAppNotification) { [weak self] in diff --git a/src/logic/Window.swift b/src/logic/Window.swift index f6868f8a..da98f482 100644 --- a/src/logic/Window.swift +++ b/src/logic/Window.swift @@ -55,6 +55,8 @@ class Window { // the app may have timed out trying to subscribe to app notifications // It may be responsive now since it has a window; we attempt again application.observeEventsIfEligible() + // fetch app icon only if we display that app in the switcher + application.fetchAppIcon() checkIfFocused() Logger.info { self.debugId } observeEvents() @@ -67,6 +69,8 @@ class Window { Window.globalCreationCounter += 1 creationOrder = Window.globalCreationCounter debugId = "\(application.debugId) (title:\(title))" + // fetch app icon only if we display that app in the switcher + application.fetchAppIcon() Logger.debug { self.debugId } }