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

Merge pull request #2184 from nextcloud/Improvements

Improvements
Marino Faggiana 2 жил өмнө
parent
commit
ed0af69759

+ 8 - 0
iOSClient/AppDelegate.swift

@@ -288,6 +288,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
     func applicationWillTerminate(_ application: UIApplication) {
 
         NCNetworking.shared.cancelAllDownloadTransfer()
+
+        let content = UNMutableNotificationContent()
+        content.title = NCBrandOptions.shared.brand
+        content.body = NSLocalizedString("_keep_running_", comment: "")
+        let req = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
+        let notificationCenter = UNUserNotificationCenter.current()
+        notificationCenter.add(req)
+
         NKCommon.shared.writeLog("bye bye")
     }
 

+ 67 - 53
iOSClient/Settings/NCEndToEndInitialize.swift

@@ -224,88 +224,102 @@ class NCEndToEndInitialize: NSObject {
                     let alertController = UIAlertController(title: NSLocalizedString("_e2e_settings_title_", comment: ""), message: NSLocalizedString(message, comment: ""), preferredStyle: .alert)
 
                     let OKAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default) { _ in
+                        self.createNewE2EE(e2ePassphrase: e2ePassphrase, error: error, copyPassphrase: false)
+                    }
 
-                        var privateKeyString: NSString?
+                    let copyAction = UIAlertAction(title: NSLocalizedString("_ok_copy_passphrase_", comment: ""), style: .default) { _ in
+                        self.createNewE2EE(e2ePassphrase: e2ePassphrase, error: error, copyPassphrase: true)
+                    }
 
-                        guard let privateKeyChiper = NCEndToEndEncryption.sharedManager().encryptPrivateKey(self.appDelegate.userId, directory: CCUtility.getDirectoryUserData(), passphrase: e2ePassphrase, privateKey: &privateKeyString) else {
-                            let error = NKError(errorCode: error.errorCode, errorDescription: "Serious internal error to create PrivateKey chiper")
-                            NCContentPresenter.shared.messageNotification("E2E privateKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
-                            return
-                        }
+                    alertController.addAction(OKAction)
+                    alertController.addAction(copyAction)
+
+                    self.appDelegate.window?.rootViewController?.present(alertController, animated: true)
+
+                case NCGlobal.shared.errorConflict:
+                    let error = NKError(errorCode: error.errorCode, errorDescription: "forbidden: the user can't access the private key")
+                    NCContentPresenter.shared.messageNotification("E2E get privateKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
 
-                        // privateKeyChiper
-                        print(privateKeyChiper)
+                default:
+                    NCContentPresenter.shared.messageNotification("E2E get privateKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
+                }
+            }
+        }
+    }
 
-                        NextcloudKit.shared.storeE2EEPrivateKey(privateKey: privateKeyChiper) { account, privateKey, data, error in
+    func createNewE2EE(e2ePassphrase: String, error: NKError, copyPassphrase: Bool) {
 
-                            if error == .success && account == self.appDelegate.account {
+        var privateKeyString: NSString?
 
-                                CCUtility.setEndToEndPrivateKey(account, privateKey: privateKeyString! as String)
-                                CCUtility.setEndToEndPassphrase(account, passphrase: e2ePassphrase)
+        guard let privateKeyChiper = NCEndToEndEncryption.sharedManager().encryptPrivateKey(self.appDelegate.userId, directory: CCUtility.getDirectoryUserData(), passphrase: e2ePassphrase, privateKey: &privateKeyString) else {
+            let error = NKError(errorCode: error.errorCode, errorDescription: "Serious internal error to create PrivateKey chiper")
+            NCContentPresenter.shared.messageNotification("E2E privateKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
+            return
+        }
 
-                                // request server publicKey
-                                NextcloudKit.shared.getE2EEPublicKey { account, publicKey, data, error in
+        // privateKeyChiper
+        print(privateKeyChiper)
 
-                                    if error == .success && account == self.appDelegate.account {
+        NextcloudKit.shared.storeE2EEPrivateKey(privateKey: privateKeyChiper) { account, privateKey, data, error in
 
-                                        CCUtility.setEndToEndPublicKey(account, publicKey: publicKey)
+            if error == .success && account == self.appDelegate.account {
 
-                                        // Clear Table
-                                        NCManageDatabase.shared.clearTable(tableDirectory.self, account: account)
-                                        NCManageDatabase.shared.clearTable(tableE2eEncryption.self, account: account)
+                CCUtility.setEndToEndPrivateKey(account, privateKey: privateKeyString! as String)
+                CCUtility.setEndToEndPassphrase(account, passphrase: e2ePassphrase)
 
-                                        self.delegate?.endToEndInitializeSuccess()
+                // request server publicKey
+                NextcloudKit.shared.getE2EEPublicKey { account, publicKey, data, error in
 
-                                    } else if error != .success {
+                    if error == .success && account == self.appDelegate.account {
 
-                                        switch error.errorCode {
+                        CCUtility.setEndToEndPublicKey(account, publicKey: publicKey)
 
-                                        case NCGlobal.shared.errorBadRequest:
-                                            let error = NKError(errorCode: error.errorCode, errorDescription: "bad request: unpredictable internal error")
-                                            NCContentPresenter.shared.messageNotification("E2E Server publicKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
+                        // Clear Table
+                        NCManageDatabase.shared.clearTable(tableDirectory.self, account: account)
+                        NCManageDatabase.shared.clearTable(tableE2eEncryption.self, account: account)
 
-                                        case NCGlobal.shared.errorResourceNotFound:
-                                            let error = NKError(errorCode: error.errorCode, errorDescription: "Server publickey doesn't exists")
-                                            NCContentPresenter.shared.messageNotification("E2E Server publicKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
+                        if copyPassphrase {
+                            UIPasteboard.general.string = e2ePassphrase
+                        }
 
-                                        case NCGlobal.shared.errorConflict:
-                                            let error = NKError(errorCode: error.errorCode, errorDescription: "forbidden: the user can't access the Server publickey")
-                                            NCContentPresenter.shared.messageNotification("E2E Server publicKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
+                        self.delegate?.endToEndInitializeSuccess()
 
-                                        default:
-                                            NCContentPresenter.shared.messageNotification("E2E Server publicKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
-                                        }
-                                    }
-                                }
+                    } else if error != .success {
 
-                            } else if error != .success {
+                        switch error.errorCode {
 
-                                switch error.errorCode {
+                        case NCGlobal.shared.errorBadRequest:
+                            let error = NKError(errorCode: error.errorCode, errorDescription: "bad request: unpredictable internal error")
+                            NCContentPresenter.shared.messageNotification("E2E Server publicKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
 
-                                case NCGlobal.shared.errorBadRequest:
-                                    let error = NKError(errorCode: error.errorCode, errorDescription: "bad request: unpredictable internal error")
-                                    NCContentPresenter.shared.messageNotification("E2E store privateKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
+                        case NCGlobal.shared.errorResourceNotFound:
+                            let error = NKError(errorCode: error.errorCode, errorDescription: "Server publickey doesn't exists")
+                            NCContentPresenter.shared.messageNotification("E2E Server publicKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
 
-                                case NCGlobal.shared.errorConflict:
-                                    let error = NKError(errorCode: error.errorCode, errorDescription: "conflict: a private key for the user already exists")
-                                    NCContentPresenter.shared.messageNotification("E2E store privateKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
+                        case NCGlobal.shared.errorConflict:
+                            let error = NKError(errorCode: error.errorCode, errorDescription: "forbidden: the user can't access the Server publickey")
+                            NCContentPresenter.shared.messageNotification("E2E Server publicKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
 
-                                default:
-                                    NCContentPresenter.shared.messageNotification("E2E store privateKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
-                                }
-                            }
+                        default:
+                            NCContentPresenter.shared.messageNotification("E2E Server publicKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
                         }
                     }
+                }
 
-                    alertController.addAction(OKAction)
-                    self.appDelegate.window?.rootViewController?.present(alertController, animated: true)
+            } else if error != .success {
+
+                switch error.errorCode {
+
+                case NCGlobal.shared.errorBadRequest:
+                    let error = NKError(errorCode: error.errorCode, errorDescription: "bad request: unpredictable internal error")
+                    NCContentPresenter.shared.messageNotification("E2E store privateKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
 
                 case NCGlobal.shared.errorConflict:
-                    let error = NKError(errorCode: error.errorCode, errorDescription: "forbidden: the user can't access the private key")
-                    NCContentPresenter.shared.messageNotification("E2E get privateKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
+                    let error = NKError(errorCode: error.errorCode, errorDescription: "conflict: a private key for the user already exists")
+                    NCContentPresenter.shared.messageNotification("E2E store privateKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
 
                 default:
-                    NCContentPresenter.shared.messageNotification("E2E get privateKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
+                    NCContentPresenter.shared.messageNotification("E2E store privateKey", error: error, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, priority: .max)
                 }
             }
         }

+ 2 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -882,6 +882,7 @@
 "_ITMS-90076_"              = "Due to a change in the Nextcloud application identifier, the settings and password for accessing your cloud are reset, so please re-enter your account data and check your Settings. We are sorry about that.";
 "_password_not_present_"    = "Please re-insert your credentials.";
 "_copy_passphrase_"         = "Copy passphrase";
+"_ok_copy_passphrase_"      = "OK and copy passphrase";
 "_select_color_"            = "Select the color";
 "_change_color_"            = "Change color";
 "_description_dashboardwidget_" = "Having the Dashboard always at your fingertips has never been easier.";
@@ -889,6 +890,7 @@
 "_description_toolbarwidget_"   = "A toolbar to speed up your operations.";
 "_no_data_available_"       = "No data available";
 "_widget_available_nc25_"   = "Widget only available starting with Nextcloud 25";
+"_keep_running_"            = "Keep the app running for a better user experience";
 
 // Video
 "_select_trace_"            = "Select the trace";