Update crash alert copy and navigate to help forum

This commit is contained in:
Angelo Stavrow 2022-06-24 08:40:10 -04:00
parent 5a1b400333
commit efe173cfca
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE

View File

@ -51,18 +51,21 @@ struct WriteFreely_MultiPlatformApp: App {
}
})
.alert(isPresented: $didCrash) {
// TODO: - Confirm copy for this alert
Alert(
title: Text("Crash Detected"),
message: Text(
UserDefaults.shared.object(forKey: WFDefaults.fatalErrorDescription) as? String ??
"Something went horribly wrong!"
),
dismissButton: .default(
Text("Dismiss"), action: {
UserDefaults.shared.set(false, forKey: WFDefaults.didHaveFatalError)
UserDefaults.shared.removeObject(forKey: WFDefaults.fatalErrorDescription)
var helpMsg = "Alert the humans by sharing what happened on the help forum."
if let errorMsg = UserDefaults.shared.object(forKey: WFDefaults.fatalErrorDescription) as? String {
helpMsg.append("\n\n\(errorMsg)")
}
// TODO: - Confirm copy for this alert
return Alert(
title: Text("Crash Detected"),
message: Text(helpMsg),
primaryButton: .default(
Text("Let us know"), action: didPressCrashAlertButton
),
secondaryButton: .cancel(
Text("Dismiss"),
action: resetCrashFlags
)
)
}
@ -163,4 +166,19 @@ struct WriteFreely_MultiPlatformApp: App {
}
}
}
private func resetCrashFlags() {
UserDefaults.shared.set(false, forKey: WFDefaults.didHaveFatalError)
UserDefaults.shared.removeObject(forKey: WFDefaults.fatalErrorDescription)
}
private func didPressCrashAlertButton() {
resetCrashFlags()
#if os(macOS)
NSWorkspace().open(model.helpURL)
#else
UIApplication.shared.open(model.helpURL)
#endif
}
}