Introduce support for multiple windows on mac and iPad OS

Once the app starts the WindowManager is configured with SwiftUI's environment OpenWindowAction. It can then be used to register coordinators (that provide the toPresentable view) and an optional flow coordinator (as most of the screens are part of a flow, especially rooms).
Once a coordinator is registed, the WindowManager invokes the OpenWindowAction which in turn makes the Application call its newly introduced WindowManagerWindowType WindowGroup's block to instantiate a new visual window rooting that view.

The WindowManager is also responsible for wrapping the presentable in a disappearance block and clean up the coordinator stack.

# Conflicts:
#	ElementX/Sources/Application/AppCoordinator.swift
This commit is contained in:
Stefan Ceriu
2026-03-26 20:28:50 +02:00
committed by Stefan Ceriu
parent 91a10f4d51
commit f1ef968975
16 changed files with 231 additions and 63 deletions
@@ -18,6 +18,8 @@ class WindowManager: SecureWindowManagerProtocol {
private(set) var overlayWindow: UIWindow!
private(set) var globalSearchWindow: UIWindow!
private(set) var alternateWindow: UIWindow!
private(set) var openWindowAction: OpenWindowAction!
var windows: [UIWindow] {
[mainWindow, overlayWindow, globalSearchWindow, alternateWindow]
@@ -29,6 +31,8 @@ class WindowManager: SecureWindowManagerProtocol {
/// A duration that allows window switching to wait a couple of frames to avoid a transition through black.
private let windowHideDelay = Duration.milliseconds(33)
private var coordinators: [WindowManagerWindowType: (coordinator: CoordinatorProtocol, flowCoordinator: FlowCoordinatorProtocol?)] = [:]
init(appDelegate: AppDelegate) {
self.appDelegate = appDelegate
}
@@ -54,6 +58,29 @@ class WindowManager: SecureWindowManagerProtocol {
delegate?.windowManagerDidConfigureWindows(self)
}
func configure(with openWindowAction: OpenWindowAction) {
self.openWindowAction = openWindowAction
}
func registerCoordinator(_ coordinator: CoordinatorProtocol, flowCoordinator: FlowCoordinatorProtocol?, forWindowType type: WindowManagerWindowType) {
coordinators[type] = (coordinator, flowCoordinator)
openWindowAction(value: type)
}
func windowForType(_ type: WindowManagerWindowType) -> AnyView? {
guard let coordinator = coordinators[type]?.coordinator else {
return nil
}
return coordinator.toPresentable()
}
func handleRoute(_ appRoute: AppRoute, windowType: WindowManagerWindowType) {
if let flowCoordinator = coordinators[windowType]?.flowCoordinator {
flowCoordinator.handleAppRoute(appRoute, animated: true)
}
}
func switchToMain() {
mainWindow.isHidden = false
overlayWindow.isHidden = false