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
}
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()
}
}

View File

@ -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) {

View File

@ -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()
}
}
}

View File

@ -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)
}
}