diff --git a/src/logic/Application.swift b/src/logic/Application.swift index ad043c78..2a135162 100644 --- a/src/logic/Application.swift +++ b/src/logic/Application.swift @@ -63,7 +63,7 @@ class Application: NSObject { let windows = axWindows.map { Window($0, self) } Windows.list.insertAndScaleRecycledPool(windows, at: 0) windows.forEach { _ in Windows.moveFocusedWindowIndexAfterWindowCreatedInBackground() } - (App.shared as! App).refreshOpenUi() + (App.shared as! App).refreshOpenUi(windows) } private func observeEvents() { @@ -104,15 +104,13 @@ private func eventApplicationActivated(_ app: App, _ element: AXUIElement) { let appFocusedWindow = element.focusedWindow(), let existingIndex = Windows.list.firstIndexThatMatches(appFocusedWindow) else { return } Windows.list.insert(Windows.list.remove(at: existingIndex), at: 0) - app.refreshOpenUi() + app.refreshOpenUi([Windows.list[0]]) } private func eventApplicationHiddenOrShown(_ app: App, _ element: AXUIElement, _ type: String) { - for window in Windows.list { - guard window.application.axUiElement! == element else { continue } - window.isHidden = type == kAXApplicationHiddenNotification - } - app.refreshOpenUi() + let windows = Windows.list.filter { $0.application.axUiElement! == element } + windows.forEach { $0.isHidden = type == kAXApplicationHiddenNotification } + app.refreshOpenUi(windows) } private func eventWindowCreated(_ app: App, _ element: AXUIElement, _ application: Application) { @@ -122,12 +120,12 @@ private func eventWindowCreated(_ app: App, _ element: AXUIElement, _ applicatio let window = Window(element, application) Windows.list.insertAndScaleRecycledPool([window], at: 0) Windows.moveFocusedWindowIndexAfterWindowCreatedInBackground() - app.refreshOpenUi() + app.refreshOpenUi([window]) } private func eventFocusedWindowChanged(_ app: App, _ element: AXUIElement) { guard !app.appIsBeingUsed, let existingIndex = Windows.list.firstIndexThatMatches(element) else { return } Windows.list.insert(Windows.list.remove(at: existingIndex), at: 0) - app.refreshOpenUi() + app.refreshOpenUi([Windows.list[0]]) } \ No newline at end of file diff --git a/src/logic/Window.swift b/src/logic/Window.swift index 97380062..8d5598f1 100644 --- a/src/logic/Window.swift +++ b/src/logic/Window.swift @@ -139,7 +139,7 @@ private func eventWindowMiniaturizedOrDeminiaturized(_ app: App, _ element: AXUI guard let index = Windows.list.firstIndexThatMatches(element) else { return } let window = Windows.list[index] window.isMinimized = type == kAXWindowMiniaturizedNotification - app.refreshOpenUi() + app.refreshOpenUi([window]) } private func eventWindowTitleChanged(_ app: App, _ element: AXUIElement) { @@ -148,10 +148,11 @@ private func eventWindowTitleChanged(_ app: App, _ element: AXUIElement) { guard let newTitle = window.axUiElement.title(), newTitle != window.title else { return } window.title = newTitle - app.refreshOpenUi() + app.refreshOpenUi([window]) } private func eventWindowResized(_ app: App, _ element: AXUIElement) { guard let index = Windows.list.firstIndexThatMatches(element) else { return } - app.refreshOpenUi() + let window = Windows.list[index] + app.refreshOpenUi([window]) } diff --git a/src/ui/App.swift b/src/ui/App.swift index 87d59cc7..49bec5c1 100644 --- a/src/ui/App.swift +++ b/src/ui/App.swift @@ -110,15 +110,17 @@ class App: NSApplication, NSApplicationDelegate { } func reopenUi() { - // TODO: retest this thumbnailsPanel!.orderOut(nil) Windows.refreshAllThumbnails() refreshOpenUi() thumbnailsPanel!.show() } - func refreshOpenUi() { + func refreshOpenUi(_ windowsToRefresh: [Window]? = nil) { guard appIsBeingUsed else { return } + if let windowsToRefresh = windowsToRefresh { + windowsToRefresh.map { $0.refreshThumbnail() } + } let currentScreen = Screen.preferred() // fix screen between steps since it could change (e.g. mouse moved to another screen) guard uiWorkShouldBeDone else { return } thumbnailsPanel!.thumbnailsView.updateItems(currentScreen)