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...@@ -190,19 +190,22 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate, UISplitViewContro
190 self.window = window190 self.window = window
191 Notebooks.load()191 Notebooks.load()
192 notebooks.reload()192 notebooks.reload()
193 for notebook in Notebooks.all {193 Crash.offer(from: split) { [weak self] in
194 notebook.open { [weak self] in194 guard let self else { return }
195 self?.notebooks.reload()195 for notebook in Notebooks.all {
196 self?.restore(notebook)196 notebook.open { [weak self] in
197 self?.notebooks.reload()
198 self?.restore(notebook)
199 }
197 }200 }
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)
198 }208 }
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) }
206 }209 }
207210
208 /// A section file Files opens in Snowbound, in place.211 /// A section file Files opens in Snowbound, in place.
apps/ios/Snowbound/Crash.swift+22-9
...@@ -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 }
1111
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 = true18 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 }
2433
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 = .systemBackground41 text.backgroundColor = .systemBackground
33 page.view = text42 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] _ in45 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] _ in49 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 }