feat: reduce memory usage by storing fewer app icons

This commit is contained in:
lwouis
2026-03-13 10:22:04 +01:00
parent cf8a41528d
commit b21168a033
2 changed files with 15 additions and 7 deletions
+11 -7
View File
@@ -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
+4
View File
@@ -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 }
}