Преглед изворни кода

Improvements (#2600)

* fix

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>

* build 8

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>

* added NCTrash cancel, select all

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>

* cleaning

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>

* add separator

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>

* fix tip media only for image

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>

* replace OLD func useragent

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>

* lint

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>

* lint

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>

---------

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana пре 1 година
родитељ
комит
150510fa0f

+ 13 - 10
Brand/NCBrand.swift

@@ -23,7 +23,11 @@
 
 import UIKit
 
-// MARK: - Options
+let userAgent: String = {
+    let appVersion: String = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
+    // Original Nextcloud useragent "Mozilla/5.0 (iOS) Nextcloud-iOS/\(appVersion)"
+    return "Mozilla/5.0 (iOS) Nextcloud-iOS/\(appVersion)"
+}()
 
 @objc class NCBrandOptions: NSObject {
     @objc static let shared: NCBrandOptions = {
@@ -54,11 +58,8 @@ import UIKit
     @objc public var capabilitiesGroups: String = "group.it.twsweb.Crypto-Cloud"
     @objc public var capabilitiesGroupApps: String = "group.com.nextcloud.apps"
 
-    // User Agent
-    @objc public var userAgent: String = "Nextcloud-iOS"                                                            // Don't touch me !!
-
     // BRAND ONLY
-    @objc public var use_login_web_personalized: Bool = false                                                // Don't touch me !!
+    @objc public var use_login_web_personalized: Bool = false                                   // Don't touch me !!
     @objc public var use_AppConfig: Bool = false                                                // Don't touch me !!
     @objc public var use_GroupApps: Bool = true                                                 // Don't touch me !!
 
@@ -67,21 +68,21 @@ import UIKit
     @objc public var use_themingColor: Bool = true
     @objc public var use_themingLogo: Bool = false
     @objc public var use_storeLocalAutoUploadAll: Bool = false
-    @objc public var use_loginflowv2: Bool = false                                                // Don't touch me !!
+    @objc public var use_loginflowv2: Bool = false                                              // Don't touch me !!
 
     @objc public var disable_intro: Bool = false
     @objc public var disable_request_login_url: Bool = false
     @objc public var disable_multiaccount: Bool = false
     @objc public var disable_manage_account: Bool = false
     @objc public var disable_more_external_site: Bool = false
-    @objc public var disable_openin_file: Bool = false                                                // Don't touch me !!
+    @objc public var disable_openin_file: Bool = false                                          // Don't touch me !!
     @objc public var disable_crash_service: Bool = false
     @objc public var disable_log: Bool = false
     @objc public var disable_mobileconfig: Bool = false
     @objc public var disable_show_more_nextcloud_apps_in_settings: Bool = false
 
     // Internal option behaviour
-    @objc public var cleanUpDay: Int = 0                                                     // Set default "Delete, in the cache, all files older than" possible days value are: 0, 1, 7, 30, 90, 180, 365
+    @objc public var cleanUpDay: Int = 0                                                        // Set default "Delete, in the cache, all files older than" possible days value are: 0, 1, 7, 30, 90, 180, 365
 
     // Info Paging
     enum NCInfoPagingTab: Int, CaseIterable {
@@ -123,9 +124,11 @@ import UIKit
             }
         }
     }
-}
 
-// MARK: - Color
+    @objc func getUserAgent() -> String {
+        return userAgent
+    }
+}
 
 class NCBrandColor: NSObject {
     @objc static let shared: NCBrandColor = {

+ 2 - 2
File Provider Extension/FileProviderData.swift

@@ -93,7 +93,7 @@ class fileProviderData: NSObject {
 
             NCManageDatabase.shared.setCapabilities(account: account)
 
-            NextcloudKit.shared.setup(account: activeAccount.account, user: activeAccount.user, userId: activeAccount.userId, password: CCUtility.getPassword(activeAccount.account), urlBase: activeAccount.urlBase, userAgent: CCUtility.getUserAgent(), nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor, delegate: NCNetworking.shared)
+            NextcloudKit.shared.setup(account: activeAccount.account, user: activeAccount.user, userId: activeAccount.userId, password: CCUtility.getPassword(activeAccount.account), urlBase: activeAccount.urlBase, userAgent: userAgent, nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor, delegate: NCNetworking.shared)
             NCNetworking.shared.delegate = providerExtension as? NCNetworkingDelegate
 
             return tableAccount.init(value: activeAccount)
@@ -117,7 +117,7 @@ class fileProviderData: NSObject {
 
                 NCManageDatabase.shared.setCapabilities(account: account)
 
-                NextcloudKit.shared.setup(account: activeAccount.account, user: activeAccount.user, userId: activeAccount.userId, password: CCUtility.getPassword(activeAccount.account), urlBase: activeAccount.urlBase, userAgent: CCUtility.getUserAgent(), nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor, delegate: NCNetworking.shared)
+                NextcloudKit.shared.setup(account: activeAccount.account, user: activeAccount.user, userId: activeAccount.userId, password: CCUtility.getPassword(activeAccount.account), urlBase: activeAccount.urlBase, userAgent: userAgent, nextcloudVersion: NCGlobal.shared.capabilityServerVersionMajor, delegate: NCNetworking.shared)
                 NCNetworking.shared.delegate = providerExtension as? NCNetworkingDelegate
 
                 return tableAccount.init(value: activeAccount)

+ 2 - 2
Nextcloud.xcodeproj/project.pbxproj

@@ -4670,7 +4670,7 @@
 				CLANG_WARN_UNREACHABLE_CODE = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 				COPY_PHASE_STRIP = NO;
-				CURRENT_PROJECT_VERSION = 7;
+				CURRENT_PROJECT_VERSION = 8;
 				DEBUG_INFORMATION_FORMAT = dwarf;
 				DEVELOPMENT_TEAM = NKUJUXUJ3B;
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
@@ -4735,7 +4735,7 @@
 				CLANG_WARN_UNREACHABLE_CODE = YES;
 				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
 				COPY_PHASE_STRIP = NO;
-				CURRENT_PROJECT_VERSION = 7;
+				CURRENT_PROJECT_VERSION = 8;
 				DEVELOPMENT_TEAM = NKUJUXUJ3B;
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
 				ENABLE_TESTABILITY = YES;

+ 1 - 1
Share/NCShareExtension+NCDelegate.swift

@@ -90,7 +90,7 @@ extension NCShareExtension: NCEmptyDataSetDelegate, NCAccountRequestDelegate {
             userId: activeAccount.userId,
             password: CCUtility.getPassword(activeAccount.account),
             urlBase: activeAccount.urlBase,
-            userAgent: CCUtility.getUserAgent(),
+            userAgent: userAgent,
             nextcloudVersion: 0,
             delegate: NCNetworking.shared)
 

+ 1 - 1
Widget/Dashboard/DashboardData.swift

@@ -143,7 +143,7 @@ func getDashboardDataEntry(configuration: DashboardIntent?, isPreview: Bool, dis
         userId: account.userId,
         password: password,
         urlBase: account.urlBase,
-        userAgent: CCUtility.getUserAgent(),
+        userAgent: userAgent,
         nextcloudVersion: 0,
         delegate: NCNetworking.shared)
 

+ 1 - 1
Widget/Files/FilesData.swift

@@ -131,7 +131,7 @@ func getFilesDataEntry(configuration: AccountIntent?, isPreview: Bool, displaySi
         userId: account.userId,
         password: password,
         urlBase: account.urlBase,
-        userAgent: CCUtility.getUserAgent(),
+        userAgent: userAgent,
         nextcloudVersion: 0,
         delegate: NCNetworking.shared)
 

+ 1 - 1
Widget/Lockscreen/LockscreenData.swift

@@ -70,7 +70,7 @@ func getLockscreenDataEntry(configuration: AccountIntent?, isPreview: Bool, fami
         userId: account.userId,
         password: password,
         urlBase: account.urlBase,
-        userAgent: CCUtility.getUserAgent(),
+        userAgent: userAgent,
         nextcloudVersion: 0,
         delegate: NCNetworking.shared)
 

+ 0 - 1
iOSClient/AppDelegate.swift

@@ -72,7 +72,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
         NCSettingsBundleHelper.checkAndExecuteSettings(delay: 0)
 
-        let userAgent = CCUtility.getUserAgent() as String
         let versionNextcloudiOS = String(format: NCBrandOptions.shared.textCopyrightNextcloudiOS, NCUtility.shared.getVersionApp())
 
         // Register initialize

+ 1 - 1
iOSClient/BrowserWeb/NCBrowserWeb.swift

@@ -95,7 +95,7 @@ class NCBrowserWeb: UIViewController {
         request.addValue("true", forHTTPHeaderField: "OCS-APIRequest")
         request.addValue(language, forHTTPHeaderField: "Accept-Language")
 
-        webView.customUserAgent = CCUtility.getUserAgent()
+        webView.customUserAgent = userAgent
         webView.load(request)
     }
 }

+ 1 - 0
iOSClient/Data/NCManageDatabase+Metadata.swift

@@ -1074,6 +1074,7 @@ extension NCManageDatabase {
 
         do {
             let realm = try Realm()
+            realm.refresh()
             try realm.write {
                 let sortProperties = [SortDescriptor(keyPath: "serverUrl", ascending: false), SortDescriptor(keyPath: "fileNameView", ascending: false)]
                 let results = realm.objects(tableMetadata.self).filter(predicate).sorted(by: sortProperties)

+ 1 - 1
iOSClient/Login/NCLoginWeb.swift

@@ -171,7 +171,7 @@ class NCLoginWeb: UIViewController {
             let deviceUserAgent = String(cString: deviceName, encoding: .ascii) {
             webView.customUserAgent = deviceUserAgent
         } else {
-            webView.customUserAgent = CCUtility.getUserAgent()
+            webView.customUserAgent = userAgent
         }
 
         request.addValue("true", forHTTPHeaderField: "OCS-APIRequest")

+ 16 - 0
iOSClient/Menu/NCTrash+Menu.swift

@@ -30,6 +30,22 @@ import NextcloudKit
 extension NCTrash {
     var selectActions: [NCMenuAction] {
         [
+            NCMenuAction(
+                title: NSLocalizedString("_cancel_", comment: ""),
+                icon: NCUtility.shared.loadImage(named: "xmark"),
+                action: { _ in
+                    self.tapSelect()
+                }
+            ),
+            NCMenuAction(
+                title: NSLocalizedString("_select_all_", comment: ""),
+                icon: NCUtility.shared.loadImage(named: "checkmark.circle.fill"),
+                action: { _ in
+                    self.selectOcId = self.datasource.map { $0.fileId }
+                    self.collectionView.reloadData()
+                }
+            ),
+            NCMenuAction.seperator(),
             NCMenuAction(
                 title: NSLocalizedString("_trash_restore_selected_", comment: ""),
                 icon: NCUtility.shared.loadImage(named: "restore"),

+ 2 - 2
iOSClient/PushNotification/NCPushNotification.m

@@ -108,7 +108,7 @@
     
     [[NextcloudKit shared] subscribingPushNotificationWithServerUrl:urlBase account:account user:user password:[CCUtility getPassword:account] pushTokenHash:pushTokenHash devicePublicKey:pushDevicePublicKey proxyServerUrl:proxyServerPath customUserAgent:nil addCustomHeaders:nil queue:dispatch_get_main_queue() completion:^(NSString *account, NSString *deviceIdentifier, NSString *signature, NSString *publicKey, NSData *data, NKError *error) {
         if (error == NKError.success) {
-            NSString *userAgent = [NSString stringWithFormat:@"%@  (Strict VoIP)", [CCUtility getUserAgent]];
+            NSString *userAgent = [NSString stringWithFormat:@"%@  (Strict VoIP)", [[NCBrandOptions shared] getUserAgent]];
             [[NextcloudKit shared] subscribingPushProxyWithProxyServerUrl:proxyServerPath pushToken:self.pushKitToken deviceIdentifier:deviceIdentifier signature:signature publicKey:publicKey userAgent:userAgent queue:dispatch_get_main_queue() completion:^(NKError *error) {
                 if (error == NKError.success) {
 
@@ -134,7 +134,7 @@
 
     [[NextcloudKit shared] unsubscribingPushNotificationWithServerUrl:urlBase account:account user:user password:[CCUtility getPassword:account] customUserAgent:nil addCustomHeaders:nil queue:dispatch_get_main_queue() completion:^(NSString *account, NKError *error) {
         if (error == NKError.success) {
-            NSString *userAgent = [NSString stringWithFormat:@"%@  (Strict VoIP)", [CCUtility getUserAgent]];
+            NSString *userAgent = [NSString stringWithFormat:@"%@  (Strict VoIP)", [[NCBrandOptions shared] getUserAgent]];
             NSString *proxyServerPath = [NCBrandOptions shared].pushNotificationServerProxy;
             [[NextcloudKit shared] unsubscribingPushProxyWithProxyServerUrl:proxyServerPath deviceIdentifier:deviceIdentifier signature:signature publicKey:publicKey userAgent:userAgent queue:dispatch_get_main_queue() completion:^(NKError *error) {
                 if (error == NKError.success) {

+ 0 - 2
iOSClient/RichWorkspace/NCViewerRichWorkspaceWebView.swift

@@ -37,8 +37,6 @@ class NCViewerRichWorkspaceWebView: UIViewController, WKNavigationDelegate, WKSc
     override func viewDidLoad() {
         super.viewDidLoad()
 
-        let userAgent: String = CCUtility.getUserAgent()
-
         NotificationCenter.default.addObserver(self, selector: #selector(keyboardDidShow), name: UIResponder.keyboardDidShowNotification, object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
 

+ 0 - 2
iOSClient/Utility/CCUtility.h

@@ -182,8 +182,6 @@
 
 + (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL;
 
-+ (NSString *)getUserAgent;
-
 + (NSString *)dateDiff:(NSDate *)convertedDate;
 + (NSString *)transformedSize:(int64_t)value;
 

+ 0 - 8
iOSClient/Utility/CCUtility.m

@@ -723,14 +723,6 @@
     return success;
 }
 
-+ (NSString *)getUserAgent
-{
-    NSString *appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
-    NSString *userAgent = [[NCBrandOptions shared] userAgent];
-
-    return [NSString stringWithFormat:@"Mozilla/5.0 (iOS) %@/%@", userAgent, appVersion];
-}
-
 + (NSString *)dateDiff:(NSDate *) convertedDate
 {
     NSDate *todayDate = [NSDate date];

+ 0 - 1
iOSClient/Utility/NCUtility.swift

@@ -235,7 +235,6 @@ class NCUtility: NSObject {
     }
 
     @objc func getCustomUserAgentNCText() -> String {
-        let userAgent: String = CCUtility.getUserAgent()
         if UIDevice.current.userInterfaceIdiom == .phone {
             // NOTE: Hardcoded (May 2022)
             // Tested for iPhone SE (1st), iOS 12 iPhone Pro Max, iOS 15.4

+ 1 - 1
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayer.swift

@@ -82,7 +82,7 @@ class NCPlayer: NSObject {
     func openAVPlayer(url: URL, autoplay: Bool = false) {
 
         var position: Float = 0
-        let userAgent = CCUtility.getUserAgent()!
+        let userAgent = userAgent
 
         self.url = url
         self.singleTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(didSingleTapWith(gestureRecognizer:)))

+ 5 - 2
iOSClient/Viewer/NCViewerMedia/NCViewerMedia.swift

@@ -248,11 +248,14 @@ class NCViewerMedia: UIViewController {
                 self.scrollView.zoom(to: CGRect(x: 0, y: 0, width: self.scrollView.bounds.width, height: self.scrollView.bounds.height), animated: false)
                 self.view.layoutIfNeeded()
             }, completion: { _ in
-                self.showTip()
                 if self.metadata.isVideo {
                     self.imageVideoContainer.isHidden = false
+                } else if self.metadata.isImage {
+                    self.showTip()
+                }
+                if wasShown {
+                    self.openDetail(animate: true)
                 }
-                if wasShown { self.openDetail(animate: true) }
             })
         }
     }

+ 1 - 1
iOSClient/Viewer/NCViewerProviderContextMenu.swift

@@ -240,7 +240,7 @@ class NCViewerProviderContextMenu: UIViewController {
     private func viewVideo(metadata: tableMetadata) {
 
         NCNetworking.shared.getVideoUrl(metadata: metadata) { url, _, _ in
-            if let url = url, let userAgent = CCUtility.getUserAgent() {
+            if let url = url {
                 self.player.media = VLCMedia(url: url)
                 self.player.delegate = self
                 self.player.media?.addOption(":http-user-agent=\(userAgent)")

+ 1 - 1
iOSClient/Viewer/NCViewerRichdocument/NCViewerRichdocument.swift

@@ -71,7 +71,7 @@ class NCViewerRichdocument: UIViewController, WKNavigationDelegate, WKScriptMess
         let language = NSLocale.preferredLanguages[0] as String
         request.addValue(language, forHTTPHeaderField: "Accept-Language")
 
-        webView.customUserAgent = CCUtility.getUserAgent()
+        webView.customUserAgent = userAgent
 
         webView.load(request)
     }