iOS: Fix handling of deletion outside app
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
54f45cb3f8
commit
77d4a02139
|
@ -8,7 +8,6 @@ class MainViewController: UISplitViewController {
|
||||||
var tunnelsManager: TunnelsManager?
|
var tunnelsManager: TunnelsManager?
|
||||||
var onTunnelsManagerReady: ((TunnelsManager) -> Void)?
|
var onTunnelsManagerReady: ((TunnelsManager) -> Void)?
|
||||||
var tunnelsListVC: TunnelsListTableViewController?
|
var tunnelsListVC: TunnelsListTableViewController?
|
||||||
private var foregroundObservationToken: AnyObject?
|
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
let detailVC = UIViewController()
|
let detailVC = UIViewController()
|
||||||
|
@ -57,29 +56,6 @@ class MainViewController: UISplitViewController {
|
||||||
self.onTunnelsManagerReady?(tunnelsManager)
|
self.onTunnelsManagerReady?(tunnelsManager)
|
||||||
self.onTunnelsManagerReady = nil
|
self.onTunnelsManagerReady = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
foregroundObservationToken = NotificationCenter.default.addObserver(forName: UIApplication.willEnterForegroundNotification, object: nil, queue: OperationQueue.main) { [weak self] _ in
|
|
||||||
guard let self = self else { return }
|
|
||||||
self.tunnelsManager?.reload { [weak self] hasChanges in
|
|
||||||
guard let self = self, let tunnelsManager = self.tunnelsManager, hasChanges else { return }
|
|
||||||
|
|
||||||
self.tunnelsListVC?.setTunnelsManager(tunnelsManager: tunnelsManager)
|
|
||||||
|
|
||||||
if self.isCollapsed {
|
|
||||||
(self.viewControllers[0] as? UINavigationController)?.popViewController(animated: false)
|
|
||||||
} else {
|
|
||||||
let detailVC = UIViewController()
|
|
||||||
detailVC.view.backgroundColor = .white
|
|
||||||
let detailNC = UINavigationController(rootViewController: detailVC)
|
|
||||||
self.showDetailViewController(detailNC, sender: self)
|
|
||||||
}
|
|
||||||
|
|
||||||
if let presentedNavController = self.presentedViewController as? UINavigationController, presentedNavController.viewControllers.first is TunnelEditTableViewController {
|
|
||||||
self.presentedViewController?.dismiss(animated: false, completion: nil)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,7 +252,21 @@ extension TunnelsListTableViewController: TunnelsManagerListDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
func tunnelRemoved(at index: Int) {
|
func tunnelRemoved(at index: Int) {
|
||||||
|
let selectedIndex = tableView.indexPathForSelectedRow?.row
|
||||||
tableView.deleteRows(at: [IndexPath(row: index, section: 0)], with: .automatic)
|
tableView.deleteRows(at: [IndexPath(row: index, section: 0)], with: .automatic)
|
||||||
centeredAddButton.isHidden = tunnelsManager?.numberOfTunnels() ?? 0 > 0
|
centeredAddButton.isHidden = tunnelsManager?.numberOfTunnels() ?? 0 > 0
|
||||||
|
if let selectedIndex = selectedIndex, selectedIndex == index, let splitViewController = splitViewController {
|
||||||
|
if splitViewController.isCollapsed != false {
|
||||||
|
(splitViewController.viewControllers[0] as? UINavigationController)?.popViewController(animated: false)
|
||||||
|
} else {
|
||||||
|
let detailVC = UIViewController()
|
||||||
|
detailVC.view.backgroundColor = .white
|
||||||
|
let detailNC = UINavigationController(rootViewController: detailVC)
|
||||||
|
splitViewController.showDetailViewController(detailNC, sender: self)
|
||||||
|
}
|
||||||
|
if let presentedNavController = self.presentedViewController as? UINavigationController, presentedNavController.viewControllers.first is TunnelEditTableViewController {
|
||||||
|
self.presentedViewController?.dismiss(animated: false, completion: nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue