fix: things in background properly reflect in ui

This commit is contained in:
Louis Pontoise authored and lwouis committed 2020-03-24 19:37:45 +09:00
1 parent 311beef3cf
commit fdf1524137
3 files changed
+15 -14

No files matched your search

+7 -9
View File
@@ -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]])
}
+4 -3
View File
@@ -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])
}
+4 -2
View File
@@ -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)