Эх сурвалжийг харах

Merge pull request #2180 from nextcloud/action

Action
Marino Faggiana 2 жил өмнө
parent
commit
03eaae232b

+ 2 - 2
Nextcloud.xcodeproj/project.pbxproj

@@ -3389,7 +3389,7 @@
 				CLANG_WARN_UNREACHABLE_CODE = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 				COPY_PHASE_STRIP = NO;
-				CURRENT_PROJECT_VERSION = 11;
+				CURRENT_PROJECT_VERSION = 12;
 				DEVELOPMENT_TEAM = NKUJUXUJ3B;
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
 				ENABLE_TESTABILITY = YES;
@@ -3451,7 +3451,7 @@
 				CLANG_WARN_UNREACHABLE_CODE = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 				COPY_PHASE_STRIP = NO;
-				CURRENT_PROJECT_VERSION = 11;
+				CURRENT_PROJECT_VERSION = 12;
 				DEVELOPMENT_TEAM = NKUJUXUJ3B;
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
 				ENABLE_TESTABILITY = YES;

+ 27 - 30
iOSClient/AppDelegate.swift

@@ -65,9 +65,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
 
         let userAgent = CCUtility.getUserAgent() as String
-        let isSimulatorOrTestFlight = NCUtility.shared.isSimulatorOrTestFlight()
         let versionNextcloudiOS = String(format: NCBrandOptions.shared.textCopyrightNextcloudiOS, NCUtility.shared.getVersionApp())
 
+        // Register initialize
+        NotificationCenter.default.addObserver(self, selector: #selector(initialize), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterInitialize), object: nil)
+
         UserDefaults.standard.register(defaults: ["UserAgent": userAgent])
         if !CCUtility.getDisableCrashservice() && !NCBrandOptions.shared.disable_crash_service {
             FirebaseApp.configure()
@@ -136,16 +138,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         // Create user color
         NCBrandColor.shared.createUserColors()
 
-        // Register initialize
-        NotificationCenter.default.addObserver(self, selector: #selector(initialize), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterInitialize), object: nil)
-
-        // Start process Upload, Initialize
-        if UIApplication.shared.applicationState != .background {
-            NKCommon.shared.writeLog("[INFO] Starting process upload and Inizialize main")
-            networkingProcessUpload = NCNetworkingProcessUpload()
-            NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterInitialize, userInfo:["atStart":1])
-        }
-
         // Push Notification & display notification
         application.registerForRemoteNotifications()
         UNUserNotificationCenter.current().delegate = self
@@ -223,16 +215,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         // Account changed ??
         if activeAccount.account != account {
             settingAccount(activeAccount.account, urlBase: activeAccount.urlBase, user: activeAccount.user, userId: activeAccount.userId, password: CCUtility.getPassword(activeAccount.account))
-
-            NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterInitialize)
-        }
-
-        // START UPLOAD PROCESS
-        networkingProcessUpload = NCNetworkingProcessUpload()
-
-        // Initialize Auto upload
-        NCAutoUpload.shared.initAutoUpload(viewController: nil) { items in
-            NKCommon.shared.writeLog("[INFO] Initialize Auto upload with \(items) uploads")
+        } else {
+            // Initialize Auto upload
+            NCAutoUpload.shared.initAutoUpload(viewController: nil) { items in
+                NKCommon.shared.writeLog("[INFO] Initialize Auto upload with \(items) uploads")
+                // START UPLOAD PROCESS
+                DispatchQueue.main.async { self.networkingProcessUpload = NCNetworkingProcessUpload() }
+            }
         }
 
         // Required unsubscribing / subscribing
@@ -317,6 +306,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         // Start Auto Upload
         NCAutoUpload.shared.initAutoUpload(viewController: nil) { items in
             NKCommon.shared.writeLog("[INFO] Initialize Auto upload with \(items) uploads")
+            DispatchQueue.main.async { self.networkingProcessUpload = NCNetworkingProcessUpload() }
         }
 
         // Start services
@@ -544,19 +534,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
         let certificateHostSavedPath = CCUtility.getDirectoryCerificates()! + "/" + host + ".der"
         var title = NSLocalizedString("_ssl_certificate_changed_", comment: "")
-        
+
         if !FileManager.default.fileExists(atPath: certificateHostSavedPath) {
             title = NSLocalizedString("_connect_server_anyway_", comment: "")
         }
-        
+
         let alertController = UIAlertController(title: title, message: NSLocalizedString("_server_is_trusted_", comment: ""), preferredStyle: .alert)
-        
+
         alertController.addAction(UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .default, handler: { action in
             NCNetworking.shared.writeCertificate(host: host)
         }))
-        
+
         alertController.addAction(UIAlertAction(title: NSLocalizedString("_no_", comment: ""), style: .default, handler: { action in }))
-        
+
         alertController.addAction(UIAlertAction(title: NSLocalizedString("_certificate_details_", comment: ""), style: .default, handler: { action in
             if let navigationController = UIStoryboard(name: "NCViewCertificateDetails", bundle: nil).instantiateInitialViewController() as? UINavigationController {
                 let viewController = navigationController.topViewController as! NCViewCertificateDetails
@@ -565,7 +555,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
                 self.window?.rootViewController?.present(navigationController, animated: true)
             }
         }))
-        
+
         window?.rootViewController?.present(alertController, animated: true)
     }
 
@@ -577,6 +567,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
     @objc func settingAccount(_ account: String, urlBase: String, user: String, userId: String, password: String) {
 
+        let accountBackup = self.account
+        let userIdBackup = self.userId
+
         self.account = account
         self.urlBase = urlBase
         self.user = user
@@ -591,6 +584,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             NKCommon.shared.setup(nextcloudVersion: serverVersionMajor)
         }
         NCKTVHTTPCache.shared.restartProxy(user: user, password: password)
+
+        DispatchQueue.main.async {
+            if UIApplication.shared.applicationState != .background && (accountBackup != account || userIdBackup != userId) {
+                NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterInitialize, second: 0.2)
+            }
+        }
     }
 
     @objc func deleteAccount(_ account: String, wipe: Bool) {
@@ -631,8 +630,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
             NCNetworking.shared.cancelAllTask()
 
             settingAccount(tableAccount.account, urlBase: tableAccount.urlBase, user: tableAccount.user, userId: tableAccount.userId, password: CCUtility.getPassword(tableAccount.account))
-
-            NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterInitialize)
         }
     }
 
@@ -895,7 +892,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
                         }
 
                         DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
-                            NCFunctionCenter.shared.openFileViewInFolder(serverUrl: serverUrl, fileNameBlink: fileName)
+                            NCFunctionCenter.shared.openFileViewInFolder(serverUrl: serverUrl, fileNameBlink: nil, fileNameOpen: fileName)
                         }
 
                     } else {

+ 24 - 8
iOSClient/Files/NCFiles.swift

@@ -28,6 +28,7 @@ class NCFiles: NCCollectionViewCommon {
 
     internal var isRoot: Bool = true
     internal var fileNameBlink: String?
+    internal var fileNameOpen: String?
 
     // MARK: - View Life Cycle
 
@@ -60,21 +61,24 @@ class NCFiles: NCCollectionViewCommon {
         super.viewWillDisappear(animated)
 
         fileNameBlink = nil
+        fileNameOpen = nil
     }
 
     // MARK: - NotificationCenter
 
-    override func initialize(_ notification: NSNotification) {
+    override func initialize() {
 
         if isRoot {
             serverUrl = NCUtilityFileSystem.shared.getHomeServer(account: appDelegate.account)
             titleCurrentFolder = getNavigationTitle()
         }
-        super.initialize(notification)
+        super.initialize()
 
+        /*
         if let userInfo = notification.userInfo as NSDictionary?, userInfo["atStart"] as? Int == 1 {
             return
         }
+        */
 
         reloadDataSource(forced: false)
         reloadDataSourceNetwork()
@@ -101,7 +105,7 @@ class NCFiles: NCCollectionViewCommon {
             self.richWorkspaceText = directory?.richWorkspace
 
             // FORCED false: test the directory.etag
-            if !forced, let directory = directory, directory.etag == self.dataSource.directory?.etag, metadataTransfer == nil, self.fileNameBlink == nil {
+            if !forced, let directory = directory, directory.etag == self.dataSource.directory?.etag, metadataTransfer == nil, self.fileNameBlink == nil, self.fileNameOpen == nil {
                 return
             }
 
@@ -122,7 +126,9 @@ class NCFiles: NCCollectionViewCommon {
                 self.collectionView.reloadData()
                 if !self.dataSource.metadatas.isEmpty {
                     self.blinkCell(fileName: self.fileNameBlink)
+                    self.openFile(fileName: self.fileNameOpen)
                     self.fileNameBlink = nil
+                    self.fileNameOpen = nil
                 }
             }
         }
@@ -139,10 +145,8 @@ class NCFiles: NCCollectionViewCommon {
 
         networkReadFolder(forced: forced) { tableDirectory, metadatas, metadatasUpdate, metadatasDelete, error in
             if error == .success {
-                for metadata in metadatas ?? [] {
-                    if !metadata.directory, NCManageDatabase.shared.isDownloadMetadata(metadata, download: false) {
-                        NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorDownloadFile)
-                    }
+                for metadata in metadatas ?? [] where !metadata.directory && NCManageDatabase.shared.isDownloadMetadata(metadata, download: false) {
+                    NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorDownloadFile)
                 }
             }
 
@@ -164,7 +168,7 @@ class NCFiles: NCCollectionViewCommon {
         if let fileName = fileName, let metadata = NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@", self.appDelegate.account, self.serverUrl, fileName)) {
             let (indexPath, _) = self.dataSource.getIndexPathMetadata(ocId: metadata.ocId)
             if let indexPath = indexPath {
-                DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
+                DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                     UIView.animate(withDuration: 0.3) {
                         self.collectionView.scrollToItem(at: indexPath, at: .centeredVertically, animated: false)
                     } completion: { _ in
@@ -179,4 +183,16 @@ class NCFiles: NCCollectionViewCommon {
             }
         }
     }
+
+    func openFile(fileName: String?) {
+
+        if let fileName = fileName, let metadata = NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@", self.appDelegate.account, self.serverUrl, fileName)) {
+            let (indexPath, _) = self.dataSource.getIndexPathMetadata(ocId: metadata.ocId)
+            if let indexPath = indexPath {
+                DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
+                    self.collectionView(self.collectionView, didSelectItemAt: indexPath)
+                }
+            }
+        }
+    }
 }

+ 0 - 10
iOSClient/Login/NCLogin.swift

@@ -347,25 +347,15 @@ class NCLogin: UIViewController, UITextFieldDelegate, NCLoginQRCodeDelegate {
             }
 
             if CCUtility.getIntro() {
-
-                NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterInitialize)
                 self.dismiss(animated: true)
-
             } else {
-
                 CCUtility.setIntro(true)
-
                 if self.presentingViewController == nil {
-
                     let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()
                     viewController?.modalPresentationStyle = .fullScreen
-                    NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterInitialize)
                     self.appDelegate.window?.rootViewController = viewController
                     self.appDelegate.window?.makeKey()
-
                 } else {
-
-                    NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterInitialize)
                     self.dismiss(animated: true)
                 }
             }

+ 0 - 6
iOSClient/Login/NCLoginWeb.swift

@@ -320,17 +320,12 @@ extension NCLoginWeb: WKNavigationDelegate {
         appDelegate.settingAccount(account, urlBase: urlBase, user: username, userId: tableAccount.userId, password: password)
 
         if CCUtility.getIntro() {
-
-            NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterInitialize)
             self.dismiss(animated: true)
-
         } else {
-
             CCUtility.setIntro(true)
             if self.presentingViewController == nil {
                 if let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController() {
                     viewController.modalPresentationStyle = .fullScreen
-                    NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterInitialize)
                     viewController.view.alpha = 0
                     appDelegate.window?.rootViewController = viewController
                     appDelegate.window?.makeKeyAndVisible()
@@ -339,7 +334,6 @@ extension NCLoginWeb: WKNavigationDelegate {
                     }
                 }
             } else {
-                NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterInitialize)
                 self.dismiss(animated: true)
             }
         }

+ 2 - 4
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -155,7 +155,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
         tipView = EasyTipView(text: NSLocalizedString("_tip_accountrequest_", comment: ""), preferences: preferences, delegate: self)
 
         // Notification
-        NotificationCenter.default.addObserver(self, selector: #selector(initialize(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterInitialize), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(initialize), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterInitialize), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeTheming), object: nil)
     }
 
@@ -280,7 +280,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
 
     // MARK: - NotificationCenter
 
-    @objc func initialize(_ notification: NSNotification) {
+    @objc func initialize() {
         guard !appDelegate.account.isEmpty else { return }
 
         // Search
@@ -799,8 +799,6 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
             NCNetworking.shared.cancelAllTask()
 
             appDelegate.settingAccount(activeAccount.account, urlBase: activeAccount.urlBase, user: activeAccount.user, userId: activeAccount.userId, password: CCUtility.getPassword(activeAccount.account))
-
-            NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterInitialize)
         }
     }
 

+ 8 - 4
iOSClient/Main/NCFunctionCenter.swift

@@ -460,18 +460,20 @@ import Photos
 
     // MARK: -
 
-    func openFileViewInFolder(serverUrl: String, fileNameBlink: String?) {
+    func openFileViewInFolder(serverUrl: String, fileNameBlink: String?, fileNameOpen: String?) {
 
         appDelegate.isSearchingMode = false
         
         DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
             var topNavigationController: UINavigationController?
             var pushServerUrl = NCUtilityFileSystem.shared.getHomeServer(account: self.appDelegate.account)
-            var mostViewController = UIApplication.shared.keyWindow!.rootViewController!.topMostViewController()
+            guard var mostViewController = self.appDelegate.window?.rootViewController?.topMostViewController() else { return }
 
             if mostViewController.isModal {
                 mostViewController.dismiss(animated: false)
-                mostViewController = UIApplication.shared.keyWindow!.rootViewController!.topMostViewController()
+                if let viewController = self.appDelegate.window?.rootViewController?.topMostViewController() {
+                    mostViewController = viewController
+                }
             }
             mostViewController.navigationController?.popToRootViewController(animated: false)
 
@@ -485,6 +487,7 @@ import Photos
             if pushServerUrl == serverUrl {
                 let viewController = topNavigationController?.topViewController as? NCFiles
                 viewController?.blinkCell(fileName: fileNameBlink)
+                viewController?.openFile(fileName: fileNameOpen)
                 return
             }
             guard let topNavigationController = topNavigationController else { return }
@@ -502,6 +505,7 @@ import Photos
                 viewController.titleCurrentFolder = String(dir)
                 if pushServerUrl == serverUrl {
                     viewController.fileNameBlink = fileNameBlink
+                    viewController.fileNameOpen = fileNameOpen
                 }
                 self.appDelegate.listFilesVC[serverUrl] = viewController
 
@@ -650,7 +654,7 @@ import Photos
         }
 
         let viewInFolder = UIAction(title: NSLocalizedString("_view_in_folder_", comment: ""), image: UIImage(systemName: "arrow.forward.square")) { _ in
-            self.openFileViewInFolder(serverUrl: metadata.serverUrl, fileNameBlink: metadata.fileName)
+            self.openFileViewInFolder(serverUrl: metadata.serverUrl, fileNameBlink: metadata.fileName, fileNameOpen: nil)
         }
 
         let openIn = UIAction(title: NSLocalizedString("_open_in_", comment: ""), image: UIImage(systemName: "square.and.arrow.up") ) { _ in

+ 0 - 4
iOSClient/Media/Cell/NCGridMediaCell.swift

@@ -62,10 +62,6 @@ class NCGridMediaCell: UICollectionViewCell, NCCellProtocol {
         imageItem.backgroundColor = .secondarySystemBackground
         imageStatus.image = nil
         imageItem.image = nil
-        imageItem.layer.masksToBounds = true
-        imageItem.layer.cornerRadius = 3
-        imageVisualEffect.layer.cornerRadius = 3
-        imageVisualEffect.clipsToBounds = true
     }
 
     func selectMode(_ status: Bool) {

+ 0 - 1
iOSClient/Menu/NCLoginWeb+Menu.swift

@@ -55,7 +55,6 @@ extension NCLoginWeb {
                             NCManageDatabase.shared.setAccountActive(account.account)
                             self.dismiss(animated: true) {
                                 self.appDelegate.settingAccount(account.account, urlBase: account.urlBase, user: account.user, userId: account.userId, password: CCUtility.getPassword(account.account))
-                                NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterInitialize)
                             }
                         }
                     }

+ 1 - 1
iOSClient/Menu/NCViewer+Menu.swift

@@ -190,7 +190,7 @@ extension NCViewer {
                     title: NSLocalizedString("_view_in_folder_", comment: ""),
                     icon: NCUtility.shared.loadImage(named: "arrow.forward.square"),
                     action: { menuAction in
-                        NCFunctionCenter.shared.openFileViewInFolder(serverUrl: metadata.serverUrl, fileNameBlink: metadata.fileName)
+                        NCFunctionCenter.shared.openFileViewInFolder(serverUrl: metadata.serverUrl, fileNameBlink: metadata.fileName, fileNameOpen: nil)
                     }
                 )
             )

+ 5 - 52
iOSClient/Networking/NCAutoUpload.swift

@@ -171,62 +171,15 @@ class NCAutoUpload: NSObject {
             if selector == NCGlobal.shared.selectorUploadAutoUploadAll {
                 self.appDelegate?.networkingProcessUpload?.createProcessUploads(metadatas: metadatas, completion: completion)
             } else {
-                if self.applicationState == .background {
-                    self.createBackgroundProcessAutoUpload(metadatas: metadatas, completion: completion)
-                } else {
-                    self.appDelegate?.networkingProcessUpload?.createProcessUploads(metadatas: metadatas, completion: completion)
-                }
-            }
-        }
-    }
-
-    // MARK: -
-
-    func createBackgroundProcessAutoUpload(metadatas: [tableMetadata], completion: @escaping (_ items: Int) -> Void) {
-
-        var metadatasForUpload: [tableMetadata] = []
-        var numStartUpload: Int = 0
-        let isWiFi = NCNetworking.shared.networkReachability == NKCommon.typeReachability.reachableEthernetOrWiFi
-
-        for metadata in metadatas {
-            if NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ && serverUrl == %@ && fileName == %@ && session != ''", metadata.account, metadata.serverUrl, metadata.fileName)) != nil { continue }
-            metadatasForUpload.append(metadata)
-        }
-        NCManageDatabase.shared.addMetadatas(metadatasForUpload)
-
-        let metadatasInUpload = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "status == %d OR status == %d", NCGlobal.shared.metadataStatusInUpload, NCGlobal.shared.metadataStatusUploading))
-        let counterUpload = NCGlobal.shared.maxConcurrentOperationUpload - metadatasInUpload.count
-        if counterUpload <= 0 { return completion(0) }
-
-        // Extract file
-        let metadatas = NCManageDatabase.shared.getAdvancedMetadatas(predicate: NSPredicate(format: "sessionSelector == %@ AND status == %d", NCGlobal.shared.selectorUploadAutoUpload, NCGlobal.shared.metadataStatusWaitUpload), page: 0, limit: counterUpload, sorted: "date", ascending: true)
-        for metadata in metadatas {
-
-            let metadata = tableMetadata.init(value: metadata)
-            let semaphore = DispatchSemaphore(value: 0)
-
-            NCUtility.shared.extractFiles(from: metadata) { metadatas in
-                if metadatas.isEmpty {
-                    NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-                }
+                var metadatasForUpload: [tableMetadata] = []
                 for metadata in metadatas {
-                    if (metadata.e2eEncrypted || metadata.chunk) {  continue }
-                    if (metadata.session == NCNetworking.shared.sessionIdentifierBackgroundWWan && !isWiFi) { continue }
-                    guard let metadata = NCManageDatabase.shared.setMetadataStatus(ocId: metadata.ocId, status: NCGlobal.shared.metadataStatusInUpload) else { continue }
-                    // Upload
-                    let semaphoreUpload = DispatchSemaphore(value: 1)
-                    NCNetworking.shared.upload(metadata: metadata) {
-                        numStartUpload += 1
-                    } completion: { error in
-                        semaphoreUpload.signal()
-                    }
-                    semaphoreUpload.wait()
+                    if NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ && serverUrl == %@ && fileName == %@ && session != ''", metadata.account, metadata.serverUrl, metadata.fileName)) != nil { continue }
+                    metadatasForUpload.append(metadata)
                 }
-                semaphore.signal()
+                NCManageDatabase.shared.addMetadatas(metadatasForUpload)
+                NCNetworking.shared.createUploadProcessAutoUpload(completion: completion)
             }
-            semaphore.wait()
         }
-        completion(numStartUpload)
     }
 
     // MARK: -

+ 42 - 4
iOSClient/Networking/NCNetworking.swift

@@ -168,16 +168,14 @@ import Photos
 
         #if !EXTENSION
         defer {
-            DispatchQueue.main.async {
-                if !isTrusted {
+            if !isTrusted {
+                DispatchQueue.main.async {
                     (UIApplication.shared.delegate as? AppDelegate)?.trustCertificateError(host: host)
                 }
             }
         }
         #endif
         
-        print("SSL host: \(host)")
-        
         if let serverTrust: SecTrust = protectionSpace.serverTrust, let certificate = SecTrustGetCertificateAtIndex(serverTrust, 0)  {
             
             // extarct certificate txt
@@ -599,6 +597,46 @@ import Photos
         }
     }
 
+    func createUploadProcessAutoUpload(completion: @escaping (_ items: Int) -> Void) {
+
+        var numStartUpload: Int = 0
+        let isWiFi = NCNetworking.shared.networkReachability == NKCommon.typeReachability.reachableEthernetOrWiFi
+
+        let metadatasInUpload = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "status == %d OR status == %d", NCGlobal.shared.metadataStatusInUpload, NCGlobal.shared.metadataStatusUploading))
+        let counterUpload = NCGlobal.shared.maxConcurrentOperationUpload - metadatasInUpload.count
+        if counterUpload <= 0 { return completion(0) }
+
+        // Extract file
+        let metadatas = NCManageDatabase.shared.getAdvancedMetadatas(predicate: NSPredicate(format: "sessionSelector == %@ AND status == %d", NCGlobal.shared.selectorUploadAutoUpload, NCGlobal.shared.metadataStatusWaitUpload), page: 0, limit: counterUpload, sorted: "date", ascending: true)
+        for metadata in metadatas {
+
+            let metadata = tableMetadata.init(value: metadata)
+            let semaphore = DispatchSemaphore(value: 0)
+
+            NCUtility.shared.extractFiles(from: metadata) { metadatas in
+                if metadatas.isEmpty {
+                    NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
+                }
+                for metadata in metadatas {
+                    if (metadata.e2eEncrypted || metadata.chunk) {  continue }
+                    if (metadata.session == NCNetworking.shared.sessionIdentifierBackgroundWWan && !isWiFi) { continue }
+                    guard let metadata = NCManageDatabase.shared.setMetadataStatus(ocId: metadata.ocId, status: NCGlobal.shared.metadataStatusInUpload) else { continue }
+                    // Upload
+                    let semaphoreUpload = DispatchSemaphore(value: 1)
+                    NCNetworking.shared.upload(metadata: metadata) {
+                        numStartUpload += 1
+                    } completion: { error in
+                        semaphoreUpload.signal()
+                    }
+                    semaphoreUpload.wait()
+                }
+                semaphore.signal()
+            }
+            semaphore.wait()
+        }
+        completion(numStartUpload)
+    }
+    
     func getOcIdInBackgroundSession(queue: DispatchQueue = .main, completion: @escaping (_ listOcId: [String]) -> Void) {
 
         var listOcId: [String] = []

+ 1 - 1
iOSClient/Settings/CCAdvanced.m

@@ -416,7 +416,7 @@
     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_delete_cache_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
     
     [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_yes_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-        [[NCActivityIndicator shared] startActivityWithBackgroundView:nil style: UIActivityIndicatorViewStyleWhiteLarge];
+        [[NCActivityIndicator shared] startActivityWithBackgroundView:nil style: UIActivityIndicatorViewStyleLarge];
         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
             [self clearCache];
         });