Customize block on passphrase input cancellation

Do not delete .ovpn file when importing from iTunes.
This commit is contained in:
Davide De Rosa 2019-03-25 19:44:53 +01:00
parent 8f0e28e315
commit f3e6c34bd1
3 changed files with 9 additions and 4 deletions

View File

@ -101,7 +101,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
let passphraseBlock = { (passphrase) in
_ = self.tryParseURL(url, passphrase: passphrase, target: target)
}
guard let parsingResult = ConfigurationParser.ParsingResult.from(url, withErrorAlertIn: target, passphrase: passphrase, passphraseBlock: passphraseBlock) else {
let passphraseCancelBlock = {
_ = try? FileManager.default.removeItem(at: url)
}
guard let parsingResult = ConfigurationParser.ParsingResult.from(url, withErrorAlertIn: target, passphrase: passphrase, passphraseBlock: passphraseBlock, passphraseCancelBlock: passphraseCancelBlock) else {
return true
}
if let warning = parsingResult.warning {

View File

@ -32,7 +32,9 @@ import Passepartout_Core
private let log = SwiftyBeaver.self
extension ConfigurationParser.ParsingResult {
static func from(_ url: URL, withErrorAlertIn viewController: UIViewController, passphrase: String?, passphraseBlock: @escaping (String) -> Void) -> ConfigurationParser.ParsingResult? {
static func from(_ url: URL, withErrorAlertIn viewController: UIViewController, passphrase: String?,
passphraseBlock: @escaping (String) -> Void, passphraseCancelBlock: (() -> Void)?) -> ConfigurationParser.ParsingResult? {
let result: ConfigurationParser.ParsingResult
let fm = FileManager.default
@ -51,7 +53,7 @@ extension ConfigurationParser.ParsingResult {
passphraseBlock(passphrase)
}
alert.addCancelAction(L10n.Global.cancel) {
try? fm.removeItem(at: url)
passphraseCancelBlock?()
}
viewController.present(alert, animated: true, completion: nil)

View File

@ -88,7 +88,7 @@ class ImportedHostsViewController: UITableViewController {
}
self.perform(segue: StoryboardSegue.Organizer.importHostSegueIdentifier, sender: cell)
}
guard let parsingResult = ConfigurationParser.ParsingResult.from(url, withErrorAlertIn: self, passphrase: passphrase, passphraseBlock: passphraseBlock) else {
guard let parsingResult = ConfigurationParser.ParsingResult.from(url, withErrorAlertIn: self, passphrase: passphrase, passphraseBlock: passphraseBlock, passphraseCancelBlock: nil) else {
deselectSelectedRow()
return false
}