Automatically dismiss (now) empty windows
This commit is contained in:
committed by
Stefan Ceriu
parent
12b6b7ec74
commit
c66e737ee0
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user