Skip to content

Commit

Permalink
Add an alert to prevent accidental proxy-deletion (#2382)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitschlag committed Nov 7, 2024
1 parent 786a29f commit ea9e083
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,27 @@ class ProxySettingsViewController: UITableViewController {
private func deleteProxy(at indexPath: IndexPath) {
let proxyToRemove = proxies[indexPath.row]

if let selectedProxy, proxyToRemove == selectedProxy {
dcContext.isProxyEnabled = false
let deleteAlert = UIAlertController(title: String.localized("proxy_delete"), message: String.localized(stringID: "proxy_delete_explain", parameter: proxyToRemove), preferredStyle: .alert)

let cancelAction = UIAlertAction(title: String.localized("cancel"), style: .cancel)
let deleteAction = UIAlertAction(title: String.localized("proxy_delete"), style: .destructive) { [weak self] _ in
guard let self else { return }

if let selectedProxy = self.selectedProxy, proxyToRemove == selectedProxy {
self.dcContext.isProxyEnabled = false
}

self.proxies.remove(at: indexPath.row)
self.dcContext.setProxies(proxyURLs: proxies)
DispatchQueue.main.async {
self.toggleProxyCell.uiSwitch.isEnabled = (self.proxies.isEmpty == false)
self.tableView.reloadData()
}
}

proxies.remove(at: indexPath.row)
toggleProxyCell.uiSwitch.isEnabled = (proxies.isEmpty == false)
dcContext.setProxies(proxyURLs: proxies)
tableView.reloadData()
deleteAlert.addAction(cancelAction)
deleteAlert.addAction(deleteAction)
present(deleteAlert, animated: true)
}
}

Expand Down

0 comments on commit ea9e083

Please sign in to comment.