From 714d6a41bd2669515181552104a5c587064ae3ea Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Wed, 29 May 2019 19:45:22 +0530 Subject: 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 --- .../UI/macOS/ViewController/LogViewController.swift | 5 +++-- .../macOS/ViewController/TunnelEditViewController.swift | 16 +++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'WireGuard/WireGuard') 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]?) { -- cgit v1.2.3-59-g8ed1b