From c49a2bcd4bc81e31b77eaba8e569fc1335d19ca1 Mon Sep 17 00:00:00 2001 From: Louis Pontoise Date: Tue, 8 Sep 2020 16:40:45 +0900 Subject: [PATCH] fix: crash from appcenter in rare scenario Stack trace: closure #1 () -> () in AltTab.(windowDestroyed in _3E1A2D100A6A10BAACF80B17AC9C41B5)(__C.AXUIElementRef) throws -> () Windows.swift:43 reabstraction thunk helper from @escaping @callee_guaranteed () -> () to @escaping @callee_unowned @convention(block) () -> () :0 --- src/logic/Windows.swift | 6 +++--- src/logic/events/AccessibilityEvents.swift | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/logic/Windows.swift b/src/logic/Windows.swift index 7e5368e98..cf9f07bcf 100644 --- a/src/logic/Windows.swift +++ b/src/logic/Windows.swift @@ -94,10 +94,10 @@ class Windows { return targetIndex } - static func moveFocusedWindowIndexAfterWindowDestroyedInBackground(_ destroyedWindowIndex: Int) { - if focusedWindowIndex > destroyedWindowIndex { + static func moveFocusedWindowIndexAfterWindowDestroyedInBackground(_ window: Window) { + if focusedWindowIndex > window.lastFocusOrder { cycleFocusedWindowIndex(-1) - } else if focusedWindowIndex == destroyedWindowIndex && !focusedWindow()!.shouldShowTheUser { + } else if focusedWindowIndex == window.lastFocusOrder && !window.shouldShowTheUser { cycleFocusedWindowIndex(1) } } diff --git a/src/logic/events/AccessibilityEvents.swift b/src/logic/events/AccessibilityEvents.swift index d5d4a4aab..01fb90df2 100644 --- a/src/logic/events/AccessibilityEvents.swift +++ b/src/logic/events/AccessibilityEvents.swift @@ -151,7 +151,7 @@ private func windowDestroyed(_ element: AXUIElement) throws { Windows.removeAndUpdateFocus(window) let windowlessApp = window.application.addWindowslessAppsIfNeeded() if Windows.list.count > 0 { - Windows.moveFocusedWindowIndexAfterWindowDestroyedInBackground(window.lastFocusOrder) + Windows.moveFocusedWindowIndexAfterWindowDestroyedInBackground(window) App.app.refreshOpenUi(windowlessApp) } else { App.app.hideUi()