From 7b88c46da8b00dcde023ec41f9629d19e0024902 Mon Sep 17 00:00:00 2001 From: Nikita Bobko Date: Thu, 5 Dec 2024 22:14:47 +0100 Subject: [PATCH] restoreTreeRecursive: there is no reason to continue if at least one window in the tree couldn't be restored Related: https://github.com/nikitabobko/AeroSpace/issues/771 Motivation: I am not aware of any test case that would lead to problems. The code change is purely for sanity --- .../AppBundle/tree/frozen/closedWindowsCache.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Sources/AppBundle/tree/frozen/closedWindowsCache.swift b/Sources/AppBundle/tree/frozen/closedWindowsCache.swift index 36042b80..323f0ceb 100644 --- a/Sources/AppBundle/tree/frozen/closedWindowsCache.swift +++ b/Sources/AppBundle/tree/frozen/closedWindowsCache.swift @@ -83,7 +83,8 @@ func restoreClosedWindowsCacheIfNeeded(newlyDetectedWindow: Window) -> Bool { return true } -private func restoreTreeRecursive(frozenContainer: FrozenContainer, parent: NonLeafTreeNodeObject, index: Int) { +@discardableResult +private func restoreTreeRecursive(frozenContainer: FrozenContainer, parent: NonLeafTreeNodeObject, index: Int) -> Bool { let container = TilingContainer( parent: parent, adaptiveWeight: frozenContainer.weight, @@ -92,16 +93,18 @@ private func restoreTreeRecursive(frozenContainer: FrozenContainer, parent: NonL index: index ) - loop: for (index, child) in frozenContainer.children.enumerated() { + for (index, child) in frozenContainer.children.enumerated() { switch child { case .window(let w): // Stop the loop if can't find the window, because otherwise all the subsequent windows will have incorrect index - guard let window = MacWindow.get(byId: w.id) else { break loop } + guard let window = MacWindow.get(byId: w.id) else { return false } window.bind(to: container, adaptiveWeight: w.weight, index: index) case .container(let c): - restoreTreeRecursive(frozenContainer: c, parent: container, index: index) + // There is no reason to continue + if !restoreTreeRecursive(frozenContainer: c, parent: container, index: index) { return false } } } + return true } // Consider the following case: