Remove unnecessary IssueReporterDelegate

This commit is contained in:
Shadowfacts 2022-03-30 09:58:50 -04:00
parent 7da139be4d
commit cab78a4aa4
4 changed files with 17 additions and 30 deletions

View File

@ -127,7 +127,9 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate {
return return
} }
window!.rootViewController = CrashReporterViewController.create(report: report, delegate: self) window!.rootViewController = CrashReporterViewController.create(report: report, dismiss: {
self.showAppOrOnboardingUI()
})
#endif #endif
} }
@ -207,9 +209,3 @@ extension MainSceneDelegate: OnboardingViewControllerDelegate {
activateAccount(account, animated: false) activateAccount(account, animated: false)
} }
} }
extension MainSceneDelegate: IssueReporterViewControllerDelegate {
func didDismissReporter() {
showAppOrOnboardingUI()
}
}

View File

@ -21,17 +21,17 @@ class CrashReporterViewController: IssueReporterViewController {
"Tusker Crash Report" "Tusker Crash Report"
} }
static func create(report: PLCrashReport, delegate: IssueReporterViewControllerDelegate) -> UINavigationController { static func create(report: PLCrashReport, dismiss: @escaping () -> Void) -> UINavigationController {
return create(CrashReporterViewController(report: report, delegate: delegate)) return create(CrashReporterViewController(report: report, dismiss: dismiss))
} }
private init(report: PLCrashReport, delegate: IssueReporterViewControllerDelegate) { private init(report: PLCrashReport, dismiss: @escaping () -> Void) {
self.report = report self.report = report
let reportText = PLCrashReportTextFormatter.stringValue(for: report, with: PLCrashReportTextFormatiOS)! let reportText = PLCrashReportTextFormatter.stringValue(for: report, with: PLCrashReportTextFormatiOS)!
let timestamp = ISO8601DateFormatter().string(from: report.systemInfo.timestamp) let timestamp = ISO8601DateFormatter().string(from: report.systemInfo.timestamp)
let reportFilename = "Tusker-crash-\(timestamp).crash" 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) { required init?(coder: NSCoder) {

View File

@ -10,10 +10,6 @@ import UIKit
import CrashReporter import CrashReporter
import MessageUI import MessageUI
protocol IssueReporterViewControllerDelegate: AnyObject {
func didDismissReporter()
}
class IssueReporterViewController: UIViewController { class IssueReporterViewController: UIViewController {
static func create(_ self: IssueReporterViewController) -> UINavigationController { static func create(_ self: IssueReporterViewController) -> UINavigationController {
@ -22,14 +18,14 @@ class IssueReporterViewController: UIViewController {
return nav 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" 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 reportText: String
let reportFilename: String let reportFilename: String
private weak var delegate: IssueReporterViewControllerDelegate? private let dismiss: () -> Void
var preamble: String { 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." "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 crashReportTextView: UITextView!
@IBOutlet weak var sendReportButton: UIButton! @IBOutlet weak var sendReportButton: UIButton!
init(reportText: String, reportFilename: String, delegate: IssueReporterViewControllerDelegate?) { init(reportText: String, reportFilename: String, dismiss: @escaping () -> Void) {
self.reportText = reportText self.reportText = reportText
self.reportFilename = reportFilename self.reportFilename = reportFilename
self.delegate = delegate self.dismiss = dismiss
super.init(nibName: "IssueReporterViewController", bundle: .main) super.init(nibName: "IssueReporterViewController", bundle: .main)
} }
@ -131,7 +127,7 @@ class IssueReporterViewController: UIViewController {
} }
@IBAction func cancelPressed(_ sender: Any) { @IBAction func cancelPressed(_ sender: Any) {
delegate?.didDismissReporter() dismiss()
} }
} }
@ -139,7 +135,7 @@ class IssueReporterViewController: UIViewController {
extension IssueReporterViewController: MFMailComposeViewControllerDelegate { extension IssueReporterViewController: MFMailComposeViewControllerDelegate {
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true) { controller.dismiss(animated: true) {
self.delegate?.didDismissReporter() self.dismiss()
} }
} }
} }

View File

@ -49,7 +49,9 @@ extension ToastConfiguration {
\(error.type) \(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) 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)
}
}