Automatically dismiss (now) empty windows

This commit is contained in:
Stefan Ceriu
2026-03-27 13:12:49 +02:00
committed by Stefan Ceriu
parent 12b6b7ec74
commit c66e737ee0
2 changed files with 16 additions and 3 deletions

View File

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

View File

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