diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index 299f2a310..522dcb323 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -680,6 +680,7 @@ AD55E245FE686D7DB4C86406 /* RoomTimelineItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90F2F8998E5632668B0AD848 /* RoomTimelineItemView.swift */; }; AE1160076F663BF14E0E893A /* EffectsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4548A9BDE5CB3AB864BCA9F /* EffectsView.swift */; }; AE1A73B24D63DA3D63DC4EE3 /* SessionVerificationControllerProxyMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 248649EBA5BC33DB93698734 /* SessionVerificationControllerProxyMock.swift */; }; + AE5AAD9E32511544FDFA5560 /* WindowManagerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06F27F588F9059128E17C669 /* WindowManagerProtocol.swift */; }; AF19D65A9C60C6B2646F3210 /* RedactedRoomTimelineItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6E6BDF9D26DB05C88901416 /* RedactedRoomTimelineItem.swift */; }; AF2ABA2794E376B64104C964 /* MockSoftLogoutScreenState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5644919DB2022397D9D5825A /* MockSoftLogoutScreenState.swift */; }; AF33B9044498211C3D82F1E1 /* UNTextInputNotificationResponse+Creator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 130ED565A078F7E0B59D9D25 /* UNTextInputNotificationResponse+Creator.swift */; }; @@ -1073,6 +1074,7 @@ 05F598B1B346DAF223651C91 /* LoginScreenCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginScreenCoordinator.swift; sourceTree = ""; }; 0685156EB62D7E243F097CFC /* ServerSelectionScreenViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerSelectionScreenViewModelProtocol.swift; sourceTree = ""; }; 06B098A612DCB5A7358EECD5 /* DeveloperOptionsScreenModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeveloperOptionsScreenModels.swift; sourceTree = ""; }; + 06F27F588F9059128E17C669 /* WindowManagerProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowManagerProtocol.swift; sourceTree = ""; }; 06FAE373A7F20780BA84B59C /* MessageForwardingScreenCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageForwardingScreenCoordinator.swift; sourceTree = ""; }; 07579F9C29001E40715F3014 /* NotificationSettingsChatType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationSettingsChatType.swift; sourceTree = ""; }; 077D7C3BE199B6E5DDEC07EC /* AppCoordinatorStateMachine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppCoordinatorStateMachine.swift; sourceTree = ""; }; @@ -1160,6 +1162,7 @@ 1CC09F30B0E1010951952BDC /* SecureBackupLogoutConfirmationScreenUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureBackupLogoutConfirmationScreenUITests.swift; sourceTree = ""; }; 1CC575D1895FA62591451A93 /* RoomMemberDetailsScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoomMemberDetailsScreen.swift; sourceTree = ""; }; 1D56469A9EE0CFA2B7BA9760 /* SessionVerificationControllerProxyProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionVerificationControllerProxyProtocol.swift; sourceTree = ""; }; + 1D652E78832289CD9EB64488 /* hu */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hu; path = hu.lproj/InfoPlist.strings; sourceTree = ""; }; 1D67E616BCA82D8A1258D488 /* NetworkMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkMonitor.swift; sourceTree = ""; }; 1D8866FE1CCCF10305FCACBC /* CallScreenUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallScreenUITests.swift; sourceTree = ""; }; 1D8C38663020DF2EB2D13F5E /* AppLockSetupSettingsScreenViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppLockSetupSettingsScreenViewModel.swift; sourceTree = ""; }; @@ -1190,6 +1193,7 @@ 248649EBA5BC33DB93698734 /* SessionVerificationControllerProxyMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionVerificationControllerProxyMock.swift; sourceTree = ""; }; 24DEE0682C95F897B6C7CB0D /* ServerConfirmationScreenViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerConfirmationScreenViewModel.swift; sourceTree = ""; }; 24F5530B2212862FA4BEFF2D /* HomeScreenViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeScreenViewModelProtocol.swift; sourceTree = ""; }; + 2525D78FEA7E7B132ED85C58 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/InfoPlist.strings; sourceTree = ""; }; 259E5B05BDE6E20C26CF11B4 /* PollInteractionHandlerProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PollInteractionHandlerProtocol.swift; sourceTree = ""; }; 25F7FE40EF7490A7E09D7BE6 /* NotificationItemProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationItemProxy.swift; sourceTree = ""; }; 25F8664F1FB95AF3C4202478 /* PollFormScreenCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PollFormScreenCoordinator.swift; sourceTree = ""; }; @@ -1453,6 +1457,7 @@ 7101698791B321A76F552804 /* WelcomeScreenScreenViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeScreenScreenViewModelProtocol.swift; sourceTree = ""; }; 713B48DBF65DE4B0DD445D66 /* ReportContentScreenViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReportContentScreenViewModelProtocol.swift; sourceTree = ""; }; 71556206CD5E8B1F53F07178 /* MockRoomTimelineControllerFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockRoomTimelineControllerFactory.swift; sourceTree = ""; }; + 7199693797B66245EF97BCF5 /* id */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = id; path = id.lproj/InfoPlist.strings; sourceTree = ""; }; 71A7D4DDEEE5D2CA0C8D63CD /* SoftLogoutScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SoftLogoutScreen.swift; sourceTree = ""; }; 71BC7CA1BC1041E93077BBA1 /* HomeScreenModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeScreenModels.swift; sourceTree = ""; }; 71D52BAA5BADB06E5E8C295D /* Assets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assets.swift; sourceTree = ""; }; @@ -3178,6 +3183,7 @@ children = ( 5A37E2FACFD041CE466223CD /* SceneDelegate.swift */, 035177BCD8E8308B098AC3C2 /* WindowManager.swift */, + 06F27F588F9059128E17C669 /* WindowManagerProtocol.swift */, ); path = Windowing; sourceTree = ""; @@ -5971,6 +5977,7 @@ DC1BB5EE5F4D9B6A1F98A77A /* WelcomeScreenScreenViewModel.swift in Sources */, 94CEF587A3994A36A46D8334 /* WelcomeScreenScreenViewModelProtocol.swift in Sources */, 08CB4BD12CEEDE6AAE4A18DD /* WindowManager.swift in Sources */, + AE5AAD9E32511544FDFA5560 /* WindowManagerProtocol.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -6120,7 +6127,10 @@ 8D1FA20DAB853C1156054912 /* cs */, 84311D707B09854D67F78BBF /* de */, 1215A4FC53D2319E81AE8970 /* en */, + 2525D78FEA7E7B132ED85C58 /* es */, ACD7BD6BEE21264F6677904A /* fr */, + 1D652E78832289CD9EB64488 /* hu */, + 7199693797B66245EF97BCF5 /* id */, 44C314C00533E2C297796B60 /* it */, 9B7D8D3638864B7482E148CC /* ru */, 7D39AF1F659923D77778511E /* sk */, diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index 32d41656e..f02e455f4 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -57,7 +57,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate, private var clientProxyObserver: AnyCancellable? private var cancellables = Set() - let windowManager = WindowManager() + let windowManager: WindowManagerProtocol = WindowManager() let notificationManager: NotificationManagerProtocol private let appRouteURLParser: AppRouteURLParser @@ -218,7 +218,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationCoordinatorDelegate, // MARK: - WindowManagerDelegate - func windowManagerDidConfigureWindows(_ windowManager: WindowManager) { + func windowManagerDidConfigureWindows(_ windowManager: WindowManagerProtocol) { windowManager.alternateWindow.rootViewController = UIHostingController(rootView: appLockFlowCoordinator.toPresentable()) ServiceLocator.shared.userIndicatorController.window = windowManager.overlayWindow } diff --git a/ElementX/Sources/Application/AppCoordinatorProtocol.swift b/ElementX/Sources/Application/AppCoordinatorProtocol.swift index 7787cf822..aa8649d3f 100644 --- a/ElementX/Sources/Application/AppCoordinatorProtocol.swift +++ b/ElementX/Sources/Application/AppCoordinatorProtocol.swift @@ -17,6 +17,6 @@ import Foundation protocol AppCoordinatorProtocol: CoordinatorProtocol { - var windowManager: WindowManager { get } + var windowManager: WindowManagerProtocol { get } @discardableResult func handleDeepLink(_ url: URL) -> Bool } diff --git a/ElementX/Sources/Application/Windowing/SceneDelegate.swift b/ElementX/Sources/Application/Windowing/SceneDelegate.swift index 0af1dc290..df9a5fb9b 100644 --- a/ElementX/Sources/Application/Windowing/SceneDelegate.swift +++ b/ElementX/Sources/Application/Windowing/SceneDelegate.swift @@ -20,7 +20,7 @@ import SwiftUI /// /// We don't support multiple scenes right now, so the implementation is pretty basic. class SceneDelegate: NSObject, UIWindowSceneDelegate { - weak static var windowManager: WindowManager! + weak static var windowManager: WindowManagerProtocol! func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = scene as? UIWindowScene else { return } diff --git a/ElementX/Sources/Application/Windowing/WindowManager.swift b/ElementX/Sources/Application/Windowing/WindowManager.swift index e87bd75c9..20e54ec41 100644 --- a/ElementX/Sources/Application/Windowing/WindowManager.swift +++ b/ElementX/Sources/Application/Windowing/WindowManager.swift @@ -17,23 +17,11 @@ import Combine import SwiftUI -protocol WindowManagerDelegate: AnyObject { - /// The window manager has configured its windows. - func windowManagerDidConfigureWindows(_ windowManager: WindowManager) -} - -@MainActor -/// A window manager that supports switching between a main app window with an overlay and -/// an alternate window to switch contexts whilst also preserving the main view hierarchy. -/// Heavily inspired by https://www.fivestars.blog/articles/swiftui-windows/ -class WindowManager { +class WindowManager: WindowManagerProtocol { weak var delegate: WindowManagerDelegate? - /// The app's main window (we only support a single scene). private(set) var mainWindow: UIWindow! - /// Presented on top of the main window, to display e.g. user indicators. private(set) var overlayWindow: UIWindow! - /// A secondary window that can be presented instead of the main/overlay window combo. private(set) var alternateWindow: UIWindow! var windows: [UIWindow] { @@ -46,7 +34,6 @@ class WindowManager { /// A duration that allows window switching to wait a couple of frames to avoid a transition through black. private let windowHideDelay = Duration.milliseconds(33) - /// Configures the window manager to operate on the supplied scene. func configure(with windowScene: UIWindowScene) { mainWindow = windowScene.keyWindow mainWindow.tintColor = .compound.textActionPrimary @@ -62,7 +49,6 @@ class WindowManager { delegate?.windowManagerDidConfigureWindows(self) } - /// Shows the main and overlay window combo, hiding the alternate window. func switchToMain() { mainWindow.isHidden = false overlayWindow.isHidden = false @@ -75,7 +61,6 @@ class WindowManager { } } - /// Shows the alternate window, hiding the main and overlay combo. func switchToAlternate() { alternateWindow.isHidden = false diff --git a/ElementX/Sources/Application/Windowing/WindowManagerProtocol.swift b/ElementX/Sources/Application/Windowing/WindowManagerProtocol.swift new file mode 100644 index 000000000..c0cae9e3b --- /dev/null +++ b/ElementX/Sources/Application/Windowing/WindowManagerProtocol.swift @@ -0,0 +1,49 @@ +// +// Copyright 2024 New Vector Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import SwiftUI + +protocol WindowManagerDelegate: AnyObject { + /// The window manager has configured its windows. + func windowManagerDidConfigureWindows(_ windowManager: WindowManagerProtocol) +} + +@MainActor +/// A window manager that supports switching between a main app window with an overlay and +/// an alternate window to switch contexts whilst also preserving the main view hierarchy. +/// Heavily inspired by https://www.fivestars.blog/articles/swiftui-windows/ +protocol WindowManagerProtocol: AnyObject { + var delegate: WindowManagerDelegate? { get set } + + /// The app's main window (we only support a single scene). + var mainWindow: UIWindow! { get } + /// Presented on top of the main window, to display e.g. user indicators. + var overlayWindow: UIWindow! { get } + /// A secondary window that can be presented instead of the main/overlay window combo. + var alternateWindow: UIWindow! { get } + + /// All the windows being managed + var windows: [UIWindow] { get } + + /// Configures the window manager to operate on the supplied scene. + func configure(with windowScene: UIWindowScene) + + /// Shows the main and overlay window combo, hiding the alternate window. + func switchToMain() + + /// Shows the alternate window, hiding the main and overlay combo. + func switchToAlternate() +} diff --git a/ElementX/Sources/FlowCoordinators/SettingsFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/SettingsFlowCoordinator.swift index 1cd7673c5..154093c00 100644 --- a/ElementX/Sources/FlowCoordinators/SettingsFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/SettingsFlowCoordinator.swift @@ -28,7 +28,7 @@ enum SettingsFlowCoordinatorAction { struct SettingsFlowCoordinatorParameters { let userSession: UserSessionProtocol - let windowManager: WindowManager + let windowManager: WindowManagerProtocol let appLockService: AppLockServiceProtocol let bugReportService: BugReportServiceProtocol let notificationSettings: NotificationSettingsProxyProtocol diff --git a/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift index 65b819f6b..7761a13f5 100644 --- a/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/UserSessionFlowCoordinator.swift @@ -49,7 +49,7 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol { init(userSession: UserSessionProtocol, navigationSplitCoordinator: NavigationSplitCoordinator, - windowManager: WindowManager, + windowManager: WindowManagerProtocol, appLockService: AppLockServiceProtocol, bugReportService: BugReportServiceProtocol, roomTimelineControllerFactory: RoomTimelineControllerFactoryProtocol, diff --git a/ElementX/Sources/UITests/UITestsAppCoordinator.swift b/ElementX/Sources/UITests/UITestsAppCoordinator.swift index 43091577d..bdc1ffbe7 100644 --- a/ElementX/Sources/UITests/UITestsAppCoordinator.swift +++ b/ElementX/Sources/UITests/UITestsAppCoordinator.swift @@ -28,7 +28,7 @@ class UITestsAppCoordinator: AppCoordinatorProtocol, WindowManagerDelegate { // periphery:ignore - retaining purpose private var alternateWindowMockScreen: MockScreen? - let windowManager = WindowManager() + let windowManager: WindowManagerProtocol = WindowManager() init() { // disabling View animations @@ -65,7 +65,7 @@ class UITestsAppCoordinator: AppCoordinatorProtocol, WindowManagerDelegate { fatalError("Not implemented.") } - func windowManagerDidConfigureWindows(_ windowManager: WindowManager) { + func windowManagerDidConfigureWindows(_ windowManager: WindowManagerProtocol) { ServiceLocator.shared.userIndicatorController.window = windowManager.overlayWindow // Set up the alternate window for the App Lock flow coordinator tests. @@ -79,12 +79,12 @@ class UITestsAppCoordinator: AppCoordinatorProtocol, WindowManagerDelegate { @MainActor class MockScreen: Identifiable { let id: UITestsScreenIdentifier - let windowManager: WindowManager + let windowManager: WindowManagerProtocol private var retainedState = [Any]() private var cancellables = Set() - init(id: UITestsScreenIdentifier, windowManager: WindowManager) { + init(id: UITestsScreenIdentifier, windowManager: WindowManagerProtocol) { self.id = id self.windowManager = windowManager } diff --git a/ElementX/Sources/UnitTests/UnitTestsAppCoordinator.swift b/ElementX/Sources/UnitTests/UnitTestsAppCoordinator.swift index 2b3af2116..4d1f1a0b5 100644 --- a/ElementX/Sources/UnitTests/UnitTestsAppCoordinator.swift +++ b/ElementX/Sources/UnitTests/UnitTestsAppCoordinator.swift @@ -17,7 +17,7 @@ import SwiftUI class UnitTestsAppCoordinator: AppCoordinatorProtocol { - let windowManager = WindowManager() + let windowManager: WindowManagerProtocol = WindowManager() init() { ServiceLocator.shared.register(userIndicatorController: UserIndicatorControllerMock.default)