marinofaggiana 4 years ago
parent
commit
5326b142a4

+ 1 - 1
iOSClient/Activity/NCActivity.swift

@@ -386,7 +386,7 @@ extension activityTableViewCell: UICollectionViewDelegate {
             
             let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(activitySubjectRich.id, fileNameView: activitySubjectRich.name)!
             
-            NCUtility.shared.startActivityIndicator(view: (appDelegate.window.rootViewController?.view)!)
+            NCUtility.shared.startActivityIndicator(view: (appDelegate.window?.rootViewController?.view)!)
             
             NCCommunication.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, requestHandler: { (_) in
                 

+ 19 - 3
iOSClient/AppDelegate.swift

@@ -9,8 +9,9 @@ import TOPasscodeViewController
 @UIApplicationMain
 class AppDelegate: UIResponder, UIApplicationDelegate {
 
-    var window: UIWindow!
-    
+    var window: UIWindow?
+    var backgroundSessionCompletionHandler: (() -> Void)?
+
     var account: String = ""
     var urlBase: String = ""
     var user: String = ""
@@ -75,7 +76,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
     
     // MARK: -
 
-    @objc func checkErrorNetworking() {
+    func openLoginView(viewController: UIViewController, selector: Int, openLoginWeb: Bool) {
         
     }
 
@@ -83,6 +84,21 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
         timerErrorNetworking = Timer.scheduledTimer(timeInterval: 3, target: self, selector: #selector(checkErrorNetworking), userInfo: nil, repeats: true)
     }
     
+    @objc func checkErrorNetworking() {
+        
+        if account == "" { return }
+        
+        // check unauthorized server (401)
+        if CCUtility.getPasscode()?.cont == 0 {
+            openLoginView(viewController: window.rootViewController, selector: NCBrandGlobal.shared.introLogin, openLoginWeb: true)
+        }
+        
+        // check certificate untrusted (-1202)
+        if CCUtility.getCertificateError(account) {
+            
+        }
+    }
+    
     // MARK: -
     
     func settingAccount(_ account: String, urlBase: String, user: String, userID: String, password: String) {

+ 2 - 2
iOSClient/Login/NCLoginWeb.swift

@@ -246,8 +246,8 @@ extension NCLoginWeb: WKNavigationDelegate {
                     viewController.modalPresentationStyle = .fullScreen
                     NotificationCenter.default.postOnMainThread(name: NCBrandGlobal.shared.notificationCenterInitializeMain)
                     viewController.view.alpha = 0
-                    appDelegate.window.rootViewController = viewController
-                    appDelegate.window.makeKeyAndVisible()
+                    appDelegate.window?.rootViewController = viewController
+                    appDelegate.window?.makeKeyAndVisible()
                     UIView.animate(withDuration: 0.5) {
                         viewController.view.alpha = 1
                     }

+ 2 - 2
iOSClient/Main/Colleaction Common/NCCollectionCommon.swift

@@ -205,7 +205,7 @@ class NCCollectionCommon: NSObject, NCSelectDelegate {
         navigationController.setViewControllers(listViewController, animated: false)
         navigationController.modalPresentationStyle = .formSheet
         
-        appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
+        appDelegate.window?.rootViewController?.present(navigationController, animated: true, completion: nil)
     }
     
     // MARK: - Save Photo - Video - Live Photo
@@ -255,7 +255,7 @@ class NCCollectionCommon: NSObject, NCSelectDelegate {
         }
         
         if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) && CCUtility.fileProviderStorageExists(metadataMOV.ocId, fileNameView: metadataMOV.fileNameView) {
-            saveLivePhotoToDisk(metadata: metadata, metadataMov: metadataMOV, progressView: nil, viewActivity: self.appDelegate.window.rootViewController?.view)
+            saveLivePhotoToDisk(metadata: metadata, metadataMov: metadataMOV, progressView: nil, viewActivity: self.appDelegate.window?.rootViewController?.view)
         }
     }
     

+ 2 - 2
iOSClient/Main/Create cloud/NCCreateFormUploadAssets.swift

@@ -456,7 +456,7 @@ class NCCreateFormUploadAssets: XLFormViewController, NCSelectDelegate {
                         conflict.metadatasMOV = metadatasMOV
                         conflict.metadatasUploadInConflict = metadatasUploadInConflict
                     
-                        self.appDelegate.window.rootViewController?.present(conflict, animated: true, completion: nil)
+                        self.appDelegate.window?.rootViewController?.present(conflict, animated: true, completion: nil)
                     }
                 }
                 
@@ -465,7 +465,7 @@ class NCCreateFormUploadAssets: XLFormViewController, NCSelectDelegate {
                 NCManageDatabase.shared.addMetadatas(metadatasNOConflict)
                 NCManageDatabase.shared.addMetadatas(metadatasMOV)
                 
-                self.appDelegate.networkingAutoUpload.startProcess()
+                self.appDelegate.networkingAutoUpload?.startProcess()
             }
         
             DispatchQueue.main.async {self.dismiss(animated: true, completion: nil)  }

+ 1 - 1
iOSClient/Main/Create cloud/NCCreateFormUploadVoiceNote.swift

@@ -259,7 +259,7 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAud
                    
         NCManageDatabase.shared.addMetadata(metadata)
                 
-        appDelegate.networkingAutoUpload.startProcess()
+        appDelegate.networkingAutoUpload?.startProcess()
         
         self.dismiss(animated: true, completion: nil)
     }

+ 17 - 14
iOSClient/Main/Menu/AppDelegate+Menu.swift

@@ -56,7 +56,9 @@ extension AppDelegate: NCAudioRecorderViewControllerDelegate {
                 title: NSLocalizedString("_upload_photos_videos_", comment: ""), icon: UIImage(named: "file_photo")!.image(color: NCBrandColor.shared.icon, size: 50), action: { menuAction in
                     NCAskAuthorization.shared.askAuthorizationPhotoLibrary(viewController: viewController) { (hasPermission) in
                         if hasPermission {
-                            NCPhotosPickerViewController.init(viewController: appDelegate.window.rootViewController!, maxSelectedAssets: 0, singleSelectedMode: false)
+                            if let viewController = appDelegate.window?.rootViewController {
+                                NCPhotosPickerViewController.init(viewController: viewController, maxSelectedAssets: 0, singleSelectedMode: false)
+                            }
                         }
                     }
                 }
@@ -66,7 +68,7 @@ extension AppDelegate: NCAudioRecorderViewControllerDelegate {
         actions.append(
             NCMenuAction(
                 title: NSLocalizedString("_upload_file_", comment: ""), icon: UIImage(named: "file")!.image(color: NCBrandColor.shared.icon, size: 50), action: { menuAction in
-                    if let tabBarController = self.window.rootViewController as? UITabBarController {
+                    if let tabBarController = self.window?.rootViewController as? UITabBarController {
                         self.documentPickerViewController = NCDocumentPickerViewController.init(tabBarController: tabBarController)
                     }
                 }
@@ -99,7 +101,7 @@ extension AppDelegate: NCAudioRecorderViewControllerDelegate {
                     viewController.serverUrl = appDelegate.activeServerUrl
                     viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
 
-                    appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
+                    appDelegate.window?.rootViewController?.present(navigationController, animated: true, completion: nil)
                 })
             )
         } 
@@ -108,7 +110,9 @@ extension AppDelegate: NCAudioRecorderViewControllerDelegate {
             actions.append(
                 NCMenuAction(
                     title: NSLocalizedString("_scans_document_", comment: ""), icon: UIImage(named: "scan")!.image(color: NCBrandColor.shared.icon, size: 50), action: { menuAction in
-                        NCCreateScanDocument.shared.openScannerDocument(viewController: appDelegate.window.rootViewController!)
+                        if let viewController = appDelegate.window?.rootViewController {
+                            NCCreateScanDocument.shared.openScannerDocument(viewController: viewController)
+                        }
                     }
                 )
             )
@@ -128,7 +132,7 @@ extension AppDelegate: NCAudioRecorderViewControllerDelegate {
                             viewController.modalTransitionStyle = .crossDissolve
                             viewController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
                         
-                            appDelegate.window.rootViewController?.present(viewController, animated: true, completion: nil)
+                            appDelegate.window?.rootViewController?.present(viewController, animated: true, completion: nil)
                         }
                     }
                 }
@@ -140,7 +144,6 @@ extension AppDelegate: NCAudioRecorderViewControllerDelegate {
                 icon: UIImage(named: "folder")!.image(color: NCBrandColor.shared.brandElement, size: 50), action: { menuAction in
                     
                     if appDelegate.activeServerUrl == "" { return }
-                     //guard let serverUrl = appDelegate.activeServerUrl else { return }
                     
                     let alertController = UIAlertController(title: NSLocalizedString("_create_folder_on_", comment: ""), message: nil, preferredStyle: .alert)
                     
@@ -162,7 +165,7 @@ extension AppDelegate: NCAudioRecorderViewControllerDelegate {
                     alertController.addAction(cancelAction)
                     alertController.addAction(okAction)
 
-                    appDelegate.window.rootViewController?.present(alertController, animated: true, completion: nil)
+                    appDelegate.window?.rootViewController?.present(alertController, animated: true, completion: nil)
                 }
             )
         )
@@ -201,7 +204,7 @@ extension AppDelegate: NCAudioRecorderViewControllerDelegate {
                         viewController.serverUrl = appDelegate.activeServerUrl
                         viewController.titleForm = NSLocalizedString("_create_new_document_", comment: "")
 
-                        appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
+                        appDelegate.window?.rootViewController?.present(navigationController, animated: true, completion: nil)
                     }
                 )
             )
@@ -224,7 +227,7 @@ extension AppDelegate: NCAudioRecorderViewControllerDelegate {
                         viewController.serverUrl = appDelegate.activeServerUrl
                         viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
 
-                        appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
+                        appDelegate.window?.rootViewController?.present(navigationController, animated: true, completion: nil)
                     }
                 )
             )
@@ -247,7 +250,7 @@ extension AppDelegate: NCAudioRecorderViewControllerDelegate {
                         viewController.serverUrl = appDelegate.activeServerUrl
                         viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
 
-                        appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
+                        appDelegate.window?.rootViewController?.present(navigationController, animated: true, completion: nil)
                     }
                 )
             )
@@ -269,7 +272,7 @@ extension AppDelegate: NCAudioRecorderViewControllerDelegate {
                             viewController.serverUrl = appDelegate.activeServerUrl
                             viewController.titleForm = NSLocalizedString("_create_nextcloudtext_document_", comment: "")
 
-                            appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
+                            appDelegate.window?.rootViewController?.present(navigationController, animated: true, completion: nil)
                         }
                     )
                 )
@@ -288,7 +291,7 @@ extension AppDelegate: NCAudioRecorderViewControllerDelegate {
                             viewController.serverUrl = appDelegate.activeServerUrl
                             viewController.titleForm = NSLocalizedString("_create_new_spreadsheet_", comment: "")
 
-                            appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
+                            appDelegate.window?.rootViewController?.present(navigationController, animated: true, completion: nil)
                         }
                     )
                 )
@@ -307,7 +310,7 @@ extension AppDelegate: NCAudioRecorderViewControllerDelegate {
                             viewController.serverUrl = appDelegate.activeServerUrl
                             viewController.titleForm = NSLocalizedString("_create_new_presentation_", comment: "")
 
-                            appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
+                            appDelegate.window?.rootViewController?.present(navigationController, animated: true, completion: nil)
                         }
                     )
                 )
@@ -327,7 +330,7 @@ extension AppDelegate: NCAudioRecorderViewControllerDelegate {
         
         let viewController = (navigationController as! UINavigationController).topViewController as! NCCreateFormUploadVoiceNote
         viewController.setup(serverUrl: appDelegate.activeServerUrl, fileNamePath: NSTemporaryDirectory() + fileName, fileName: fileName)
-        appDelegate.window.rootViewController?.present(navigationController, animated: true, completion: nil)
+        appDelegate.window?.rootViewController?.present(navigationController, animated: true, completion: nil)
     }
     
     func didFinishWithoutRecording(_ viewController: NCAudioRecorderViewController, fileName: String) { }

+ 2 - 2
iOSClient/Main/NCPickerViewController.swift

@@ -133,7 +133,7 @@ class NCDocumentPickerViewController: NSObject, UIDocumentPickerDelegate {
         documentProviderMenu.popoverPresentationController?.sourceRect = tabBarController.tabBar.bounds
         documentProviderMenu.delegate = self
         
-        appDelegate.window.rootViewController?.present(documentProviderMenu, animated: true, completion: nil)
+        appDelegate.window?.rootViewController?.present(documentProviderMenu, animated: true, completion: nil)
     }
     
     func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
@@ -168,7 +168,7 @@ class NCDocumentPickerViewController: NSObject, UIDocumentPickerDelegate {
                                 conflict.serverUrl = serverUrl
                                 conflict.metadatasUploadInConflict = [metadataForUpload]
                             
-                                appDelegate.window.rootViewController?.present(conflict, animated: true, completion: nil)
+                                appDelegate.window?.rootViewController?.present(conflict, animated: true, completion: nil)
                             }
                         
                         } else {

+ 4 - 3
iOSClient/More/NCMore.swift

@@ -302,8 +302,9 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
             cell.status.text = ""
             cell.displayName.text = ""
             
-            let fileNamePath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase) + "-" + appDelegate.user + ".png"
-
+            var fileNamePath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase) + "-" + appDelegate.user
+            fileNamePath = fileNamePath + ".png"
+            
             if let themingAvatarFile = UIImage.init(contentsOfFile: fileNamePath) {
                 cell.avatar?.image = themingAvatarFile
             } else {
@@ -417,7 +418,7 @@ class NCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
                 let manageAccount = CCManageAccount()
                 manageAccount.delete(self.appDelegate.account)
 
-                self.appDelegate.openLoginView(self, selector: NCBrandGlobal.shared.introLogin, openLoginWeb: false)
+                self.appDelegate.openLoginView(viewController:self, selector: NCBrandGlobal.shared.introLogin, openLoginWeb: false)
             }
 
             let actionNo = UIAlertAction(title: NSLocalizedString("_no_delete_", comment: ""), style: .default) { (action: UIAlertAction) in

+ 2 - 2
iOSClient/Networking/NCAutoUpload.swift

@@ -134,9 +134,9 @@ class NCAutoUpload: NSObject, CLLocationManagerDelegate {
     }
     
     @objc func autoUploadFullPhotos(viewController: UIViewController?, log: String) {
-        NCAskAuthorization.shared.askAuthorizationPhotoLibrary(viewController: appDelegate.window.rootViewController) { (hasPermission) in
+        NCAskAuthorization.shared.askAuthorizationPhotoLibrary(viewController: appDelegate.window?.rootViewController) { (hasPermission) in
             if hasPermission {
-                self.hud = CCHud.init(view: self.appDelegate.window.rootViewController?.view)
+                self.hud = CCHud.init(view: self.appDelegate.window?.rootViewController?.view)
                 NCContentPresenter.shared.messageNotification("_attention_", description: "_create_full_upload_", delay: NCBrandGlobal.shared.dismissAfterSecondLong, type: .info, errorCode: 0, forced: true)
                 self.hud?.visibleHudTitle(NSLocalizedString("_wait_", comment: ""), mode: MBProgressHUDMode.indeterminate, color: NCBrandColor.shared.brand)
                 

+ 1 - 1
iOSClient/Networking/NCNetworkingNotificationCenter.swift

@@ -127,7 +127,7 @@ import Foundation
                         }
                             
                         if CCUtility.fileProviderStorageExists(metadata.ocId, fileNameView: metadata.fileNameView) && CCUtility.fileProviderStorageExists(metadataMOV.ocId, fileNameView: metadataMOV.fileNameView) {
-                            NCCollectionCommon.shared.saveLivePhotoToDisk(metadata: metadata, metadataMov: metadataMOV, progressView: nil, viewActivity: self.appDelegate.window.rootViewController?.view)
+                            NCCollectionCommon.shared.saveLivePhotoToDisk(metadata: metadata, metadataMov: metadataMOV, progressView: nil, viewActivity: self.appDelegate.window?.rootViewController?.view)
                         }
                         
                     default:

+ 1 - 1
iOSClient/RichWorkspace/NCViewerRichWorkspace.swift

@@ -62,7 +62,7 @@ import MarkdownKit
                 guard let metadata = metadata else { return }
                 NCManageDatabase.shared.setDirectory(richWorkspace: metadata.richWorkspace, serverUrl: self.serverUrl, account: account)
                 if self.richWorkspaceText != metadata.richWorkspace && metadata.richWorkspace != nil {
-                    self.appDelegate.activeFiles.richWorkspaceText = self.richWorkspaceText
+                    self.appDelegate.activeFiles?.richWorkspaceText = self.richWorkspaceText
                     self.richWorkspaceText = metadata.richWorkspace!
                     self.textView.attributedText = self.markdownParser.parse(metadata.richWorkspace!)
                 }

+ 2 - 1
iOSClient/Select/NCSelect.swift

@@ -566,7 +566,8 @@ extension NCSelect: UICollectionViewDataSource {
                 cell.imageShared.image = NCCollectionCommon.images.cellCanShareImage
             }
             if metadata.ownerId.count > 0 && metadata.ownerId != appDelegate.userID {
-                let fileNameUser = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase) + "-" + metadata.ownerId + ".png"
+                var fileNameUser = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(appDelegate.user, urlBase: appDelegate.urlBase) + "-" + metadata.ownerId
+                fileNameUser = fileNameUser + ".png"
                 if FileManager.default.fileExists(atPath: fileNameUser) {
                     cell.imageShared.image = UIImage(contentsOfFile: fileNameUser)
                 } else {

+ 2 - 2
iOSClient/Settings/NCEndToEndInitialize.swift

@@ -187,7 +187,7 @@ class NCEndToEndInitialize : NSObject  {
                     passphraseTextField?.placeholder = "Enter passphrase (12 words)"
                 }
                 
-                self.appDelegate.window.rootViewController?.present(alertController, animated: true)
+                self.appDelegate.window?.rootViewController?.present(alertController, animated: true)
                 
             } else if errorCode != 0 {
                 
@@ -274,7 +274,7 @@ class NCEndToEndInitialize : NSObject  {
                     }
                     
                     alertController.addAction(OKAction)
-                    self.appDelegate.window.rootViewController?.present(alertController, animated: true)
+                    self.appDelegate.window?.rootViewController?.present(alertController, animated: true)
                     
                 case NCBrandGlobal.shared.ErrorConflict:
                     NCContentPresenter.shared.messageNotification("E2E get privateKey", description: "forbidden: the user can't access the private key", delay: NCBrandGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)