diff --git a/apps/ios/Snowbound/App.swift b/apps/ios/Snowbound/App.swift index 3c21ff5aa88f80e86df32343509298732ece7102..ba526a51fbc4eef43feb9bd437ad5324abc67500 100644 --- a/apps/ios/Snowbound/App.swift +++ b/apps/ios/Snowbound/App.swift @@ -190,19 +190,22 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate, UISplitViewContro self.window = window Notebooks.load() notebooks.reload() - for notebook in Notebooks.all { - notebook.open { [weak self] in - self?.notebooks.reload() - self?.restore(notebook) + Crash.offer(from: split) { [weak self] in + guard let self else { return } + for notebook in Notebooks.all { + notebook.open { [weak self] in + self?.notebooks.reload() + self?.restore(notebook) + } } + // iCloud Drive's notebooks list once its folder is found, and again when the account + // changes; it may have been found while the report was offered. + NotificationCenter.default.addObserver(forName: ICloud.changed, object: nil, queue: .main) { [weak self] _ in + self?.notebooks.rescan { self?.restore($0) } + } + notebooks.rescan { [weak self] in self?.restore($0) } + self.scene(scene, openURLContexts: options.urlContexts) } - // iCloud Drive's notebooks list once its folder is found, and again when the account - // changes. - NotificationCenter.default.addObserver(forName: ICloud.changed, object: nil, queue: .main) { [weak self] _ in - self?.notebooks.rescan { self?.restore($0) } - } - self.scene(scene, openURLContexts: options.urlContexts) - DispatchQueue.main.async { Crash.offer(from: self.split) } } /// A section file Files opens in Snowbound, in place. diff --git a/apps/ios/Snowbound/Crash.swift b/apps/ios/Snowbound/Crash.swift index 4e162b88ecd57fec482d81403d413a286343d8b9..59f04c813c2eb92caca64bc8def678a94b818bdc 100644 --- a/apps/ios/Snowbound/Crash.swift +++ b/apps/ios/Snowbound/Crash.swift @@ -9,20 +9,29 @@ enum Crash { _ = sb_crash_start(folder.appendingPathComponent("crash.txt").path, build, "iOS \(UIDevice.current.systemVersion)") } - static func offer(from host: UIViewController) { - guard !offered, let saved = sb_crash_report() else { return } + /// Offers the last run's report, then runs `then` once it is answered, so that what crashed + /// that run does not open again before the report can be sent; at once where there is none. + static func offer(from host: UIViewController, then: @escaping () -> Void) { + guard !offered, let saved = sb_crash_report() else { return then() } let report = String(cString: saved) sb_string_free(saved) offered = true let alert = UIAlertController( title: "Snowbound quit unexpectedly", message: "Send a report to help fix the problem. You can review the report before sending it.", preferredStyle: .alert) - alert.addAction(UIAlertAction(title: "Send Report", style: .default) { _ in send(report, from: host) }) - alert.addAction(UIAlertAction(title: "Show Report", style: .default) { _ in show(report, from: host) }) - alert.addAction(UIAlertAction(title: "Don’t Send", style: .cancel) { _ in sb_crash_forget() }) - host.present(alert, animated: true) + alert.addAction(UIAlertAction(title: "Send Report", style: .default) { _ in + send(report, from: host) + then() + }) + alert.addAction(UIAlertAction(title: "Show Report", style: .default) { _ in show(report, from: host, then: then) }) + alert.addAction(UIAlertAction(title: "Don’t Send", style: .cancel) { _ in + sb_crash_forget() + then() + }) + // The scene's window is not yet on screen as it connects. + DispatchQueue.main.async { host.present(alert, animated: true) } } - private static func show(_ report: String, from host: UIViewController) { + private static func show(_ report: String, from host: UIViewController, then: @escaping () -> Void) { let page = UIViewController() page.title = "Crash Report" let text = UITextView() @@ -32,12 +41,16 @@ enum Crash { text.backgroundColor = .systemBackground page.view = text let navigation = UINavigationController(rootViewController: page) + navigation.isModalInPresentation = true page.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Don’t Send", primaryAction: UIAction { [weak navigation] _ in sb_crash_forget() - navigation?.dismiss(animated: true) + navigation?.dismiss(animated: true, completion: then) }) page.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Send Report", primaryAction: UIAction { [weak navigation] _ in - navigation?.dismiss(animated: true) { send(report, from: host) } + navigation?.dismiss(animated: true) { + send(report, from: host) + then() + } }) host.present(navigation, animated: true) }