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()