Skip to content

Commit

Permalink
fix: Photo library upload will not restart if using applock
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed Jan 9, 2024
1 parent 71b14e6 commit e86f036
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
6 changes: 4 additions & 2 deletions kDrive/AppDelegate+Launch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -41,6 +42,7 @@ extension AppDelegate {
showLaunchFloatingPanel()
requestAppStoreReview()
askUserToRemovePicturesIfNecessary()
refreshCacheAndRestartUpload()
case .onboarding:
showOnboarding()
}
Expand Down
14 changes: 7 additions & 7 deletions kDrive/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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)
}
}

Expand Down
5 changes: 4 additions & 1 deletion kDrive/UI/Controller/Menu/MenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e86f036

Please sign in to comment.