authoravatarclover caruso<git@paperclover.net>2026-10-16 14:12:44-07:00
committeravatarclover caruso<git@paperclover.net>2026-10-19 11:25:14-07:00
logc845ee1e2b81dda8f02ee6a6c286c2ed889aeb9e
treee09b3dce212a82813d92403768b2e84128070db5
parentd87e4bf1bd81de7fc0966d3dff01bc3784a51d10
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

fix(ios): offer a crash report before reopening what crashed

The report of the last crash was offered only after launch had begun reopening every notebook and the page shown last. A crash on that path, as a notebook or page that crashes whenever it opens, came again before the alert could be answered, so each launch crashed with the report never sent. Launch now waits for the report to be answered (sent, shown and closed, or declined) before it opens notebooks, restores the page or opens a file from Files. The report sheet can no longer be swiped away, which would have left launch waiting. - After a crash, Snowbound on iPhone asks to send the report before it reopens your notebooks, so a crash on launch can still be reported. Assisted-by: claude-opus-5.5

2 files changed, 36 insertions(+), 20 deletions(-)

apps/ios/Snowbound/App.swift+14-11
......@@ -190,19 +190,22 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate, UISplitViewContro
190190 self.window = window
191191 Notebooks.load()
192192 notebooks.reload()
193 for notebook in Notebooks.all {
194 notebook.open { [weak self] in
195 self?.notebooks.reload()
196 self?.restore(notebook)
193 Crash.offer(from: split) { [weak self] in
194 guard let self else { return }
195 for notebook in Notebooks.all {
196 notebook.open { [weak self] in
197 self?.notebooks.reload()
198 self?.restore(notebook)
199 }
197200 }
201 // iCloud Drive's notebooks list once its folder is found, and again when the account
202 // changes; it may have been found while the report was offered.
203 NotificationCenter.default.addObserver(forName: ICloud.changed, object: nil, queue: .main) { [weak self] _ in
204 self?.notebooks.rescan { self?.restore($0) }
205 }
206 notebooks.rescan { [weak self] in self?.restore($0) }
207 self.scene(scene, openURLContexts: options.urlContexts)
198208 }
199 // iCloud Drive's notebooks list once its folder is found, and again when the account
200 // changes.
201 NotificationCenter.default.addObserver(forName: ICloud.changed, object: nil, queue: .main) { [weak self] _ in
202 self?.notebooks.rescan { self?.restore($0) }
203 }
204 self.scene(scene, openURLContexts: options.urlContexts)
205 DispatchQueue.main.async { Crash.offer(from: self.split) }
206209 }
207210
208211 /// A section file Files opens in Snowbound, in place.
apps/ios/Snowbound/Crash.swift+22-9
......@@ -9,20 +9,29 @@ enum Crash {
99 _ = sb_crash_start(folder.appendingPathComponent("crash.txt").path, build, "iOS \(UIDevice.current.systemVersion)")
1010 }
1111
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() }
1416 let report = String(cString: saved)
1517 sb_string_free(saved)
1618 offered = true
1719 let alert = UIAlertController(
1820 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) }
2332 }
2433
25 private static func show(_ report: String, from host: UIViewController) {
34 private static func show(_ report: String, from host: UIViewController, then: @escaping () -> Void) {
2635 let page = UIViewController()
2736 page.title = "Crash Report"
2837 let text = UITextView()
......@@ -32,12 +41,16 @@ enum Crash {
3241 text.backgroundColor = .systemBackground
3342 page.view = text
3443 let navigation = UINavigationController(rootViewController: page)
44 navigation.isModalInPresentation = true
3545 page.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Don’t Send", primaryAction: UIAction { [weak navigation] _ in
3646 sb_crash_forget()
37 navigation?.dismiss(animated: true)
47 navigation?.dismiss(animated: true, completion: then)
3848 })
3949 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 }
4154 })
4255 host.present(navigation, animated: true)
4356 }