macOS: Dismiss modals correctly

Previously, the presented vc were leaking when discarding edits
or when closing the log view controller.

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander 2019-05-29 19:45:22 +05:30 committed by Jason A. Donenfeld
parent 9b92a8f933
commit 714d6a41bd
2 changed files with 12 additions and 9 deletions

View File

@ -220,7 +220,8 @@ class LogViewController: NSViewController {
return return
} }
DispatchQueue.main.async { [weak self] in DispatchQueue.main.async { [weak self] in
self?.dismiss(self) guard let self = self else { return }
self.presentingViewController?.dismiss(self)
} }
} }
@ -228,7 +229,7 @@ class LogViewController: NSViewController {
} }
@objc func closeClicked() { @objc func closeClicked() {
dismiss(self) presentingViewController?.dismiss(self)
} }
@objc func copy(_ sender: Any?) { @objc func copy(_ sender: Any?) {

View File

@ -237,24 +237,26 @@ class TunnelEditViewController: NSViewController {
if let tunnel = tunnel { if let tunnel = tunnel {
// We're modifying an existing tunnel // We're modifying an existing tunnel
tunnelsManager.modify(tunnel: tunnel, tunnelConfiguration: tunnelConfiguration, onDemandOption: onDemandOption) { [weak self] error in tunnelsManager.modify(tunnel: tunnel, tunnelConfiguration: tunnelConfiguration, onDemandOption: onDemandOption) { [weak self] error in
self?.setUserInteractionEnabled(true) guard let self = self else { return }
self.setUserInteractionEnabled(true)
if let error = error { if let error = error {
ErrorPresenter.showErrorAlert(error: error, from: self) ErrorPresenter.showErrorAlert(error: error, from: self)
return return
} }
self?.dismiss(self) self.delegate?.tunnelSaved(tunnel: tunnel)
self?.delegate?.tunnelSaved(tunnel: tunnel) self.presentingViewController?.dismiss(self)
} }
} else { } else {
// We're creating a new tunnel // We're creating a new tunnel
self.tunnelsManager.add(tunnelConfiguration: tunnelConfiguration, onDemandOption: onDemandOption) { [weak self] result in self.tunnelsManager.add(tunnelConfiguration: tunnelConfiguration, onDemandOption: onDemandOption) { [weak self] result in
self?.setUserInteractionEnabled(true) guard let self = self else { return }
self.setUserInteractionEnabled(true)
switch result { switch result {
case .failure(let error): case .failure(let error):
ErrorPresenter.showErrorAlert(error: error, from: self) ErrorPresenter.showErrorAlert(error: error, from: self)
case .success(let tunnel): case .success(let tunnel):
self?.dismiss(self) self.delegate?.tunnelSaved(tunnel: tunnel)
self?.delegate?.tunnelSaved(tunnel: tunnel) self.presentingViewController?.dismiss(self)
} }
} }
} }
@ -262,7 +264,7 @@ class TunnelEditViewController: NSViewController {
@objc func handleDiscardAction() { @objc func handleDiscardAction() {
delegate?.tunnelEditingCancelled() delegate?.tunnelEditingCancelled()
dismiss(self) presentingViewController?.dismiss(self)
} }
func updateExcludePrivateIPsVisibility(singlePeerAllowedIPs: [String]?) { func updateExcludePrivateIPsVisibility(singlePeerAllowedIPs: [String]?) {