| ... | ... | @@ -9,20 +9,29 @@ enum Crash { |
| 9 | 9 | _ = sb_crash_start(folder.appendingPathComponent("crash.txt").path, build, "iOS \(UIDevice.current.systemVersion)") |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | | static func offer(from host: UIViewController) { |
| 13 | | guard !offered, let saved = sb_crash_report() else { return } |
| 12 | /// Offers the last run's report, then runs `then` once it is answered, so that what crashed |
| 13 | /// that run does not open again before the report can be sent; at once where there is none. |
| 14 | static func offer(from host: UIViewController, then: @escaping () -> Void) { |
| 15 | guard !offered, let saved = sb_crash_report() else { return then() } |
| 14 | 16 | let report = String(cString: saved) |
| 15 | 17 | sb_string_free(saved) |
| 16 | 18 | offered = true |
| 17 | 19 | let alert = UIAlertController( |
| 18 | 20 | title: "Snowbound quit unexpectedly", message: "Send a report to help fix the problem. You can review the report before sending it.", preferredStyle: .alert) |
| 19 | | alert.addAction(UIAlertAction(title: "Send Report", style: .default) { _ in send(report, from: host) }) |
| 20 | | alert.addAction(UIAlertAction(title: "Show Report", style: .default) { _ in show(report, from: host) }) |
| 21 | | alert.addAction(UIAlertAction(title: "Don’t Send", style: .cancel) { _ in sb_crash_forget() }) |
| 22 | | host.present(alert, animated: true) |
| 21 | alert.addAction(UIAlertAction(title: "Send Report", style: .default) { _ in |
| 22 | send(report, from: host) |
| 23 | then() |
| 24 | }) |
| 25 | alert.addAction(UIAlertAction(title: "Show Report", style: .default) { _ in show(report, from: host, then: then) }) |
| 26 | alert.addAction(UIAlertAction(title: "Don’t Send", style: .cancel) { _ in |
| 27 | sb_crash_forget() |
| 28 | then() |
| 29 | }) |
| 30 | // The scene's window is not yet on screen as it connects. |
| 31 | DispatchQueue.main.async { host.present(alert, animated: true) } |
| 23 | 32 | } |
| 24 | 33 | |
| 25 | | private static func show(_ report: String, from host: UIViewController) { |
| 34 | private static func show(_ report: String, from host: UIViewController, then: @escaping () -> Void) { |
| 26 | 35 | let page = UIViewController() |
| 27 | 36 | page.title = "Crash Report" |
| 28 | 37 | let text = UITextView() |
| ... | ... | @@ -32,12 +41,16 @@ enum Crash { |
| 32 | 41 | text.backgroundColor = .systemBackground |
| 33 | 42 | page.view = text |
| 34 | 43 | let navigation = UINavigationController(rootViewController: page) |
| 44 | navigation.isModalInPresentation = true |
| 35 | 45 | page.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Don’t Send", primaryAction: UIAction { [weak navigation] _ in |
| 36 | 46 | sb_crash_forget() |
| 37 | | navigation?.dismiss(animated: true) |
| 47 | navigation?.dismiss(animated: true, completion: then) |
| 38 | 48 | }) |
| 39 | 49 | page.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Send Report", primaryAction: UIAction { [weak navigation] _ in |
| 40 | | navigation?.dismiss(animated: true) { send(report, from: host) } |
| 50 | navigation?.dismiss(animated: true) { |
| 51 | send(report, from: host) |
| 52 | then() |
| 53 | } |
| 41 | 54 | }) |
| 42 | 55 | host.present(navigation, animated: true) |
| 43 | 56 | } |