From c66e737ee08b0ec7f1f1753fa63bb24cbffc6483 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Fri, 27 Mar 2026 13:12:49 +0200 Subject: [PATCH] Automatically dismiss (now) empty windows --- .../Application/Windowing/WindowManager.swift | 17 +++++++++++++++-- .../Windowing/WindowManagerProtocol.swift | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ElementX/Sources/Application/Windowing/WindowManager.swift b/ElementX/Sources/Application/Windowing/WindowManager.swift index 33f0534f7..ce7208038 100644 --- a/ElementX/Sources/Application/Windowing/WindowManager.swift +++ b/ElementX/Sources/Application/Windowing/WindowManager.swift @@ -67,9 +67,9 @@ class WindowManager: SecureWindowManagerProtocol { openWindowAction(value: type) } - func windowForType(_ type: WindowManagerWindowType) -> AnyView? { + func windowForType(_ type: WindowManagerWindowType) -> AnyView { guard let coordinator = coordinators[type]?.coordinator else { - return nil + return AnyView(InstantlyDismissingWindow()) } return coordinator.toPresentable() @@ -179,3 +179,16 @@ private class PassthroughWindow: UIWindow { } } } + +/// Whenever restoring an app SwiftUI tries to restore its windows as well +/// which we're generally not prepared for so use this to just close them instead +private struct InstantlyDismissingWindow: View { + @Environment(\.dismissWindow) var dismissWindow + + var body: some View { + Rectangle() + .task { + dismissWindow() + } + } +} diff --git a/ElementX/Sources/Application/Windowing/WindowManagerProtocol.swift b/ElementX/Sources/Application/Windowing/WindowManagerProtocol.swift index d53366b48..2d3b8715d 100644 --- a/ElementX/Sources/Application/Windowing/WindowManagerProtocol.swift +++ b/ElementX/Sources/Application/Windowing/WindowManagerProtocol.swift @@ -29,7 +29,7 @@ protocol SecureWindowManagerProtocol: WindowManagerProtocol { func handleRoute(_ appRoute: AppRoute, windowType: WindowManagerWindowType) - func windowForType(_ type: WindowManagerWindowType) -> AnyView? + func windowForType(_ type: WindowManagerWindowType) -> AnyView /// Shows the main and overlay window combo, hiding the alternate window. func switchToMain()