diff --git a/kDrive/AppDelegate+Launch.swift b/kDrive/AppDelegate+Launch.swift index 1d363bb58..100935de7 100644 --- a/kDrive/AppDelegate+Launch.swift +++ b/kDrive/AppDelegate+Launch.swift @@ -27,8 +27,9 @@ import UIKit extension AppDelegate { // MARK: Launch - func launchSetup() { - refreshCacheData(preload: false, isSwitching: false) + /// Refresh cache for `currentDrive`, Scan photo library and restart upload. + func refreshCacheAndRestartUpload() { + refreshCacheScanLibraryAndUpload(preload: false, isSwitching: false) uploadEditedFiles() } @@ -41,6 +42,7 @@ extension AppDelegate { showLaunchFloatingPanel() requestAppStoreReview() askUserToRemovePicturesIfNecessary() + refreshCacheAndRestartUpload() case .onboarding: showOnboarding() } diff --git a/kDrive/AppDelegate.swift b/kDrive/AppDelegate.swift index bca59419b..8d58e24e1 100644 --- a/kDrive/AppDelegate.swift +++ b/kDrive/AppDelegate.swift @@ -235,7 +235,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, AccountManagerDeleg prepareRootViewController(currentState: currentState) if case .mainViewController = currentState { UserDefaults.shared.numberOfConnections += 1 - launchSetup() + refreshCacheAndRestartUpload() } // Remove all notifications on App Opening @@ -295,8 +295,8 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, AccountManagerDeleg } } - func refreshCacheData(preload: Bool, isSwitching: Bool) { - Log.appDelegate("refreshCacheData preload:\(preload) isSwitching:\(preload)") + func refreshCacheScanLibraryAndUpload(preload: Bool, isSwitching: Bool) { + Log.appDelegate("refreshCacheScanLibraryAndUpload preload:\(preload) isSwitching:\(preload)") guard let currentAccount = accountManager.currentAccount else { Log.appDelegate("No account to refresh", level: .error) @@ -328,14 +328,14 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, AccountManagerDeleg let newDrive = DriveInfosManager.instance.getDrive(objectId: oldDriveId), !newDrive.inMaintenance { // The current drive is still usable, do not switch - restartUploadQueue() + scanLibraryAndRestartUpload() return } let driveFileManager = try accountManager.getFirstAvailableDriveFileManager(for: account.userId) accountManager.setCurrentDriveForCurrentAccount(drive: driveFileManager.drive) showMainViewController(driveFileManager: driveFileManager) - restartUploadQueue() + scanLibraryAndRestartUpload() } catch DriveError.NoDriveError.noDrive { let driveErrorNavigationViewController = DriveErrorViewController.instantiateInNavigationController( errorType: .noDrive, @@ -355,7 +355,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, AccountManagerDeleg } } - private func restartUploadQueue() { + private func scanLibraryAndRestartUpload() { // Resolving an upload queue will restart it if this is the first time @InjectService var uploadQueue: UploadQueue @@ -465,7 +465,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, AccountManagerDeleg @objc func reloadDrive(_ notification: Notification) { Task { @MainActor in - self.refreshCacheData(preload: false, isSwitching: false) + self.refreshCacheScanLibraryAndUpload(preload: false, isSwitching: false) } } diff --git a/kDrive/UI/Controller/Menu/MenuViewController.swift b/kDrive/UI/Controller/Menu/MenuViewController.swift index bc9bf99e0..a61476708 100644 --- a/kDrive/UI/Controller/Menu/MenuViewController.swift +++ b/kDrive/UI/Controller/Menu/MenuViewController.swift @@ -287,7 +287,10 @@ extension MenuViewController { self.accountManager.removeTokenAndAccount(token: self.accountManager.currentAccount.token) if let nextAccount = self.accountManager.accounts.first { self.accountManager.switchAccount(newAccount: nextAccount) - (UIApplication.shared.delegate as? AppDelegate)?.refreshCacheData(preload: true, isSwitching: true) + (UIApplication.shared.delegate as? AppDelegate)?.refreshCacheScanLibraryAndUpload( + preload: true, + isSwitching: true + ) } else { SentrySDK.setUser(nil) self.tabBarController?.present(OnboardingViewController.instantiate(), animated: true) diff --git a/kDrive/UI/Controller/Menu/ParameterTableViewController.swift b/kDrive/UI/Controller/Menu/ParameterTableViewController.swift index 346a410fd..47308c1dc 100644 --- a/kDrive/UI/Controller/Menu/ParameterTableViewController.swift +++ b/kDrive/UI/Controller/Menu/ParameterTableViewController.swift @@ -206,7 +206,7 @@ extension ParameterTableViewController: DeleteAccountDelegate { accountManager.removeTokenAndAccount(token: accountManager.currentAccount.token) if let nextAccount = accountManager.accounts.first { accountManager.switchAccount(newAccount: nextAccount) - (UIApplication.shared.delegate as? AppDelegate)?.refreshCacheData(preload: true, isSwitching: true) + (UIApplication.shared.delegate as? AppDelegate)?.refreshCacheScanLibraryAndUpload(preload: true, isSwitching: true) driveFileManager = accountManager.currentDriveFileManager } else { SentrySDK.setUser(nil)