diff options
author | Roopesh Chander <roop@roopc.net> | 2019-05-29 19:45:22 +0530 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-31 17:29:29 +0200 |
commit | 714d6a41bd2669515181552104a5c587064ae3ea (patch) | |
tree | 836056954d14aaa83b54b2ae66c7d3480fe80570 | |
parent | macOS: Update app icon (diff) | |
download | wireguard-apple-714d6a41bd2669515181552104a5c587064ae3ea.tar.xz wireguard-apple-714d6a41bd2669515181552104a5c587064ae3ea.zip |
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>
-rw-r--r-- | WireGuard/WireGuard/UI/macOS/ViewController/LogViewController.swift | 5 | ||||
-rw-r--r-- | WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift | 16 |
2 files changed, 12 insertions, 9 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/LogViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/LogViewController.swift index 8146977..088d161 100644 --- a/WireGuard/WireGuard/UI/macOS/ViewController/LogViewController.swift +++ b/WireGuard/WireGuard/UI/macOS/ViewController/LogViewController.swift @@ -220,7 +220,8 @@ class LogViewController: NSViewController { return } 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() { - dismiss(self) + presentingViewController?.dismiss(self) } @objc func copy(_ sender: Any?) { diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift index 88cabbd..17ebbef 100644 --- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift +++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelEditViewController.swift @@ -237,24 +237,26 @@ class TunnelEditViewController: NSViewController { if let tunnel = tunnel { // We're modifying an existing tunnel 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 { ErrorPresenter.showErrorAlert(error: error, from: self) return } - self?.dismiss(self) - self?.delegate?.tunnelSaved(tunnel: tunnel) + self.delegate?.tunnelSaved(tunnel: tunnel) + self.presentingViewController?.dismiss(self) } } else { // We're creating a new tunnel 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 { case .failure(let error): ErrorPresenter.showErrorAlert(error: error, from: self) 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() { delegate?.tunnelEditingCancelled() - dismiss(self) + presentingViewController?.dismiss(self) } func updateExcludePrivateIPsVisibility(singlePeerAllowedIPs: [String]?) { |