fix: don't trigger ui refreshes if the app is not active
This commit is contained in:
1 parent
b03b0aa22e
commit
b9a0152f85
3 files changed
+11
-8
No files matched your search
@@ -66,11 +66,12 @@ class Application: NSObject {
|
||||
|
||||
func axObserverApplicationCallback(observer: AXObserver, element: AXUIElement, notificationName: CFString, applicationPointer: UnsafeMutableRawPointer?) -> Void {
|
||||
let application = Unmanaged<Application>.fromOpaque(applicationPointer!).takeUnretainedValue()
|
||||
let app = App.shared as! App
|
||||
let type = notificationName as String
|
||||
debugPrint("OS event: " + type, element.title())
|
||||
switch type {
|
||||
case kAXApplicationActivatedNotification:
|
||||
guard !(App.shared as! App).appIsBeingUsed,
|
||||
guard !app.appIsBeingUsed,
|
||||
let appFocusedWindow = element.focusedWindow(),
|
||||
let existingIndex = Windows.listRecentlyUsedFirst.firstIndexThatMatches(appFocusedWindow) else { return }
|
||||
Windows.listRecentlyUsedFirst.insert(Windows.listRecentlyUsedFirst.remove(at: existingIndex), at: 0)
|
||||
@@ -79,7 +80,7 @@ func axObserverApplicationCallback(observer: AXObserver, element: AXUIElement, n
|
||||
guard window.application.axUiElement!.pid() == element.pid() else { continue }
|
||||
window.isHidden = type == kAXApplicationHiddenNotification
|
||||
}
|
||||
(App.shared as! App).refreshOpenUi()
|
||||
app.refreshOpenUi()
|
||||
case kAXWindowCreatedNotification:
|
||||
guard element.isActualWindow() else { return }
|
||||
// a window being un-minimized can trigger kAXWindowCreatedNotification
|
||||
@@ -89,9 +90,9 @@ func axObserverApplicationCallback(observer: AXObserver, element: AXUIElement, n
|
||||
Windows.moveFocusedWindowIndexAfterWindowCreatedInBackground()
|
||||
// TODO: find a better way to get thumbnail of the new window
|
||||
window.refreshThumbnail()
|
||||
(App.shared as! App).refreshOpenUi()
|
||||
app.refreshOpenUi()
|
||||
case kAXFocusedWindowChangedNotification:
|
||||
guard !(App.shared as! App).appIsBeingUsed,
|
||||
guard !app.appIsBeingUsed,
|
||||
element.isActualWindow(),
|
||||
let existingIndex = Windows.listRecentlyUsedFirst.firstIndexThatMatches(element) else { return }
|
||||
Windows.listRecentlyUsedFirst.insert(Windows.listRecentlyUsedFirst.remove(at: existingIndex), at: 0)
|
||||
|
||||
@@ -100,27 +100,28 @@ class Window {
|
||||
|
||||
func axObserverWindowCallback(observer: AXObserver, element: AXUIElement, notificationName: CFString, _: UnsafeMutableRawPointer?) -> Void {
|
||||
let type = notificationName as String
|
||||
let app = App.shared as! App
|
||||
debugPrint("OS event: " + type, element.title())
|
||||
switch type {
|
||||
case kAXUIElementDestroyedNotification:
|
||||
guard let existingIndex = Windows.listRecentlyUsedFirst.firstIndexThatMatches(element) else { return }
|
||||
Windows.listRecentlyUsedFirst.remove(at: existingIndex)
|
||||
guard Windows.listRecentlyUsedFirst.count > 0 else { (App.shared as! App).hideUi(); return }
|
||||
guard Windows.listRecentlyUsedFirst.count > 0 else { app.hideUi(); return }
|
||||
Windows.moveFocusedWindowIndexAfterWindowDestroyedInBackground(existingIndex)
|
||||
(App.shared as! App).refreshOpenUi()
|
||||
app.refreshOpenUi()
|
||||
case kAXWindowMiniaturizedNotification, kAXWindowDeminiaturizedNotification:
|
||||
guard let window = Windows.listRecentlyUsedFirst.firstWindowThatMatches(element) else { return }
|
||||
window.isMinimized = type == kAXWindowMiniaturizedNotification
|
||||
// TODO: find a better way to get thumbnail of the new window (when AltTab is triggered min/demin animation)
|
||||
window.refreshThumbnail()
|
||||
(App.shared as! App).refreshOpenUi()
|
||||
app.refreshOpenUi()
|
||||
case kAXTitleChangedNotification:
|
||||
guard element.isActualWindow(),
|
||||
let window = Windows.listRecentlyUsedFirst.firstWindowThatMatches(element),
|
||||
let newTitle = window.axUiElement.title(),
|
||||
newTitle != window.title else { return }
|
||||
window.title = newTitle
|
||||
(App.shared as! App).refreshOpenUi()
|
||||
app.refreshOpenUi()
|
||||
default: return
|
||||
}
|
||||
}
|
||||
@@ -104,6 +104,7 @@ class App: NSApplication, NSApplicationDelegate, NSWindowDelegate {
|
||||
}
|
||||
|
||||
func refreshOpenUi() {
|
||||
guard appIsBeingUsed else { return }
|
||||
let currentScreen = Screen.preferred() // fix screen between steps since it could change (e.g. mouse moved to another screen)
|
||||
if uiWorkShouldBeDone { thumbnailsPanel!.refreshCollectionView(currentScreen); debugPrint("refreshCollectionView") }
|
||||
if uiWorkShouldBeDone { thumbnailsPanel!.highlightCell(); debugPrint("highlightCellAt") }
|
||||
|
||||
Reference in new issue
Block a user