فهرست منبع

coding

Signed-off-by: Marino Faggiana <8616947+marinofaggiana@users.noreply.github.com>
Marino Faggiana 1 سال پیش
والد
کامیت
64ab1588f8

+ 28 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -549,6 +549,10 @@
 		F7A321AD1E9E6AD50069AD1B /* CCAdvanced.m in Sources */ = {isa = PBXBuildFile; fileRef = F7A321AC1E9E6AD50069AD1B /* CCAdvanced.m */; };
 		F7A48413297022E000BD1B49 /* ViewerQuickLook.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A48412297022E000BD1B49 /* ViewerQuickLook.swift */; };
 		F7A48415297028FC00BD1B49 /* Nextcloud Hub.png in Resources */ = {isa = PBXBuildFile; fileRef = F7A48414297028FC00BD1B49 /* Nextcloud Hub.png */; };
+		F7A560422AE1593700BE8FD6 /* NCOperationSaveLivePhoto.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A560412AE1593700BE8FD6 /* NCOperationSaveLivePhoto.swift */; };
+		F7A560442AE15D2900BE8FD6 /* Queuer in Frameworks */ = {isa = PBXBuildFile; productRef = F7A560432AE15D2900BE8FD6 /* Queuer */; };
+		F7A560462AE15D3D00BE8FD6 /* Queuer in Frameworks */ = {isa = PBXBuildFile; productRef = F7A560452AE15D3D00BE8FD6 /* Queuer */; };
+		F7A560482AE15D5000BE8FD6 /* Queuer in Frameworks */ = {isa = PBXBuildFile; productRef = F7A560472AE15D5000BE8FD6 /* Queuer */; };
 		F7A60F86292D215000FCE1F2 /* NCShareAccounts.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A60F84292D215000FCE1F2 /* NCShareAccounts.swift */; };
 		F7A60F87292D215000FCE1F2 /* NCShareAccounts.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7A60F85292D215000FCE1F2 /* NCShareAccounts.storyboard */; };
 		F7A76DC8256A71CD00119AB3 /* UIImage+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7B7504A2397D38E004E13EC /* UIImage+Extension.swift */; };
@@ -1171,6 +1175,7 @@
 		F7A321AC1E9E6AD50069AD1B /* CCAdvanced.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCAdvanced.m; sourceTree = "<group>"; };
 		F7A48412297022E000BD1B49 /* ViewerQuickLook.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewerQuickLook.swift; sourceTree = "<group>"; };
 		F7A48414297028FC00BD1B49 /* Nextcloud Hub.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Nextcloud Hub.png"; sourceTree = SOURCE_ROOT; };
+		F7A560412AE1593700BE8FD6 /* NCOperationSaveLivePhoto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCOperationSaveLivePhoto.swift; sourceTree = "<group>"; };
 		F7A60F84292D215000FCE1F2 /* NCShareAccounts.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCShareAccounts.swift; sourceTree = "<group>"; };
 		F7A60F85292D215000FCE1F2 /* NCShareAccounts.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = NCShareAccounts.storyboard; sourceTree = "<group>"; };
 		F7A7FA6229265CF4000603EF /* NCManageE2EE.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCManageE2EE.swift; sourceTree = "<group>"; };
@@ -1444,6 +1449,7 @@
 				F72CD01227A7E92400E59476 /* JGProgressHUD in Frameworks */,
 				F77CB6A92AA08053000C3CA4 /* OpenSSL in Frameworks */,
 				F73ADD2126554F8E0069EA0D /* SwiftEntryKit in Frameworks */,
+				F7A560482AE15D5000BE8FD6 /* Queuer in Frameworks */,
 				F7EBCDCF277B81FF00A4EF67 /* UICKeyChainStore in Frameworks */,
 				F70821D829E59E6D001CA2D7 /* TagListView in Frameworks */,
 				F7F623B72A5EFA0C0022D3D4 /* Gzip in Frameworks */,
@@ -1460,6 +1466,7 @@
 				F783034428B5142B00B84583 /* NextcloudKit in Frameworks */,
 				F7346E1328B0EF5B006CE2D2 /* SwiftUI.framework in Frameworks */,
 				F7346E2928B0FFF2006CE2D2 /* RealmSwift in Frameworks */,
+				F7A560462AE15D3D00BE8FD6 /* Queuer in Frameworks */,
 				F783030D28B4C59A00B84583 /* SwiftEntryKit in Frameworks */,
 				F7346E1228B0EF5B006CE2D2 /* WidgetKit.framework in Frameworks */,
 			);
@@ -1469,6 +1476,7 @@
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				F7A560442AE15D2900BE8FD6 /* Queuer in Frameworks */,
 				F7EBCDD1277B820D00A4EF67 /* UICKeyChainStore in Frameworks */,
 				F73ADD2426554FE20069EA0D /* SwiftEntryKit in Frameworks */,
 				F710FC84277B7D3500AA9FBF /* RealmSwift in Frameworks */,
@@ -1552,6 +1560,7 @@
 				AF93471127E2341B002537EE /* NCShare+Menu.swift */,
 				F710D2012405826100A6033D /* NCViewer+Menu.swift */,
 				F78C6FDD296D677300C952C3 /* NCContextMenu.swift */,
+				F7A560412AE1593700BE8FD6 /* NCOperationSaveLivePhoto.swift */,
 			);
 			path = Menu;
 			sourceTree = "<group>";
@@ -2793,6 +2802,7 @@
 				F70821D729E59E6D001CA2D7 /* TagListView */,
 				F7F623B62A5EFA0C0022D3D4 /* Gzip */,
 				F77CB6A82AA08053000C3CA4 /* OpenSSL */,
+				F7A560472AE15D5000BE8FD6 /* Queuer */,
 			);
 			productName = "Share Ext";
 			productReference = F7CE8AFB1DC1F8D8009CAE48 /* Share.appex */;
@@ -2817,6 +2827,7 @@
 				F783030C28B4C59A00B84583 /* SwiftEntryKit */,
 				F783034328B5142B00B84583 /* NextcloudKit */,
 				F787AC0A298BCB540001BB00 /* SVGKitSwift */,
+				F7A560452AE15D3D00BE8FD6 /* Queuer */,
 			);
 			productName = DashboardWidgetExtension;
 			productReference = F7346E1028B0EF5B006CE2D2 /* Widget.appex */;
@@ -2840,6 +2851,7 @@
 				F710FC83277B7D3500AA9FBF /* RealmSwift */,
 				F7EBCDD0277B820D00A4EF67 /* UICKeyChainStore */,
 				F72AD71228C24BCC006CB92D /* NextcloudKit */,
+				F7A560432AE15D2900BE8FD6 /* Queuer */,
 			);
 			productName = "File Provider Extension";
 			productReference = F771E3D020E2392D00AFB62D /* File Provider Extension.appex */;
@@ -3776,6 +3788,7 @@
 				F70CAE3A1F8CF31A008125FD /* NCEndToEndEncryption.m in Sources */,
 				AF93471B27E2361E002537EE /* NCShareAdvancePermission.swift in Sources */,
 				F77BC3ED293E528A005F2B08 /* NCConfigServer.swift in Sources */,
+				F7A560422AE1593700BE8FD6 /* NCOperationSaveLivePhoto.swift in Sources */,
 				F70753EB2542A99800972D44 /* NCViewerMediaPage.swift in Sources */,
 				F7817CF829801A3500FFBC65 /* Data+Extension.swift in Sources */,
 				F749B651297B0F2400087535 /* NCManageDatabase+Avatar.swift in Sources */,
@@ -5427,6 +5440,21 @@
 			package = F7A1050C29E587AF00FFD92B /* XCRemoteSwiftPackageReference "TagListView" */;
 			productName = TagListView;
 		};
+		F7A560432AE15D2900BE8FD6 /* Queuer */ = {
+			isa = XCSwiftPackageProductDependency;
+			package = F76DA961277B760E0082465B /* XCRemoteSwiftPackageReference "Queuer" */;
+			productName = Queuer;
+		};
+		F7A560452AE15D3D00BE8FD6 /* Queuer */ = {
+			isa = XCSwiftPackageProductDependency;
+			package = F76DA961277B760E0082465B /* XCRemoteSwiftPackageReference "Queuer" */;
+			productName = Queuer;
+		};
+		F7A560472AE15D5000BE8FD6 /* Queuer */ = {
+			isa = XCSwiftPackageProductDependency;
+			package = F76DA961277B760E0082465B /* XCRemoteSwiftPackageReference "Queuer" */;
+			productName = Queuer;
+		};
 		F7A8D72328F1771B008BBE1C /* NextcloudKit */ = {
 			isa = XCSwiftPackageProductDependency;
 			package = F783034028B511D200B84583 /* XCRemoteSwiftPackageReference "NextcloudKit" */;

+ 3 - 1
iOSClient/Files/NCFiles.swift

@@ -165,7 +165,9 @@ class NCFiles: NCCollectionViewCommon {
         networkReadFolder(isForced: isForced) { tableDirectory, metadatas, metadatasUpdate, metadatasDelete, error in
             if error == .success {
                 for metadata in metadatas ?? [] where !metadata.directory && NCManageDatabase.shared.isDownloadMetadata(metadata, download: false) {
-                    NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorDownloadFile)
+                    if self.appDelegate.downloadQueue.operations.filter({ ($0 as? NCOperationDownload)?.metadata.ocId == metadata.ocId }).isEmpty {
+                        self.appDelegate.downloadQueue.addOperation(NCOperationDownload(metadata: metadata, selector: NCGlobal.shared.selectorDownloadFile))
+                    }
                 }
             }
 

+ 3 - 1
iOSClient/Menu/NCContextMenu.swift

@@ -98,7 +98,9 @@ class NCContextMenu: NSObject {
         let save = UIAction(title: titleSave,
                             image: UIImage(systemName: "square.and.arrow.down")) { _ in
             if let metadataMOV = metadataMOV {
-                NCOperationQueue.shared.saveLivePhoto(metadata: metadata, metadataMOV: metadataMOV)
+                if let appDelegate = (UIApplication.shared.delegate as? AppDelegate) {
+                    appDelegate.saveLivePhotoQueue.addOperation(NCOperationSaveLivePhoto(metadata: metadata, metadataMOV: metadataMOV))
+                }
             } else {
                 if CCUtility.fileProviderStorageExists(metadata) {
                     NCActionCenter.shared.saveAlbum(metadata: metadata)

+ 6 - 2
iOSClient/Menu/NCMenuAction.swift

@@ -222,12 +222,16 @@ extension NCMenuAction {
             action: { _ in
                 for metadata in selectedMediaMetadatas {
                     if let metadataMOV = NCManageDatabase.shared.getMetadataLivePhoto(metadata: metadata) {
-                        NCOperationQueue.shared.saveLivePhoto(metadata: metadata, metadataMOV: metadataMOV)
+                        if let appDelegate = (UIApplication.shared.delegate as? AppDelegate) {
+                            appDelegate.saveLivePhotoQueue.addOperation(NCOperationSaveLivePhoto(metadata: metadata, metadataMOV: metadataMOV))
+                        }
                     } else {
                         if CCUtility.fileProviderStorageExists(metadata) {
                             NCActionCenter.shared.saveAlbum(metadata: metadata)
                         } else {
-                            NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorSaveAlbum)
+                            if let appDelegate = (UIApplication.shared.delegate as? AppDelegate), appDelegate.downloadQueue.operations.filter({ ($0 as? NCOperationDownload)?.metadata.ocId == metadata.ocId }).isEmpty {
+                                appDelegate.downloadQueue.addOperation(NCOperationDownload(metadata: metadata, selector: NCGlobal.shared.selectorSaveAlbum))
+                            }
                         }
                     }
                 }

+ 124 - 0
iOSClient/Menu/NCOperationSaveLivePhoto.swift

@@ -0,0 +1,124 @@
+//
+//  NCooo.swift
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 19/10/23.
+//  Copyright © 2023 Marino Faggiana. All rights reserved.
+//
+//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+
+import UIKit
+import Queuer
+import JGProgressHUD
+
+class NCOperationSaveLivePhoto: ConcurrentOperation {
+
+    var metadata: tableMetadata
+    var metadataMOV: tableMetadata
+    let hud = JGProgressHUD()
+    let appDelegate = UIApplication.shared.delegate as? AppDelegate
+
+    init(metadata: tableMetadata, metadataMOV: tableMetadata) {
+        self.metadata = tableMetadata.init(value: metadata)
+        self.metadataMOV = tableMetadata.init(value: metadataMOV)
+    }
+
+    override func start() {
+        guard !isCancelled else { return self.finish() }
+
+        DispatchQueue.main.async {
+            self.hud.indicatorView = JGProgressHUDRingIndicatorView()
+            if let indicatorView = self.hud.indicatorView as? JGProgressHUDRingIndicatorView {
+                indicatorView.ringWidth = 1.5
+            }
+            self.hud.textLabel.text = NSLocalizedString("_download_image_", comment: "")
+            self.hud.detailTextLabel.text = self.metadata.fileName
+            self.hud.show(in: (self.appDelegate?.window?.rootViewController?.view)!)
+        }
+
+        NCNetworking.shared.download(metadata: metadata, selector: "", notificationCenterProgressTask: false, checkfileProviderStorageExists: true) { _ in
+        } progressHandler: { progress in
+            self.hud.progress = Float(progress.fractionCompleted)
+        } completion: { _, error in
+            guard error == .success else {
+                DispatchQueue.main.async {
+                    self.hud.indicatorView = JGProgressHUDErrorIndicatorView()
+                    self.hud.textLabel.text = NSLocalizedString("_livephoto_save_error_", comment: "")
+                    self.hud.dismiss()
+                }
+                return self.finish()
+            }
+            NCNetworking.shared.download(metadata: self.metadataMOV, selector: "", notificationCenterProgressTask: false, checkfileProviderStorageExists: true) { _ in
+                DispatchQueue.main.async {
+                    self.hud.textLabel.text = NSLocalizedString("_download_video_", comment: "")
+                    self.hud.detailTextLabel.text = self.metadataMOV.fileName
+                }
+            } progressHandler: { progress in
+                self.hud.progress = Float(progress.fractionCompleted)
+            } completion: { _, error in
+                guard error == .success else {
+                    DispatchQueue.main.async {
+                        self.hud.indicatorView = JGProgressHUDErrorIndicatorView()
+                        self.hud.textLabel.text = NSLocalizedString("_livephoto_save_error_", comment: "")
+                        self.hud.dismiss()
+                    }
+                    return self.finish()
+                }
+                self.saveLivePhotoToDisk(metadata: self.metadata, metadataMov: self.metadataMOV)
+            }
+        }
+    }
+
+    func saveLivePhotoToDisk(metadata: tableMetadata, metadataMov: tableMetadata) {
+
+        let fileNameImage = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!)
+        let fileNameMov = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadataMov.ocId, fileNameView: metadataMov.fileNameView)!)
+
+        DispatchQueue.main.async {
+            self.hud.textLabel.text = NSLocalizedString("_livephoto_save_", comment: "")
+            self.hud.detailTextLabel.text = ""
+        }
+
+        NCLivePhoto.generate(from: fileNameImage, videoURL: fileNameMov, progress: { progress in
+            self.hud.progress = Float(progress)
+        }, completion: { _, resources in
+            if resources != nil {
+                NCLivePhoto.saveToLibrary(resources!) { result in
+                    DispatchQueue.main.async {
+                        if !result {
+                            self.hud.indicatorView = JGProgressHUDErrorIndicatorView()
+                            self.hud.textLabel.text = NSLocalizedString("_livephoto_save_error_", comment: "")
+                        } else {
+                            self.hud.indicatorView = JGProgressHUDSuccessIndicatorView()
+                            self.hud.textLabel.text = NSLocalizedString("_success_", comment: "")
+                        }
+                        self.hud.dismiss()
+                    }
+                    return self.finish()
+                }
+            } else {
+                DispatchQueue.main.async {
+                    self.hud.indicatorView = JGProgressHUDErrorIndicatorView()
+                    self.hud.textLabel.text = NSLocalizedString("_livephoto_save_error_", comment: "")
+                    self.hud.dismiss()
+                }
+                return self.finish()
+            }
+        })
+    }
+}

+ 28 - 2
iOSClient/Networking/NCNetworking.swift

@@ -26,6 +26,7 @@ import OpenSSL
 import NextcloudKit
 import Alamofire
 import Photos
+import Queuer
 
 @objc public protocol NCNetworkingDelegate {
     @objc optional func downloadProgress(_ progress: Float, totalBytes: Int64, totalBytesExpected: Int64, fileName: String, serverUrl: String, session: URLSession, task: URLSessionTask)
@@ -958,8 +959,11 @@ class NCNetworking: NSObject, NKCommonDelegate {
                         if metadata.directory {
                             let serverUrl = metadata.serverUrl + "/" + metadata.fileName
                             NCManageDatabase.shared.addDirectory(encrypted: metadata.e2eEncrypted, favorite: metadata.favorite, ocId: metadata.ocId, fileId: metadata.fileId, etag: metadata.etag, permissions: metadata.permissions, serverUrl: serverUrl, account: metadata.account)
-                        } else if selector == NCGlobal.shared.selectorSynchronizationOffline, NCManageDatabase.shared.isDownloadMetadata(metadata, download: true) {
-                            NCOperationQueue.shared.download(metadata: metadata, selector: selector)
+                        } else if selector == NCGlobal.shared.selectorSynchronizationOffline,
+                                  NCManageDatabase.shared.isDownloadMetadata(metadata, download: true),
+                                  let appDelegate = (UIApplication.shared.delegate as? AppDelegate),
+                                  appDelegate.downloadQueue.operations.filter({ ($0 as? NCOperationDownload)?.metadata.ocId == metadata.ocId }).isEmpty {
+                            appDelegate.downloadQueue.addOperation(NCOperationDownload(metadata: metadata, selector: selector))
                         }
                     }
                 }
@@ -1646,3 +1650,25 @@ extension Array where Element == URLQueryItem {
         first(where: { $0.name == name })
     }
 }
+
+// MARK: -
+
+class NCOperationDownload: ConcurrentOperation {
+
+    var metadata: tableMetadata
+    var selector: String
+
+    init(metadata: tableMetadata, selector: String) {
+        self.metadata = tableMetadata.init(value: metadata)
+        self.selector = selector
+    }
+
+    override func start() {
+
+        guard !isCancelled else { return self.finish() }
+
+        NCNetworking.shared.download(metadata: metadata, selector: self.selector) { _, _ in
+            self.finish()
+        }
+    }
+}

+ 0 - 134
iOSClient/Networking/NCOperationQueue.swift

@@ -34,13 +34,7 @@ import JGProgressHUD
 
     let appDelegate = (UIApplication.shared.delegate as? AppDelegate)!
 
-    // MARK: - Download file
 
-    func download(metadata: tableMetadata, selector: String) {
-
-        for case let operation as NCOperationDownload in appDelegate.downloadQueue.operations where operation.metadata.ocId == metadata.ocId { return }
-        appDelegate.downloadQueue.addOperation(NCOperationDownload(metadata: metadata, selector: selector))
-    }
 
     // MARK: - Download Avatar
 
@@ -64,36 +58,6 @@ import JGProgressHUD
         for case let operation as NCOperationDownloadAvatar in appDelegate.downloadAvatarQueue.operations where operation.fileName == fileName { return }
         appDelegate.downloadAvatarQueue.addOperation(NCOperationDownloadAvatar(user: user, fileName: fileName, fileNameLocalPath: fileNameLocalPath, cell: cell, view: view, cellImageView: cellImageView))
     }
-
-    // MARK: - Save Live Photo
-
-    func saveLivePhoto(metadata: tableMetadata, metadataMOV: tableMetadata) {
-
-        for case let operation as NCOperationSaveLivePhoto in appDelegate.saveLivePhotoQueue.operations where operation.metadata.fileName == metadata.fileName { return }
-        appDelegate.saveLivePhotoQueue.addOperation(NCOperationSaveLivePhoto(metadata: metadata, metadataMOV: metadataMOV))
-    }
-}
-
-// MARK: -
-
-class NCOperationDownload: ConcurrentOperation {
-
-    var metadata: tableMetadata
-    var selector: String
-
-    init(metadata: tableMetadata, selector: String) {
-        self.metadata = tableMetadata.init(value: metadata)
-        self.selector = selector
-    }
-
-    override func start() {
-
-        guard !isCancelled else { return self.finish() }
-
-        NCNetworking.shared.download(metadata: metadata, selector: self.selector) { _, _ in
-            self.finish()
-        }
-    }
 }
 
 // MARK: -
@@ -154,101 +118,3 @@ class NCOperationDownloadAvatar: ConcurrentOperation {
     }
 }
 
-// MARK: -
-
-class NCOperationSaveLivePhoto: ConcurrentOperation {
-
-    var metadata: tableMetadata
-    var metadataMOV: tableMetadata
-    let hud = JGProgressHUD()
-    let appDelegate = UIApplication.shared.delegate as? AppDelegate
-
-    init(metadata: tableMetadata, metadataMOV: tableMetadata) {
-        self.metadata = tableMetadata.init(value: metadata)
-        self.metadataMOV = tableMetadata.init(value: metadataMOV)
-    }
-
-    override func start() {
-        guard !isCancelled else { return self.finish() }
-
-        DispatchQueue.main.async {
-            self.hud.indicatorView = JGProgressHUDRingIndicatorView()
-            if let indicatorView = self.hud.indicatorView as? JGProgressHUDRingIndicatorView {
-                indicatorView.ringWidth = 1.5
-            }
-            self.hud.textLabel.text = NSLocalizedString("_download_image_", comment: "")
-            self.hud.detailTextLabel.text = self.metadata.fileName
-            self.hud.show(in: (self.appDelegate?.window?.rootViewController?.view)!)
-        }
-
-        NCNetworking.shared.download(metadata: metadata, selector: "", notificationCenterProgressTask: false, checkfileProviderStorageExists: true) { _ in
-        } progressHandler: { progress in
-            self.hud.progress = Float(progress.fractionCompleted)
-        } completion: { _, error in
-            guard error == .success else {
-                DispatchQueue.main.async {
-                    self.hud.indicatorView = JGProgressHUDErrorIndicatorView()
-                    self.hud.textLabel.text = NSLocalizedString("_livephoto_save_error_", comment: "")
-                    self.hud.dismiss()
-                }
-                return self.finish()
-            }
-            NCNetworking.shared.download(metadata: self.metadataMOV, selector: "", notificationCenterProgressTask: false, checkfileProviderStorageExists: true) { _ in
-                DispatchQueue.main.async {
-                    self.hud.textLabel.text = NSLocalizedString("_download_video_", comment: "")
-                    self.hud.detailTextLabel.text = self.metadataMOV.fileName
-                }
-            } progressHandler: { progress in
-                self.hud.progress = Float(progress.fractionCompleted)
-            } completion: { _, error in
-                guard error == .success else {
-                    DispatchQueue.main.async {
-                        self.hud.indicatorView = JGProgressHUDErrorIndicatorView()
-                        self.hud.textLabel.text = NSLocalizedString("_livephoto_save_error_", comment: "")
-                        self.hud.dismiss()
-                    }
-                    return self.finish()
-                }
-                self.saveLivePhotoToDisk(metadata: self.metadata, metadataMov: self.metadataMOV)
-            }
-        }
-    }
-
-    func saveLivePhotoToDisk(metadata: tableMetadata, metadataMov: tableMetadata) {
-
-        let fileNameImage = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!)
-        let fileNameMov = URL(fileURLWithPath: CCUtility.getDirectoryProviderStorageOcId(metadataMov.ocId, fileNameView: metadataMov.fileNameView)!)
-
-        DispatchQueue.main.async {
-            self.hud.textLabel.text = NSLocalizedString("_livephoto_save_", comment: "")
-            self.hud.detailTextLabel.text = ""
-        }
-
-        NCLivePhoto.generate(from: fileNameImage, videoURL: fileNameMov, progress: { progress in
-            self.hud.progress = Float(progress)
-        }, completion: { _, resources in
-            if resources != nil {
-                NCLivePhoto.saveToLibrary(resources!) { result in
-                    DispatchQueue.main.async {
-                        if !result {
-                            self.hud.indicatorView = JGProgressHUDErrorIndicatorView()
-                            self.hud.textLabel.text = NSLocalizedString("_livephoto_save_error_", comment: "")
-                        } else {
-                            self.hud.indicatorView = JGProgressHUDSuccessIndicatorView()
-                            self.hud.textLabel.text = NSLocalizedString("_success_", comment: "")
-                        }
-                        self.hud.dismiss()
-                    }
-                    return self.finish()
-                }
-            } else {
-                DispatchQueue.main.async {
-                    self.hud.indicatorView = JGProgressHUDErrorIndicatorView()
-                    self.hud.textLabel.text = NSLocalizedString("_livephoto_save_error_", comment: "")
-                    self.hud.dismiss()
-                }
-                return self.finish()
-            }
-        })
-    }
-}

+ 3 - 2
iOSClient/Networking/NCService.swift

@@ -309,8 +309,9 @@ class NCService: NSObject {
         let files = NCManageDatabase.shared.getTableLocalFiles(predicate: NSPredicate(format: "account == %@ AND offline == true", account), sorted: "fileName", ascending: true)
         for file: tableLocalFile in files {
             guard let metadata = NCManageDatabase.shared.getMetadataFromOcId(file.ocId) else { continue }
-            if NCManageDatabase.shared.isDownloadMetadata(metadata, download: true) {
-                NCOperationQueue.shared.download(metadata: metadata, selector: NCGlobal.shared.selectorDownloadFile)
+            if NCManageDatabase.shared.isDownloadMetadata(metadata, download: true),
+               appDelegate.downloadQueue.operations.filter({ ($0 as? NCOperationDownload)?.metadata.ocId == metadata.ocId }).isEmpty {
+                appDelegate.downloadQueue.addOperation(NCOperationDownload(metadata: metadata, selector: NCGlobal.shared.selectorDownloadFile))
             }
         }
         NextcloudKit.shared.nkCommonInstance.writeLog("[INFO] end synchronize offline")

+ 20 - 10
iOSClient/Viewer/NCViewerProviderContextMenu.swift

@@ -116,28 +116,38 @@ class NCViewerProviderContextMenu: UIViewController {
                         maxDownload = NCGlobal.shared.maxAutoDownload
                     }
 
-                    if metadata.size <= maxDownload {
-                        NCOperationQueue.shared.download(metadata: metadata, selector: "")
+                    if metadata.size <= maxDownload, 
+                       let appDelegate = (UIApplication.shared.delegate as? AppDelegate),
+                       appDelegate.downloadQueue.operations.filter({ ($0 as? NCOperationDownload)?.metadata.ocId == metadata.ocId }).isEmpty {
+                        appDelegate.downloadQueue.addOperation(NCOperationDownload(metadata: metadata, selector: ""))
                     }
                 }
             }
 
             // AUTO DOWNLOAD IMAGE GIF
-            if !CCUtility.fileProviderStorageExists(metadata) && metadata.contentType == "image/gif" {
-                NCOperationQueue.shared.download(metadata: metadata, selector: "")
+            if !CCUtility.fileProviderStorageExists(metadata),
+               metadata.contentType == "image/gif",
+               let appDelegate = (UIApplication.shared.delegate as? AppDelegate),
+               appDelegate.downloadQueue.operations.filter({ ($0 as? NCOperationDownload)?.metadata.ocId == metadata.ocId }).isEmpty {
+                appDelegate.downloadQueue.addOperation(NCOperationDownload(metadata: metadata, selector: ""))
             }
 
             // AUTO DOWNLOAD IMAGE SVG
-            if !CCUtility.fileProviderStorageExists(metadata) && metadata.contentType == "image/svg+xml" {
-                NCOperationQueue.shared.download(metadata: metadata, selector: "")
+            if !CCUtility.fileProviderStorageExists(metadata),
+               metadata.contentType == "image/svg+xml",
+               let appDelegate = (UIApplication.shared.delegate as? AppDelegate),
+               appDelegate.downloadQueue.operations.filter({ ($0 as? NCOperationDownload)?.metadata.ocId == metadata.ocId }).isEmpty {
+                appDelegate.downloadQueue.addOperation(NCOperationDownload(metadata: metadata, selector: ""))
             }
 
             // AUTO DOWNLOAD LIVE PHOTO
-            if let metadataLivePhoto = self.metadataLivePhoto {
-                if !CCUtility.fileProviderStorageExists(metadataLivePhoto) {
-                    NCOperationQueue.shared.download(metadata: metadataLivePhoto, selector: "")
-                }
+            if let metadataLivePhoto = self.metadataLivePhoto,
+               !CCUtility.fileProviderStorageExists(metadataLivePhoto),
+               let appDelegate = (UIApplication.shared.delegate as? AppDelegate),
+               appDelegate.downloadQueue.operations.filter({ ($0 as? NCOperationDownload)?.metadata.ocId == metadata.ocId }).isEmpty {
+                appDelegate.downloadQueue.addOperation(NCOperationDownload(metadata: metadataLivePhoto, selector: ""))
             }
+
         }
     }