]> git.ipfire.org Git - thirdparty/wireguard-apple.git/commitdiff
Error handling: Use ErrorPresenter.showErrorAlert() instead of per-VC showErrorAlert...
authorRoopesh Chander <roop@roopc.net>
Thu, 6 Dec 2018 13:52:48 +0000 (19:22 +0530)
committerRoopesh Chander <roop@roopc.net>
Fri, 7 Dec 2018 07:06:19 +0000 (12:36 +0530)
Signed-off-by: Roopesh Chander <roop@roopc.net>
WireGuard/WireGuard/UI/iOS/SettingsTableViewController.swift
WireGuard/WireGuard/UI/iOS/TunnelDetailTableViewController.swift
WireGuard/WireGuard/UI/iOS/TunnelEditTableViewController.swift
WireGuard/WireGuard/UI/iOS/TunnelsListTableViewController.swift

index 7beb2e91ee98ec51f1825066f7c45138e77a369f..4c8c9a138f11888e8f66eec27e9d221f3206cdfe 100644 (file)
@@ -101,14 +101,14 @@ class SettingsTableViewController: UITableViewController {
         if (FileManager.default.fileExists(atPath: destinationURL.path)) {
             let isDeleted = FileManager.deleteFile(at: destinationURL)
             if (!isDeleted) {
-                showErrorAlert(title: "No log available", message: "The pre-existing log could not be cleared")
+                ErrorPresenter.showErrorAlert(title: "No log available", message: "The pre-existing log could not be cleared", from: self)
                 return
             }
         }
 
         guard let networkExtensionLogFileURL = FileManager.networkExtensionLogFileURL,
             FileManager.default.fileExists(atPath: networkExtensionLogFileURL.path) else {
-                showErrorAlert(title: "No log available", message: "Please activate a tunnel and then export the log")
+                ErrorPresenter.showErrorAlert(title: "No log available", message: "Please activate a tunnel and then export the log", from: self)
                 return
         }
 
@@ -116,7 +116,7 @@ class SettingsTableViewController: UITableViewController {
             try FileManager.default.copyItem(at: networkExtensionLogFileURL, to: destinationURL)
         } catch {
             os_log("Failed to copy file: %{public}@ to %{public}@: %{public}@", log: OSLog.default, type: .error, networkExtensionLogFileURL.absoluteString, destinationURL.absoluteString, error.localizedDescription)
-            showErrorAlert(title: "No log available", message: "The log could not be accessed")
+            ErrorPresenter.showErrorAlert(title: "No log available", message: "The log could not be accessed", from: self)
             return
         }
 
@@ -130,14 +130,6 @@ class SettingsTableViewController: UITableViewController {
         }
         self.present(activityVC, animated: true)
     }
-
-    func showErrorAlert(title: String, message: String) {
-        let okAction = UIAlertAction(title: "OK", style: .default)
-        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
-        alert.addAction(okAction)
-
-        self.present(alert, animated: true, completion: nil)
-    }
 }
 
 // MARK: UITableViewDataSource
index 1bb337cbccd9fd658dce486779749c7be3e2b2c7..99d751b86288ec7c857c7e52a2320a1c54bcc5e2 100644 (file)
@@ -53,14 +53,6 @@ class TunnelDetailTableViewController: UITableViewController {
         present(editNC, animated: true)
     }
 
-    func showErrorAlert(title: String, message: String) {
-        let okAction = UIAlertAction(title: "OK", style: .default)
-        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
-        alert.addAction(okAction)
-
-        self.present(alert, animated: true, completion: nil)
-    }
-
     func showConfirmationAlert(message: String, buttonTitle: String, from sourceView: UIView,
                                onConfirmed: @escaping (() -> Void)) {
         let destroyAction = UIAlertAction(title: buttonTitle, style: .destructive) { (_) in
index ca5e6a8e747e874593b098707f5b4b70b2e77c3f..c110d7383abb460690180f0dca61e436ab146f85 100644 (file)
@@ -116,14 +116,6 @@ class TunnelEditTableViewController: UITableViewController {
         dismiss(animated: true, completion: nil)
         self.delegate?.tunnelEditingCancelled()
     }
-
-    func showErrorAlert(title: String, message: String) {
-        let okAction = UIAlertAction(title: "OK", style: .default)
-        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
-        alert.addAction(okAction)
-
-        self.present(alert, animated: true, completion: nil)
-    }
 }
 
 // MARK: UITableViewDataSource
index 4450796ce01aef809c7d0a30a76fbf3546160fda..4cff27c4e58af0d12104bcbe105abc7879106c07 100644 (file)
@@ -154,14 +154,6 @@ class TunnelsListTableViewController: UIViewController {
         self.present(scanQRCodeNC, animated: true)
     }
 
-    func showErrorAlert(title: String, message: String) {
-        let okAction = UIAlertAction(title: "OK", style: .default)
-        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
-        alert.addAction(okAction)
-
-        self.present(alert, animated: true, completion: nil)
-    }
-
     func importFromFile(url: URL) {
         guard let tunnelsManager = tunnelsManager else { return }
         if (url.pathExtension == "zip") {
@@ -175,8 +167,9 @@ class TunnelsListTableViewController: UIViewController {
                     if numberSuccessful == configs.count {
                         return
                     }
-                    self?.showErrorAlert(title: "Created \(numberSuccessful) tunnels",
-                        message: "Created \(numberSuccessful) of \(configs.count) tunnels from zip archive")
+                    ErrorPresenter.showErrorAlert(title: "Created \(numberSuccessful) tunnels",
+                        message: "Created \(numberSuccessful) of \(configs.count) tunnels from zip archive",
+                        from: self)
                 }
             }
         } else /* if (url.pathExtension == "conf") -- we assume everything else is a conf */ {
@@ -189,7 +182,9 @@ class TunnelsListTableViewController: UIViewController {
                     }
                 }
             } else {
-                showErrorAlert(title: "Unable to import tunnel", message: "An error occured when importing the tunnel configuration.")
+                ErrorPresenter.showErrorAlert(title: "Unable to import tunnel",
+                                              message: "An error occured when importing the tunnel configuration.",
+                                              from: self)
             }
         }
     }