| ... | @@ -9,20 +9,29 @@ enum Crash { | ... | @@ -9,20 +9,29 @@ enum Crash { |
| 9 | _ = sb_crash_start(folder.appendingPathComponent("crash.txt").path, build, "iOS \(UIDevice.current.systemVersion)") | 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) { | 12 | /// Offers the last run's report, then runs `then` once it is answered, so that what crashed |
| 13 | guard !offered, let saved = sb_crash_report() else { return } | 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 | let report = String(cString: saved) | 16 | let report = String(cString: saved) |
| 15 | sb_string_free(saved) | 17 | sb_string_free(saved) |
| 16 | offered = true | 18 | offered = true |
| 17 | let alert = UIAlertController( | 19 | let alert = UIAlertController( |
| 18 | title: "Snowbound quit unexpectedly", message: "Send a report to help fix the problem. You can review the report before sending it.", preferredStyle: .alert) | 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) }) | 21 | alert.addAction(UIAlertAction(title: "Send Report", style: .default) { _ in |
| 20 | alert.addAction(UIAlertAction(title: "Show Report", style: .default) { _ in show(report, from: host) }) | 22 | send(report, from: host) |
| 21 | alert.addAction(UIAlertAction(title: "Don’t Send", style: .cancel) { _ in sb_crash_forget() }) | 23 | then() |
| 22 | host.present(alert, animated: true) | 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 | let page = UIViewController() | 35 | let page = UIViewController() |
| 27 | page.title = "Crash Report" | 36 | page.title = "Crash Report" |
| 28 | let text = UITextView() | 37 | let text = UITextView() |
| ... | @@ -32,12 +41,16 @@ enum Crash { | ... | @@ -32,12 +41,16 @@ enum Crash { |
| 32 | text.backgroundColor = .systemBackground | 41 | text.backgroundColor = .systemBackground |
| 33 | page.view = text | 42 | page.view = text |
| 34 | let navigation = UINavigationController(rootViewController: page) | 43 | let navigation = UINavigationController(rootViewController: page) |
| | 44 | navigation.isModalInPresentation = true |
| 35 | page.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Don’t Send", primaryAction: UIAction { [weak navigation] _ in | 45 | page.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Don’t Send", primaryAction: UIAction { [weak navigation] _ in |
| 36 | sb_crash_forget() | 46 | sb_crash_forget() |
| 37 | navigation?.dismiss(animated: true) | 47 | navigation?.dismiss(animated: true, completion: then) |
| 38 | }) | 48 | }) |
| 39 | page.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Send Report", primaryAction: UIAction { [weak navigation] _ in | 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 | host.present(navigation, animated: true) | 55 | host.present(navigation, animated: true) |
| 43 | } | 56 | } |