Browse Source

Merge pull request #1857 from nextcloud/fix/share-extension

fix share extension
Henry 3 years ago
parent
commit
9f54a89e9e

+ 6 - 6
Nextcloud.xcodeproj/project.pbxproj

@@ -3051,7 +3051,7 @@
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				COPY_PHASE_STRIP = NO;
 				COPY_PHASE_STRIP = NO;
-				CURRENT_PROJECT_VERSION = 2;
+				CURRENT_PROJECT_VERSION = 3;
 				DEFINES_MODULE = YES;
 				DEFINES_MODULE = YES;
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
 				ENABLE_TESTABILITY = YES;
 				ENABLE_TESTABILITY = YES;
@@ -3117,7 +3117,7 @@
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				COPY_PHASE_STRIP = NO;
 				COPY_PHASE_STRIP = NO;
-				CURRENT_PROJECT_VERSION = 2;
+				CURRENT_PROJECT_VERSION = 3;
 				DEFINES_MODULE = YES;
 				DEFINES_MODULE = YES;
 				ENABLE_NS_ASSERTIONS = NO;
 				ENABLE_NS_ASSERTIONS = NO;
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -3245,8 +3245,8 @@
 			isa = XCRemoteSwiftPackageReference;
 			isa = XCRemoteSwiftPackageReference;
 			repositoryURL = "https://github.com/marinofaggiana/IHProgressHUD";
 			repositoryURL = "https://github.com/marinofaggiana/IHProgressHUD";
 			requirement = {
 			requirement = {
-				branch = master;
-				kind = branch;
+				kind = upToNextMajorVersion;
+				minimumVersion = 0.2.0;
 			};
 			};
 		};
 		};
 		F73ADD1A265546880069EA0D /* XCRemoteSwiftPackageReference "SwiftEntryKit" */ = {
 		F73ADD1A265546880069EA0D /* XCRemoteSwiftPackageReference "SwiftEntryKit" */ = {
@@ -3285,8 +3285,8 @@
 			isa = XCRemoteSwiftPackageReference;
 			isa = XCRemoteSwiftPackageReference;
 			repositoryURL = "https://github.com/rechsteiner/Parchment";
 			repositoryURL = "https://github.com/rechsteiner/Parchment";
 			requirement = {
 			requirement = {
-				kind = upToNextMajorVersion;
-				minimumVersion = 3.0.0;
+				kind = exactVersion;
+				version = 3.0.0;
 			};
 			};
 		};
 		};
 		F76DA961277B760E0082465B /* XCRemoteSwiftPackageReference "Queuer" */ = {
 		F76DA961277B760E0082465B /* XCRemoteSwiftPackageReference "Queuer" */ = {

+ 11 - 11
Nextcloud.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

@@ -60,8 +60,8 @@
         "repositoryURL": "https://github.com/firebase/firebase-ios-sdk",
         "repositoryURL": "https://github.com/firebase/firebase-ios-sdk",
         "state": {
         "state": {
           "branch": null,
           "branch": null,
-          "revision": "08686f04881483d2bc098b2696e674c0ba135e47",
-          "version": "8.10.0"
+          "revision": "5344857522053b5d4403ec8173ec0d23200a97ea",
+          "version": "8.11.0"
         }
         }
       },
       },
       {
       {
@@ -131,9 +131,9 @@
         "package": "IHProgressHUD",
         "package": "IHProgressHUD",
         "repositoryURL": "https://github.com/marinofaggiana/IHProgressHUD",
         "repositoryURL": "https://github.com/marinofaggiana/IHProgressHUD",
         "state": {
         "state": {
-          "branch": "master",
-          "revision": "a3d94dfb869ff9b2f9e5a4d0359a73a625072853",
-          "version": null
+          "branch": null,
+          "revision": "0805867f3eaa451bd0516ac352d3cf2c493b1444",
+          "version": "0.2.0"
         }
         }
       },
       },
       {
       {
@@ -186,8 +186,8 @@
         "repositoryURL": "https://github.com/rechsteiner/Parchment",
         "repositoryURL": "https://github.com/rechsteiner/Parchment",
         "state": {
         "state": {
           "branch": null,
           "branch": null,
-          "revision": "2b1a370e71480cb1a95dd56ef8bddc2e0a45e033",
-          "version": "3.1.0"
+          "revision": "df36404c683019d26c36bb0862350300e31f4688",
+          "version": "3.0.0"
         }
         }
       },
       },
       {
       {
@@ -231,8 +231,8 @@
         "repositoryURL": "https://github.com/realm/realm-core",
         "repositoryURL": "https://github.com/realm/realm-core",
         "state": {
         "state": {
           "branch": null,
           "branch": null,
-          "revision": "f1976f0d96d9b06fbe0afbd60090b1c3966b1e23",
-          "version": "11.8.0"
+          "revision": "6b81f1a7a2d421f9e0b9e7f04e76bcf736a54409",
+          "version": "11.9.0"
         }
         }
       },
       },
       {
       {
@@ -240,8 +240,8 @@
         "repositoryURL": "https://github.com/realm/realm-swift",
         "repositoryURL": "https://github.com/realm/realm-swift",
         "state": {
         "state": {
           "branch": null,
           "branch": null,
-          "revision": "39177714b95bb5b1b29fffe28f1c7da77eef8e8b",
-          "version": "10.21.1"
+          "revision": "9dff9f2862240d521ad6ad599541269177ddb993",
+          "version": "10.22.0"
         }
         }
       },
       },
       {
       {

+ 22 - 11
Share/NCShareExtension.swift

@@ -137,9 +137,8 @@ class NCShareExtension: UIViewController {
         }
         }
 
 
         // HUD
         // HUD
-        IHProgressHUD.set(viewForExtension: self.collectionView)
+        IHProgressHUD.set(viewForExtension: self.view)
         IHProgressHUD.set(defaultMaskType: .clear)
         IHProgressHUD.set(defaultMaskType: .clear)
-        IHProgressHUD.set(minimumDismiss: 0)
 
 
         NotificationCenter.default.addObserver(self, selector: #selector(triggerProgressTask(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterProgressTask), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(triggerProgressTask(_:)), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterProgressTask), object: nil)
     }
     }
@@ -150,13 +149,13 @@ class NCShareExtension: UIViewController {
 
 
         guard let activeAccount = NCManageDatabase.shared.getActiveAccount() else {
         guard let activeAccount = NCManageDatabase.shared.getActiveAccount() else {
             return showAlert(description: "_no_active_account_") {
             return showAlert(description: "_no_active_account_") {
-                self.cancel(with: NCShareExtensionError.noAccount)
+                self.cancel(with: .noAccount)
             }
             }
         }
         }
 
 
         accountRequestChangeAccount(account: activeAccount.account)
         accountRequestChangeAccount(account: activeAccount.account)
         guard let inputItems = extensionContext?.inputItems as? [NSExtensionItem] else {
         guard let inputItems = extensionContext?.inputItems as? [NSExtensionItem] else {
-            cancel(with: NCShareExtensionError.noFiles)
+            cancel(with: .noFiles)
             return
             return
         }
         }
         NCFilesExtensionHandler(items: inputItems) { fileNames in
         NCFilesExtensionHandler(items: inputItems) { fileNames in
@@ -178,16 +177,23 @@ class NCShareExtension: UIViewController {
         tableView.reloadData()
         tableView.reloadData()
     }
     }
 
 
+    override func viewWillDisappear(_ animated: Bool) {
+        super.viewWillDisappear(animated)
+        // remove all metadata in queue
+        for metadata in uploadMetadata {
+            let filePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
+            let path = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId)!
+            NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
+            NCNetworking.shared.uploadRequest[filePath]?.tasks.forEach({ $0.cancel() })
+            NCUtilityFileSystem.shared.deleteFile(filePath: path)
+        }
+    }
+
     // MARK: -
     // MARK: -
 
 
     func cancel(with error: NCShareExtensionError) {
     func cancel(with error: NCShareExtensionError) {
         // make sure no uploads are continued
         // make sure no uploads are continued
         uploadStarted = false
         uploadStarted = false
-        let metadata = uploadMetadata[counterUploaded]
-        let filePath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
-
-        NCManageDatabase.shared.deleteMetadata(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
-        NCNetworking.shared.uploadRequest[filePath]?.tasks.forEach({ $0.cancel() })
         extensionContext?.cancelRequest(withError: error)
         extensionContext?.cancelRequest(withError: error)
     }
     }
 
 
@@ -269,7 +275,7 @@ class NCShareExtension: UIViewController {
 
 
     func setCommandView() {
     func setCommandView() {
         guard !filesName.isEmpty else {
         guard !filesName.isEmpty else {
-            cancel(with: NCShareExtensionError.noFiles)
+            cancel(with: .noFiles)
             return
             return
         }
         }
         let counter = min(CGFloat(filesName.count), 3)
         let counter = min(CGFloat(filesName.count), 3)
@@ -288,7 +294,7 @@ class NCShareExtension: UIViewController {
     // MARK: ACTION
     // MARK: ACTION
 
 
     @IBAction func actionCancel(_ sender: UIBarButtonItem) {
     @IBAction func actionCancel(_ sender: UIBarButtonItem) {
-        cancel(with: NCShareExtensionError.cancel)
+        cancel(with: .cancel)
     }
     }
 
 
     @objc func actionCreateFolder() {
     @objc func actionCreateFolder() {
@@ -370,6 +376,11 @@ extension NCShareExtension {
         // CHUNCK
         // CHUNCK
         metadata.chunk = chunckSize != 0 && metadata.size > chunckSize
         metadata.chunk = chunckSize != 0 && metadata.size > chunckSize
 
 
+        if counterUploaded == 0 {
+            let status = NSLocalizedString("_upload_file_", comment: "") + " \(counterUploaded + 1) " + NSLocalizedString("_of_", comment: "") + " \(filesName.count)"
+            IHProgressHUD.show(withStatus: status)
+        }
+
         NCNetworking.shared.upload(metadata: metadata) { } completion: { errorCode, _ in
         NCNetworking.shared.upload(metadata: metadata) { } completion: { errorCode, _ in
             if errorCode == 0 {
             if errorCode == 0 {
                 self.counterUploaded += 1
                 self.counterUploaded += 1