Skip to content

Commit

Permalink
feat: Enabling UIScene delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed May 23, 2024
1 parent e07b35c commit 05a26c7
Show file tree
Hide file tree
Showing 10 changed files with 874 additions and 248 deletions.
202 changes: 102 additions & 100 deletions kDrive/AppDelegate+Launch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,109 +28,111 @@ import UIKit
extension AppDelegate {
// MARK: Launch

func prepareRootViewController(currentState: RootViewControllerState) {
switch currentState {
case .appLock:
showAppLock()
case .mainViewController(let driveFileManager):
showMainViewController(driveFileManager: driveFileManager)
showLaunchFloatingPanel()
askForReview()
askUserToRemovePicturesIfNecessary()
case .onboarding:
showOnboarding()
case .updateRequired:
showUpdateRequired()
case .preloading(let currentAccount):
showPreloading(currentAccount: currentAccount)
}
}

func updateRootViewControllerState() {
let newState = RootViewControllerState.getCurrentState()
prepareRootViewController(currentState: newState)
}
// func prepareRootViewController(currentState: RootViewControllerState) {
// switch currentState {
// case .appLock:
// showAppLock()
// case .mainViewController(let driveFileManager):
// showMainViewController(driveFileManager: driveFileManager)
// showLaunchFloatingPanel()
// askForReview()
// askUserToRemovePicturesIfNecessary()
// case .onboarding:
// showOnboarding()
// case .updateRequired:
// showUpdateRequired()
// case .preloading(let currentAccount):
// showPreloading(currentAccount: currentAccount)
// }
// }

// func updateRootViewControllerState() {
// let newState = RootViewControllerState.getCurrentState()
// prepareRootViewController(currentState: newState)
// }

// MARK: Set root VC

func showMainViewController(driveFileManager: DriveFileManager) {
guard let window else {
SentryDebug.captureNoWindow()
return
}

let currentDriveObjectId = (window.rootViewController as? MainTabViewController)?.driveFileManager.drive.objectId
guard currentDriveObjectId != driveFileManager.drive.objectId else {
return
}

window.rootViewController = MainTabViewController(driveFileManager: driveFileManager)
window.makeKeyAndVisible()
}

func showPreloading(currentAccount: Account) {
guard let window else {
SentryDebug.captureNoWindow()
return
}

window.rootViewController = PreloadingViewController(currentAccount: currentAccount)
window.makeKeyAndVisible()
}

private func showOnboarding() {
guard let window else {
SentryDebug.captureNoWindow()
return
}

defer {
// Clean File Provider domains on first launch in case we had some dangling
driveInfosManager.deleteAllFileProviderDomains()
}

// Check if presenting onboarding
let isNotPresentingOnboarding = window.rootViewController?.isKind(of: OnboardingViewController.self) != true
guard isNotPresentingOnboarding else {
return
}

keychainHelper.deleteAllTokens()
window.rootViewController = OnboardingViewController.instantiate()
window.makeKeyAndVisible()
}

private func showAppLock() {
guard let window else {
SentryDebug.captureNoWindow()
return
}

window.rootViewController = LockedAppViewController.instantiate()
window.makeKeyAndVisible()
}

private func showLaunchFloatingPanel() {
guard let window else {
SentryDebug.captureNoWindow()
return
}

let launchPanelsController = LaunchPanelsController()
if let viewController = window.rootViewController {
launchPanelsController.pickAndDisplayPanel(viewController: viewController)
}
}

private func showUpdateRequired() {
guard let window else {
SentryDebug.captureNoWindow()
return
}

window.rootViewController = DriveUpdateRequiredViewController()
window.makeKeyAndVisible()
}
/*
func showMainViewController(driveFileManager: DriveFileManager) {
guard let window else {
SentryDebug.captureNoWindow()
return
}
let currentDriveObjectId = (window.rootViewController as? MainTabViewController)?.driveFileManager.drive.objectId
guard currentDriveObjectId != driveFileManager.drive.objectId else {
return
}
window.rootViewController = MainTabViewController(driveFileManager: driveFileManager)
window.makeKeyAndVisible()
}
func showPreloading(currentAccount: Account) {
guard let window else {
SentryDebug.captureNoWindow()
return
}
window.rootViewController = PreloadingViewController(currentAccount: currentAccount)
window.makeKeyAndVisible()
}
private func showOnboarding() {
guard let window else {
SentryDebug.captureNoWindow()
return
}
defer {
// Clean File Provider domains on first launch in case we had some dangling
driveInfosManager.deleteAllFileProviderDomains()
}
// Check if presenting onboarding
let isNotPresentingOnboarding = window.rootViewController?.isKind(of: OnboardingViewController.self) != true
guard isNotPresentingOnboarding else {
return
}
keychainHelper.deleteAllTokens()
window.rootViewController = OnboardingViewController.instantiate()
window.makeKeyAndVisible()
}
private func showAppLock() {
guard let window else {
SentryDebug.captureNoWindow()
return
}
window.rootViewController = LockedAppViewController.instantiate()
window.makeKeyAndVisible()
}
private func showLaunchFloatingPanel() {
guard let window else {
SentryDebug.captureNoWindow()
return
}
let launchPanelsController = LaunchPanelsController()
if let viewController = window.rootViewController {
launchPanelsController.pickAndDisplayPanel(viewController: viewController)
}
}
private func showUpdateRequired() {
guard let window else {
SentryDebug.captureNoWindow()
return
}
window.rootViewController = DriveUpdateRequiredViewController()
window.makeKeyAndVisible()
}
*/

// MARK: Misc

Expand Down
50 changes: 50 additions & 0 deletions kDrive/AppDelegate+Scene.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Infomaniak kDrive - iOS App
Copyright (C) 2023 Infomaniak Network SA
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import UIKit

extension AppDelegate {
/** iOS 13 or later
UIKit uses this delegate when it is about to create and vend a new UIScene instance to the application.
Use this function to select a configuration to create the new scene with.
You can define the scene configuration in code here, or define it in the Info.plist.
The application delegate may modify the provided UISceneConfiguration within this function.
If the UISceneConfiguration instance that returns from this function does not have a systemType
that matches the connectingSession's, UIKit asserts.
*/
func application(_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions) -> UISceneConfiguration {
print("•• application configurationForConnecting:\(connectingSceneSession)")
return connectingSceneSession.configuration
}

/** iOS 13 or later
The system calls this delegate when it removes one or more representations from the -[UIApplication openSessions] set
due to a user interaction or a request from the app itself. If the system discards sessions while the app isn't running,
it calls this function shortly after the app’s next launch.
Use this function to:
Release any resources that were specific to the discarded scenes, as they will NOT return.
Remove any state or data associated with this session, as it will not return (such as, unsaved draft of a document).
*/
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
print("•• application didDiscardSceneSessions:\(sceneSessions)")
}
}
43 changes: 43 additions & 0 deletions kDrive/AppDelegate+StateRestoration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Infomaniak kDrive - iOS App
Copyright (C) 2023 Infomaniak Network SA
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import UIKit

extension AppDelegate {
// For non-scene-based versions of this app on iOS 13.1 and earlier.
func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool {
return appRestorationService.shouldSaveApplicationState(coder: coder)
}

// For non-scene-based versions of this app on iOS 13.1 and earlier.
func application(_ application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool {
return appRestorationService.shouldRestoreApplicationState(coder: coder)
}

@available(iOS 13.2, *)
// For non-scene-based versions of this app on iOS 13.2 and later.
func application(_ application: UIApplication, shouldSaveSecureApplicationState coder: NSCoder) -> Bool {
return appRestorationService.shouldSaveApplicationState(coder: coder)
}

@available(iOS 13.2, *)
// For non-scene-based versions of this app on iOS 13.2 and later.
func application(_ application: UIApplication, shouldRestoreSecureApplicationState coder: NSCoder) -> Bool {
return appRestorationService.shouldRestoreApplicationState(coder: coder)
}
}
Loading

0 comments on commit 05a26c7

Please sign in to comment.