Skip to content

Commit

Permalink
fix: Making sure the scan an upload is restarted on first app launch
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed Jan 10, 2024
1 parent f439df2 commit 9f4c366
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
6 changes: 0 additions & 6 deletions kDrive/AppDelegate+Launch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ import UIKit
extension AppDelegate {
// MARK: Launch

/// Refresh cache for `currentDrive`, Scan photo library and restart upload.
func refreshCacheAndRestartUpload() {
refreshCacheScanLibraryAndUpload(preload: false, isSwitching: false)
uploadEditedFiles()
}

func prepareRootViewController(currentState: RootViewControllerState) {
switch currentState {
case .appLock:
Expand Down
19 changes: 10 additions & 9 deletions kDrive/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, AccountManagerDeleg

window = UIWindow()
setGlobalTint()
let currentState = RootViewControllerState.getCurrentState()
prepareRootViewController(currentState: currentState)

let state = UIApplication.shared.applicationState
if state != .background {
appWillBePresentedToTheUser()
}

accountManager.delegate = self

Expand Down Expand Up @@ -119,12 +122,6 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, AccountManagerDeleg
}
application.registerForRemoteNotifications()

let state = UIApplication.shared.applicationState
if state != .background {
// Remove all notifications on App Opening
UNUserNotificationCenter.current().removeAllDeliveredNotifications()
}

if let shortcutItem = launchOptions?[UIApplication.LaunchOptionsKey.shortcutItem] as? UIApplicationShortcutItem {
shortcutItemToProcess = shortcutItem
}
Expand Down Expand Up @@ -227,7 +224,10 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, AccountManagerDeleg

func applicationWillEnterForeground(_ application: UIApplication) {
Log.appDelegate("applicationWillEnterForeground")
appWillBePresentedToTheUser()
}

private func appWillBePresentedToTheUser() {
@InjectService var uploadQueue: UploadQueue
uploadQueue.pausedNotificationSent = false

Expand All @@ -236,7 +236,8 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, AccountManagerDeleg
switch currentState {
case .mainViewController, .appLock:
UserDefaults.shared.numberOfConnections += 1
refreshCacheAndRestartUpload()
refreshCacheScanLibraryAndUpload(preload: false, isSwitching: false)
uploadEditedFiles()
case .onboarding: break
// NOOP
}
Expand Down

0 comments on commit 9f4c366

Please sign in to comment.