diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2022-10-31 10:24:05 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2022-10-31 10:24:05 +0100 |
| commit | 96526fe223025af0fcb4cc9092e963c5b87f5f20 (patch) | |
| tree | 792a7635c1a21f9c2ca09be3cea38691215cd10c | |
| parent | ad0b7652ecb0511980a6c72eabad2e905c65a50e (diff) | |
| parent | 4327c75b7813adc77a4a09bdca9b068bdc001ad2 (diff) | |
| download | mullvadvpn-96526fe223025af0fcb4cc9092e963c5b87f5f20.tar.xz mullvadvpn-96526fe223025af0fcb4cc9092e963c5b87f5f20.zip | |
Merge branch 'remove-window-factory'
| -rw-r--r-- | ios/MullvadVPN/SceneDelegate.swift | 106 |
1 files changed, 35 insertions, 71 deletions
diff --git a/ios/MullvadVPN/SceneDelegate.swift b/ios/MullvadVPN/SceneDelegate.swift index df8b629b92..3cdb5d6b5c 100644 --- a/ios/MullvadVPN/SceneDelegate.swift +++ b/ios/MullvadVPN/SceneDelegate.swift @@ -51,22 +51,6 @@ class SceneDelegate: UIResponder { } } - func setupScene(windowFactory: WindowFactory) { - window = windowFactory.create() - window?.rootViewController = LaunchViewController() - - privacyOverlayWindow = windowFactory.create() - privacyOverlayWindow?.rootViewController = LaunchViewController() - privacyOverlayWindow?.windowLevel = .alert + 1 - - window?.makeKeyAndVisible() - - TunnelManager.shared.addObserver(self) - if TunnelManager.shared.isConfigurationLoaded { - configureScene() - } - } - func showUserAccount() { rootContainer.showSettings(navigateTo: .account, animated: true) } @@ -103,8 +87,38 @@ class SceneDelegate: UIResponder { window?.makeKeyAndVisible() } } +} + +// MARK: - UIWindowSceneDelegate + +extension SceneDelegate: UIWindowSceneDelegate { + func scene( + _ scene: UIScene, + willConnectTo session: UISceneSession, + options connectionOptions: UIScene.ConnectionOptions + ) { + guard let windowScene = scene as? UIWindowScene else { return } + + window = UIWindow(windowScene: windowScene) + window?.rootViewController = LaunchViewController() + + privacyOverlayWindow = UIWindow(windowScene: windowScene) + privacyOverlayWindow?.rootViewController = LaunchViewController() + privacyOverlayWindow?.windowLevel = .alert + 1 + + window?.makeKeyAndVisible() + + TunnelManager.shared.addObserver(self) + if TunnelManager.shared.isConfigurationLoaded { + configureScene() + } + } - @objc private func sceneDidBecomeActive() { + func sceneDidDisconnect(_ scene: UIScene) { + // no-op + } + + func sceneDidBecomeActive(_ scene: UIScene) { TunnelManager.shared.refreshTunnelStatus() if isSceneConfigured { @@ -123,7 +137,7 @@ class SceneDelegate: UIResponder { setShowsPrivacyOverlay(false) } - @objc private func sceneWillResignActive() { + func sceneWillResignActive(_ scene: UIScene) { RelayCacheTracker.shared.stopPeriodicUpdates() TunnelManager.shared.stopPeriodicPrivateKeyRotation() AddressCacheTracker.shared.stopPeriodicUpdates() @@ -131,44 +145,14 @@ class SceneDelegate: UIResponder { setShowsPrivacyOverlay(true) } - @objc private func sceneDidEnterBackground() { - let appDelegate = UIApplication.shared.delegate as? AppDelegate - - appDelegate?.scheduleBackgroundTasks() - } -} - -// MARK: - UIWindowSceneDelegate - -extension SceneDelegate: UIWindowSceneDelegate { - func scene( - _ scene: UIScene, - willConnectTo session: UISceneSession, - options connectionOptions: UIScene.ConnectionOptions - ) { - guard let windowScene = scene as? UIWindowScene else { return } - - setupScene(windowFactory: SceneWindowFactory(windowScene: windowScene)) - } - - func sceneDidDisconnect(_ scene: UIScene) { - // no-op - } - - func sceneDidBecomeActive(_ scene: UIScene) { - sceneDidBecomeActive() - } - - func sceneWillResignActive(_ scene: UIScene) { - sceneWillResignActive() - } - func sceneWillEnterForeground(_ scene: UIScene) { // no-op } func sceneDidEnterBackground(_ scene: UIScene) { - sceneDidEnterBackground() + let appDelegate = UIApplication.shared.delegate as? AppDelegate + + appDelegate?.scheduleBackgroundTasks() } } @@ -970,23 +954,3 @@ extension SceneDelegate: UISplitViewControllerDelegate { return nil } } - -// MARK: - Window factory - -protocol WindowFactory { - func create() -> UIWindow -} - -struct ClassicWindowFactory: WindowFactory { - func create() -> UIWindow { - return UIWindow(frame: UIScreen.main.bounds) - } -} - -struct SceneWindowFactory: WindowFactory { - let windowScene: UIWindowScene - - func create() -> UIWindow { - return UIWindow(windowScene: windowScene) - } -} |
