mirror of
https://github.com/lwouis/alt-tab-macos.git
synced 2026-05-24 11:20:36 +00:00
feat: reduce memory usage by storing fewer app icons
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user