From 3b858a4073e953cf4bc7b4ea04900134105b8246 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Mon, 30 Mar 2026 15:35:21 +0300 Subject: [PATCH] Disable multiple windows when screen lock is enabled. --- ElementX/Sources/Application/AppCoordinator.swift | 6 ++++++ .../Application/Windowing/WindowManager.swift | 13 +++++++++++++ .../Windowing/WindowManagerProtocol.swift | 2 ++ .../Sources/Mocks/Generated/GeneratedMocks.swift | 5 +++++ 4 files changed, 26 insertions(+) diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index 078b36913..3d3980777 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -188,6 +188,12 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg } } .store(in: &cancellables) + + windowManager.auxiliaryWindowsEnabled = !appLockService.isEnabled + appLockService.isEnabledPublisher.sink { [weak windowManager] appLockEnabled in + windowManager?.auxiliaryWindowsEnabled = !appLockEnabled + } + .store(in: &cancellables) } func start() { diff --git a/ElementX/Sources/Application/Windowing/WindowManager.swift b/ElementX/Sources/Application/Windowing/WindowManager.swift index 0154ced18..c5f79b019 100644 --- a/ElementX/Sources/Application/Windowing/WindowManager.swift +++ b/ElementX/Sources/Application/Windowing/WindowManager.swift @@ -22,6 +22,14 @@ class WindowManager: SecureWindowManagerProtocol { private(set) var openWindowAction: OpenWindowAction! private(set) var dismissWindowAction: DismissWindowAction! + + var auxiliaryWindowsEnabled = true { + didSet { + if auxiliaryWindowsEnabled == false { + closeAllAuxiliaryWindows() + } + } + } var windows: [UIWindow] { [mainWindow, overlayWindow, globalSearchWindow, alternateWindow] @@ -167,6 +175,11 @@ class WindowManager: SecureWindowManagerProtocol { } func registerCoordinator(_ coordinator: CoordinatorProtocol, flowCoordinator: FlowCoordinatorProtocol?, forWindowType type: WindowManagerWindowType) { + if auxiliaryWindowsEnabled == false { + MXLog.error("Cannot register coordinator, auxiliary windows are disabled.") + return + } + coordinators[type] = (coordinator, flowCoordinator) openWindowAction(value: type) } diff --git a/ElementX/Sources/Application/Windowing/WindowManagerProtocol.swift b/ElementX/Sources/Application/Windowing/WindowManagerProtocol.swift index 85aa37e7b..41bcc49f3 100644 --- a/ElementX/Sources/Application/Windowing/WindowManagerProtocol.swift +++ b/ElementX/Sources/Application/Windowing/WindowManagerProtocol.swift @@ -64,6 +64,8 @@ protocol WindowManagerProtocol: AnyObject, OrientationManagerProtocol { // MARK: - Auxiliary window support + var auxiliaryWindowsEnabled: Bool { get set } + /// Register a coordinator and it's respective flow (if any) within the WindowManager which in turn /// invokes the Application's `OpenWindowAction` func registerCoordinator(_ coordinator: CoordinatorProtocol, diff --git a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift index dd4f4d8ad..fdff6a40a 100644 --- a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift @@ -21357,6 +21357,11 @@ class WindowManagerMock: WindowManagerProtocol, @unchecked Sendable { var globalSearchWindow: UIWindow! var alternateWindow: UIWindow! var windows: [UIWindow] = [] + var auxiliaryWindowsEnabled: Bool { + get { return underlyingAuxiliaryWindowsEnabled } + set(value) { underlyingAuxiliaryWindowsEnabled = value } + } + var underlyingAuxiliaryWindowsEnabled: Bool! //MARK: - showGlobalSearch