diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index e1f39bdb4..078b36913 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -793,6 +793,8 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg fatalError("User session not setup") } + windowManager.closeAllAuxiliaryWindows() + showLoadingIndicator() stopSync(isBackgroundTask: false) diff --git a/ElementX/Sources/Application/Application.swift b/ElementX/Sources/Application/Application.swift index 728713ff0..12f063343 100644 --- a/ElementX/Sources/Application/Application.swift +++ b/ElementX/Sources/Application/Application.swift @@ -13,6 +13,7 @@ struct Application: App { @UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate @Environment(\.openURL) private var openURL @Environment(\.openWindow) private var openWindow + @Environment(\.dismissWindow) private var dismissWindow private var appCoordinator: AppCoordinatorProtocol! @@ -51,7 +52,8 @@ struct Application: App { } .task { appCoordinator.start() - appCoordinator.windowManager.configure(with: openWindow) + appCoordinator.windowManager.configure(withOpenWinddowAction: openWindow, + dismissWindowAction: dismissWindow) } } .handlesExternalEvents(matching: ["*"]) diff --git a/ElementX/Sources/Application/Windowing/WindowManager.swift b/ElementX/Sources/Application/Windowing/WindowManager.swift index ce7208038..0c86af921 100644 --- a/ElementX/Sources/Application/Windowing/WindowManager.swift +++ b/ElementX/Sources/Application/Windowing/WindowManager.swift @@ -20,6 +20,7 @@ class WindowManager: SecureWindowManagerProtocol { private(set) var alternateWindow: UIWindow! private(set) var openWindowAction: OpenWindowAction! + private(set) var dismissWindowAction: DismissWindowAction! var windows: [UIWindow] { [mainWindow, overlayWindow, globalSearchWindow, alternateWindow] @@ -58,8 +59,10 @@ class WindowManager: SecureWindowManagerProtocol { delegate?.windowManagerDidConfigureWindows(self) } - func configure(with openWindowAction: OpenWindowAction) { + func configure(withOpenWinddowAction openWindowAction: OpenWindowAction, + dismissWindowAction: DismissWindowAction) { self.openWindowAction = openWindowAction + self.dismissWindowAction = dismissWindowAction } func registerCoordinator(_ coordinator: CoordinatorProtocol, flowCoordinator: FlowCoordinatorProtocol?, forWindowType type: WindowManagerWindowType) { @@ -67,6 +70,14 @@ class WindowManager: SecureWindowManagerProtocol { openWindowAction(value: type) } + func closeAllAuxiliaryWindows() { + for key in coordinators.keys { + dismissWindowAction(value: key) + } + + coordinators.removeAll() + } + func windowForType(_ type: WindowManagerWindowType) -> AnyView { guard let coordinator = coordinators[type]?.coordinator else { return AnyView(InstantlyDismissingWindow()) diff --git a/ElementX/Sources/Application/Windowing/WindowManagerProtocol.swift b/ElementX/Sources/Application/Windowing/WindowManagerProtocol.swift index 2d3b8715d..b486c83af 100644 --- a/ElementX/Sources/Application/Windowing/WindowManagerProtocol.swift +++ b/ElementX/Sources/Application/Windowing/WindowManagerProtocol.swift @@ -25,7 +25,7 @@ protocol SecureWindowManagerProtocol: WindowManagerProtocol { /// Configures the window manager to operate on the supplied scene. func configure(with windowScene: UIWindowScene) - func configure(with openWindowAction: OpenWindowAction) + func configure(withOpenWinddowAction openWindowAction: OpenWindowAction, dismissWindowAction: DismissWindowAction) func handleRoute(_ appRoute: AppRoute, windowType: WindowManagerWindowType) @@ -56,6 +56,8 @@ protocol WindowManagerProtocol: AnyObject, OrientationManagerProtocol { func registerCoordinator(_ coordinator: CoordinatorProtocol, flowCoordinator: FlowCoordinatorProtocol?, forWindowType type: WindowManagerWindowType) + func closeAllAuxiliaryWindows() + /// Makes the global search window key. Used to get automatic text field focus. func showGlobalSearch() diff --git a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift index 7e96005fd..2dff16643 100644 --- a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift @@ -21399,6 +21399,41 @@ class WindowManagerMock: WindowManagerProtocol, @unchecked Sendable { } registerCoordinatorFlowCoordinatorForWindowTypeClosure?(coordinator, flowCoordinator, type) } + //MARK: - closeAllAuxiliaryWindows + + var closeAllAuxiliaryWindowsUnderlyingCallsCount = 0 + var closeAllAuxiliaryWindowsCallsCount: Int { + get { + if Thread.isMainThread { + return closeAllAuxiliaryWindowsUnderlyingCallsCount + } else { + var returnValue: Int? = nil + DispatchQueue.main.sync { + returnValue = closeAllAuxiliaryWindowsUnderlyingCallsCount + } + + return returnValue! + } + } + set { + if Thread.isMainThread { + closeAllAuxiliaryWindowsUnderlyingCallsCount = newValue + } else { + DispatchQueue.main.sync { + closeAllAuxiliaryWindowsUnderlyingCallsCount = newValue + } + } + } + } + var closeAllAuxiliaryWindowsCalled: Bool { + return closeAllAuxiliaryWindowsCallsCount > 0 + } + var closeAllAuxiliaryWindowsClosure: (() -> Void)? + + func closeAllAuxiliaryWindows() { + closeAllAuxiliaryWindowsCallsCount += 1 + closeAllAuxiliaryWindowsClosure?() + } //MARK: - showGlobalSearch var showGlobalSearchUnderlyingCallsCount = 0