diff --git a/Tusker/MainSceneDelegate.swift b/Tusker/MainSceneDelegate.swift index 166971de..3e7d6534 100644 --- a/Tusker/MainSceneDelegate.swift +++ b/Tusker/MainSceneDelegate.swift @@ -127,7 +127,9 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate { return } - window!.rootViewController = CrashReporterViewController.create(report: report, delegate: self) + window!.rootViewController = CrashReporterViewController.create(report: report, dismiss: { + self.showAppOrOnboardingUI() + }) #endif } @@ -207,9 +209,3 @@ extension MainSceneDelegate: OnboardingViewControllerDelegate { activateAccount(account, animated: false) } } - -extension MainSceneDelegate: IssueReporterViewControllerDelegate { - func didDismissReporter() { - showAppOrOnboardingUI() - } -} diff --git a/Tusker/Screens/Crash Reporter/CrashReporterViewController.swift b/Tusker/Screens/Crash Reporter/CrashReporterViewController.swift index c7383e7b..ddf0e281 100644 --- a/Tusker/Screens/Crash Reporter/CrashReporterViewController.swift +++ b/Tusker/Screens/Crash Reporter/CrashReporterViewController.swift @@ -21,17 +21,17 @@ class CrashReporterViewController: IssueReporterViewController { "Tusker Crash Report" } - static func create(report: PLCrashReport, delegate: IssueReporterViewControllerDelegate) -> UINavigationController { - return create(CrashReporterViewController(report: report, delegate: delegate)) + static func create(report: PLCrashReport, dismiss: @escaping () -> Void) -> UINavigationController { + return create(CrashReporterViewController(report: report, dismiss: dismiss)) } - private init(report: PLCrashReport, delegate: IssueReporterViewControllerDelegate) { + private init(report: PLCrashReport, dismiss: @escaping () -> Void) { self.report = report let reportText = PLCrashReportTextFormatter.stringValue(for: report, with: PLCrashReportTextFormatiOS)! let timestamp = ISO8601DateFormatter().string(from: report.systemInfo.timestamp) let reportFilename = "Tusker-crash-\(timestamp).crash" - super.init(reportText: reportText, reportFilename: reportFilename, delegate: delegate) + super.init(reportText: reportText, reportFilename: reportFilename, dismiss: dismiss) } required init?(coder: NSCoder) { diff --git a/Tusker/Screens/Crash Reporter/IssueReporterViewController.swift b/Tusker/Screens/Crash Reporter/IssueReporterViewController.swift index 41ac515e..95a5470b 100644 --- a/Tusker/Screens/Crash Reporter/IssueReporterViewController.swift +++ b/Tusker/Screens/Crash Reporter/IssueReporterViewController.swift @@ -10,10 +10,6 @@ import UIKit import CrashReporter import MessageUI -protocol IssueReporterViewControllerDelegate: AnyObject { - func didDismissReporter() -} - class IssueReporterViewController: UIViewController { static func create(_ self: IssueReporterViewController) -> UINavigationController { @@ -22,14 +18,14 @@ class IssueReporterViewController: UIViewController { return nav } - static func create(reportText: String, reportFilename: String? = nil, delegate: IssueReporterViewControllerDelegate) -> UINavigationController { + static func create(reportText: String, reportFilename: String? = nil, dismiss: @escaping () -> Void) -> UINavigationController { let filename = reportFilename ?? "Tusker-error-\(ISO8601DateFormatter().string(from: Date())).txt" - return create(IssueReporterViewController(reportText: reportText, reportFilename: filename, delegate: delegate)) + return create(IssueReporterViewController(reportText: reportText, reportFilename: filename, dismiss: dismiss)) } let reportText: String let reportFilename: String - private weak var delegate: IssueReporterViewControllerDelegate? + private let dismiss: () -> Void var preamble: String { "Tusker has encountered an error. You can email a report to the developer. You may review the report below before sending.\n\nIf you choose to send the report, please include any additional details about what you were doing prior that may be pertinent." @@ -41,10 +37,10 @@ class IssueReporterViewController: UIViewController { @IBOutlet weak var crashReportTextView: UITextView! @IBOutlet weak var sendReportButton: UIButton! - init(reportText: String, reportFilename: String, delegate: IssueReporterViewControllerDelegate?) { + init(reportText: String, reportFilename: String, dismiss: @escaping () -> Void) { self.reportText = reportText self.reportFilename = reportFilename - self.delegate = delegate + self.dismiss = dismiss super.init(nibName: "IssueReporterViewController", bundle: .main) } @@ -131,7 +127,7 @@ class IssueReporterViewController: UIViewController { } @IBAction func cancelPressed(_ sender: Any) { - delegate?.didDismissReporter() + dismiss() } } @@ -139,7 +135,7 @@ class IssueReporterViewController: UIViewController { extension IssueReporterViewController: MFMailComposeViewControllerDelegate { func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { controller.dismiss(animated: true) { - self.delegate?.didDismissReporter() + self.dismiss() } } } diff --git a/Tusker/Views/Toast/ToastConfiguration.swift b/Tusker/Views/Toast/ToastConfiguration.swift index 44e41764..996557b8 100644 --- a/Tusker/Views/Toast/ToastConfiguration.swift +++ b/Tusker/Views/Toast/ToastConfiguration.swift @@ -49,7 +49,9 @@ extension ToastConfiguration { \(error.type) """ - let reporter = IssueReporterViewController.create(reportText: text, delegate: viewController) + let reporter = IssueReporterViewController.create(reportText: text, dismiss: { [unowned viewController] in + viewController.dismiss(animated: true) + }) viewController.present(reporter, animated: true) } } @@ -65,10 +67,3 @@ fileprivate extension Client.Error { } } } - -// todo: i don't like that this protocol conformance is accessible outside of this file -extension UIViewController: IssueReporterViewControllerDelegate { - func didDismissReporter() { - self.dismiss(animated: true) - } -}