swiftui-multiplatform/Shared/WriteFreely_MultiPlatformApp.swift

213 lines
7.7 KiB
Swift
Raw Normal View History

2020-07-22 13:57:10 +00:00
import SwiftUI
#if os(macOS)
import Sparkle
#endif
2020-07-22 13:57:10 +00:00
@main
struct CheckForDebugModifier {
static func main() {
#if os(macOS)
if NSEvent.modifierFlags.contains(.shift) {
// Clear the launch-to-last-draft values to load a new draft.
2021-11-05 18:18:36 +00:00
UserDefaults.shared.setValue(false, forKey: WFDefaults.showAllPostsFlag)
UserDefaults.shared.setValue(nil, forKey: WFDefaults.selectedCollectionURL)
UserDefaults.shared.setValue(nil, forKey: WFDefaults.lastDraftURL)
} else {
// No-op
}
#endif
WriteFreely_MultiPlatformApp.main()
}
}
2020-07-22 13:57:10 +00:00
struct WriteFreely_MultiPlatformApp: App {
2021-02-10 20:01:23 +00:00
@StateObject private var model = WriteFreelyModel.shared
2022-12-06 21:41:12 +00:00
private let logger = Logging(for: String(describing: WriteFreely_MultiPlatformApp.self))
#if os(macOS)
2020-12-22 20:06:25 +00:00
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@StateObject var updaterViewModel = MacUpdatesViewModel()
@State private var selectedTab = 0
#endif
Fix bad merges (#215) * Alert on error: shared code commit 00e6fabe1dad243eb49d5ffdd9695bda287b8b53 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Thu Jul 28 07:16:22 2022 -0400 Replace CollectionListModel with FetchRequest in CollectionListView commit d54b9471ba9da5d22c904bbb38a555529d3c15a5 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Thu Jul 28 07:13:13 2022 -0400 Add error handling to iOS post editor commit b48fde47147572fe78379c2bd76430f474ac4822 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Wed Jul 27 12:13:06 2022 -0400 Add error handling to macOS commit 695da810854414620035005b83d9c366669f96ff Author: Angelo Stavrow <contact@angelostavrow.com> Date: Wed Jul 27 12:00:34 2022 -0400 Log fatal errors and present alert on next launch commit 2017a5b43768638089c24cc6ae5193d9342d528d Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun Jul 24 06:22:29 2022 -0400 Clean up todo comment commit 669e07ecd9411eb1de3832514158f025655de1d7 Merge: efe173c b93e0c3 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat Jun 25 12:08:17 2022 -0400 Merge branch 'show-downloadable-logs' into log-localstore-errors commit b93e0c3547e23db53e464a57e2d8df469ae319b2 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat Jun 25 12:07:38 2022 -0400 Refactor class to use protocol commit 9b2572ba41544870ac55a6dfbbe72c808a3f54ba Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat Jun 25 11:17:44 2022 -0400 Refactor logging into reuseable methods commit efe173cfca150e11f9fb3bf874f74602796277a3 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri Jun 24 08:40:10 2022 -0400 Update crash alert copy and navigate to help forum commit 5a1b40033345d216669c6f4b58ba4c28bc90b461 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat Jun 18 08:53:25 2022 -0400 Log fatal crashes and present alert on next launch commit f1b0a20643cb250b943ddc34ede6ae183ded8417 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Wed Jul 27 11:42:05 2022 -0400 Revert "Log fatal errors and present alert on next launch (#212)" This reverts commit 7475b577726faffec856dbdac4c69ed79501b972. commit 7475b577726faffec856dbdac4c69ed79501b972 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Wed Jul 27 09:47:06 2022 -0400 Log fatal errors and present alert on next launch (#212) * Log fatal crashes and present alert on next launch * Update crash alert copy and navigate to help forum * Refactor logging into reuseable methods * Refactor class to use protocol * Clean up todo comment commit a43bd801a8c8a350b488e05300fc9fb93a41af7a Author: Angelo Stavrow <contact@angelostavrow.com> Date: Tue May 31 07:35:40 2022 -0400 Add error handling to Mac app commit a315b0955351e326d1244205e6d879750c1c7543 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Tue May 31 06:51:40 2022 -0400 Cleanup commit 7863c2ba084332a9bae6b3a3a6008e83bd11638f Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat May 28 09:23:16 2022 -0400 Add error handling to post editor commit 2eba4c5c0483b8779068c52e9e6536b121e59d58 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat May 28 07:22:27 2022 -0400 Remove commented-out code commit 230f7a10762266f843b55279695a82d26d062e39 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat May 28 07:17:33 2022 -0400 Delete CollectionListModel in favour of FetchRequest in CollectionListView commit fd37a163b9ac3ec4f710e7847b81a7fb83112d3d Author: Angelo Stavrow <contact@angelostavrow.com> Date: Tue May 31 07:36:43 2022 -0400 Revert "Add error handling to Mac app" This reverts commit b1a8b8b29c7a745ea9733ed0d7266c775b534b47. commit b1a8b8b29c7a745ea9733ed0d7266c775b534b47 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Tue May 31 07:23:41 2022 -0400 Add error handling to Mac app commit 15f84b04c026749f88404a099df3fe840e2a13a0 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Thu May 26 08:08:12 2022 -0400 Handle errors in (most) shared code Two outliers to come back to are: - the LocalStoreManager, where we can’t set a current error in the WriteFreelyModel in methods that can’t throw - the CollectionListModel, where the initializer can’t throw because we use it as a property initializer in CollectionListView commit c5b611b39e16bd339282310ab3a65fdafa98e939 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Thu May 26 07:31:11 2022 -0400 Add FIXME to track silent failure on fetching collections As collections are fetched and added to the `list` property in the CollectionListModel’s initializer, it’s tricky to throw an error here: we call it as a property initializer in CollectionListView, which cannot throw. Consider refactoring this logic such that we’re using, for example, a @FetchRequest in CollectionListView instead. commit b017e21e066dbcf86a3166fc06d19222047b78b9 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Mon May 23 15:52:20 2022 -0400 Handle purging post errors commit 11d2e41ab5d58c405160b81dcdd8597d1e2c552c Author: Angelo Stavrow <contact@angelostavrow.com> Date: Mon May 23 15:12:33 2022 -0400 Add default values for some error strings commit dfb3a08608ed8ec2e2e62ad3010c9d2a67691e51 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri May 13 08:44:13 2022 -0400 Move User Defaults errors to ErrorConstants file commit 223ebf5b7cc1e34e98cc65b980673cbfdbbe527c Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri May 13 08:33:32 2022 -0400 Set current error on API call handlers commit faa557c2b48e3998ace6745a0b1e035ccc320a40 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri May 13 08:01:11 2022 -0400 Set current error on API call failures commit a3b805a31907fe045f47f41da54a1169df653834 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri May 13 07:20:47 2022 -0400 Add error handling to top-level content view commit 3a53bec1845d25853bae6c05fe858fcaa195c7eb Author: Angelo Stavrow <contact@angelostavrow.com> Date: Mon May 9 08:55:43 2022 -0400 Clean up WriteFreelyModel’s published vars commit aefcd0d7994393be7cafbde556cda29b8dad423d Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun May 8 10:18:21 2022 -0400 Fix for temporary debugging commit bf3573895726bfc69cde3fc44960b5d81d29a473 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun May 8 09:17:05 2022 -0400 Handle errors on logout commit 01ba57ae759c87a6ac40050f39bfa9e85e46c103 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun May 8 09:16:46 2022 -0400 Move Account-related error handling up the hierarchy commit 11200a01a0cf2ad453a7a2f6d4004e129d8d2ca6 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun May 1 12:06:36 2022 -0400 Initial work on presenting alert on error * Bump writefreely-swift package minimum version commit 91e28522437f54f00b4b4854458ce5137721a481 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat May 28 06:50:34 2022 -0400 Bump writefreely-swift package minimum version
2022-07-28 11:47:39 +00:00
@State private var didCrash = UserDefaults.shared.bool(forKey: WFDefaults.didHaveFatalError)
2020-07-22 13:57:10 +00:00
var body: some Scene {
WindowGroup {
2020-12-01 14:53:09 +00:00
ContentView()
2020-11-04 20:23:03 +00:00
.onAppear(perform: {
2021-09-24 19:29:20 +00:00
if model.editor.showAllPostsFlag {
DispatchQueue.main.async {
self.model.selectedCollection = nil
self.model.showAllPosts = true
showLastDraftOrCreateNewLocalPost()
}
} else {
DispatchQueue.main.async {
self.model.selectedCollection = model.editor.fetchSelectedCollectionFromAppStorage()
self.model.showAllPosts = false
showLastDraftOrCreateNewLocalPost()
}
}
2020-11-04 20:23:03 +00:00
})
Fix bad merges (#215) * Alert on error: shared code commit 00e6fabe1dad243eb49d5ffdd9695bda287b8b53 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Thu Jul 28 07:16:22 2022 -0400 Replace CollectionListModel with FetchRequest in CollectionListView commit d54b9471ba9da5d22c904bbb38a555529d3c15a5 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Thu Jul 28 07:13:13 2022 -0400 Add error handling to iOS post editor commit b48fde47147572fe78379c2bd76430f474ac4822 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Wed Jul 27 12:13:06 2022 -0400 Add error handling to macOS commit 695da810854414620035005b83d9c366669f96ff Author: Angelo Stavrow <contact@angelostavrow.com> Date: Wed Jul 27 12:00:34 2022 -0400 Log fatal errors and present alert on next launch commit 2017a5b43768638089c24cc6ae5193d9342d528d Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun Jul 24 06:22:29 2022 -0400 Clean up todo comment commit 669e07ecd9411eb1de3832514158f025655de1d7 Merge: efe173c b93e0c3 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat Jun 25 12:08:17 2022 -0400 Merge branch 'show-downloadable-logs' into log-localstore-errors commit b93e0c3547e23db53e464a57e2d8df469ae319b2 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat Jun 25 12:07:38 2022 -0400 Refactor class to use protocol commit 9b2572ba41544870ac55a6dfbbe72c808a3f54ba Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat Jun 25 11:17:44 2022 -0400 Refactor logging into reuseable methods commit efe173cfca150e11f9fb3bf874f74602796277a3 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri Jun 24 08:40:10 2022 -0400 Update crash alert copy and navigate to help forum commit 5a1b40033345d216669c6f4b58ba4c28bc90b461 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat Jun 18 08:53:25 2022 -0400 Log fatal crashes and present alert on next launch commit f1b0a20643cb250b943ddc34ede6ae183ded8417 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Wed Jul 27 11:42:05 2022 -0400 Revert "Log fatal errors and present alert on next launch (#212)" This reverts commit 7475b577726faffec856dbdac4c69ed79501b972. commit 7475b577726faffec856dbdac4c69ed79501b972 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Wed Jul 27 09:47:06 2022 -0400 Log fatal errors and present alert on next launch (#212) * Log fatal crashes and present alert on next launch * Update crash alert copy and navigate to help forum * Refactor logging into reuseable methods * Refactor class to use protocol * Clean up todo comment commit a43bd801a8c8a350b488e05300fc9fb93a41af7a Author: Angelo Stavrow <contact@angelostavrow.com> Date: Tue May 31 07:35:40 2022 -0400 Add error handling to Mac app commit a315b0955351e326d1244205e6d879750c1c7543 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Tue May 31 06:51:40 2022 -0400 Cleanup commit 7863c2ba084332a9bae6b3a3a6008e83bd11638f Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat May 28 09:23:16 2022 -0400 Add error handling to post editor commit 2eba4c5c0483b8779068c52e9e6536b121e59d58 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat May 28 07:22:27 2022 -0400 Remove commented-out code commit 230f7a10762266f843b55279695a82d26d062e39 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat May 28 07:17:33 2022 -0400 Delete CollectionListModel in favour of FetchRequest in CollectionListView commit fd37a163b9ac3ec4f710e7847b81a7fb83112d3d Author: Angelo Stavrow <contact@angelostavrow.com> Date: Tue May 31 07:36:43 2022 -0400 Revert "Add error handling to Mac app" This reverts commit b1a8b8b29c7a745ea9733ed0d7266c775b534b47. commit b1a8b8b29c7a745ea9733ed0d7266c775b534b47 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Tue May 31 07:23:41 2022 -0400 Add error handling to Mac app commit 15f84b04c026749f88404a099df3fe840e2a13a0 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Thu May 26 08:08:12 2022 -0400 Handle errors in (most) shared code Two outliers to come back to are: - the LocalStoreManager, where we can’t set a current error in the WriteFreelyModel in methods that can’t throw - the CollectionListModel, where the initializer can’t throw because we use it as a property initializer in CollectionListView commit c5b611b39e16bd339282310ab3a65fdafa98e939 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Thu May 26 07:31:11 2022 -0400 Add FIXME to track silent failure on fetching collections As collections are fetched and added to the `list` property in the CollectionListModel’s initializer, it’s tricky to throw an error here: we call it as a property initializer in CollectionListView, which cannot throw. Consider refactoring this logic such that we’re using, for example, a @FetchRequest in CollectionListView instead. commit b017e21e066dbcf86a3166fc06d19222047b78b9 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Mon May 23 15:52:20 2022 -0400 Handle purging post errors commit 11d2e41ab5d58c405160b81dcdd8597d1e2c552c Author: Angelo Stavrow <contact@angelostavrow.com> Date: Mon May 23 15:12:33 2022 -0400 Add default values for some error strings commit dfb3a08608ed8ec2e2e62ad3010c9d2a67691e51 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri May 13 08:44:13 2022 -0400 Move User Defaults errors to ErrorConstants file commit 223ebf5b7cc1e34e98cc65b980673cbfdbbe527c Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri May 13 08:33:32 2022 -0400 Set current error on API call handlers commit faa557c2b48e3998ace6745a0b1e035ccc320a40 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri May 13 08:01:11 2022 -0400 Set current error on API call failures commit a3b805a31907fe045f47f41da54a1169df653834 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri May 13 07:20:47 2022 -0400 Add error handling to top-level content view commit 3a53bec1845d25853bae6c05fe858fcaa195c7eb Author: Angelo Stavrow <contact@angelostavrow.com> Date: Mon May 9 08:55:43 2022 -0400 Clean up WriteFreelyModel’s published vars commit aefcd0d7994393be7cafbde556cda29b8dad423d Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun May 8 10:18:21 2022 -0400 Fix for temporary debugging commit bf3573895726bfc69cde3fc44960b5d81d29a473 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun May 8 09:17:05 2022 -0400 Handle errors on logout commit 01ba57ae759c87a6ac40050f39bfa9e85e46c103 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun May 8 09:16:46 2022 -0400 Move Account-related error handling up the hierarchy commit 11200a01a0cf2ad453a7a2f6d4004e129d8d2ca6 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun May 1 12:06:36 2022 -0400 Initial work on presenting alert on error * Bump writefreely-swift package minimum version commit 91e28522437f54f00b4b4854458ce5137721a481 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat May 28 06:50:34 2022 -0400 Bump writefreely-swift package minimum version
2022-07-28 11:47:39 +00:00
.alert(isPresented: $didCrash) {
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)")
}
return Alert(
title: Text("Crash Detected"),
message: Text(helpMsg),
primaryButton: .default(
Text("Let us know"), action: didPressCrashAlertButton
),
secondaryButton: .cancel(
Text("Dismiss"),
action: resetCrashFlags
)
)
}
2022-12-06 21:41:12 +00:00
.onAppear {
if #available(iOS 15, *) {
if didCrash { generateCrashLogPost() }
}
}
.withErrorHandling()
.environmentObject(model)
.environment(\.managedObjectContext, LocalStorageManager.standard.container.viewContext)
// .preferredColorScheme(preferences.selectedColorScheme) // See PreferencesModel for info.
2020-07-22 13:57:10 +00:00
}
.commands {
#if os(macOS)
CommandGroup(after: .appInfo) {
CheckForUpdatesView(updaterViewModel: updaterViewModel)
}
#endif
CommandGroup(replacing: .newItem, addition: {
Button("New Post") {
createNewLocalPost()
}
.keyboardShortcut("n", modifiers: [.command])
})
CommandGroup(after: .newItem) {
Button("Refresh Posts") {
DispatchQueue.main.async {
model.fetchUserCollections()
model.fetchUserPosts()
}
}
.disabled(!model.account.isLoggedIn)
.keyboardShortcut("r", modifiers: [.command])
}
SidebarCommands()
#if os(macOS)
PostCommands(model: model)
HelpCommands(model: model)
#endif
ToolbarCommands()
TextEditingCommands()
}
#if os(macOS)
Settings {
TabView(selection: $selectedTab) {
MacAccountView()
.environmentObject(model)
.tabItem {
Image(systemName: "person.crop.circle")
Text("Account")
}
.tag(0)
MacPreferencesView(preferences: model.preferences)
.tabItem {
Image(systemName: "gear")
Text("Preferences")
}
.tag(1)
MacUpdatesView(updaterViewModel: updaterViewModel)
.tabItem {
Image(systemName: "arrow.down.circle")
Text("Updates")
}
.tag(2)
}
.environmentObject(model)
.withErrorHandling()
.frame(minWidth: 500, maxWidth: 500, minHeight: 200)
.padding()
// .preferredColorScheme(preferences.selectedColorScheme) // See PreferencesModel for info.
}
#endif
2020-07-22 13:57:10 +00:00
}
2020-11-04 20:23:03 +00:00
2021-09-24 19:29:20 +00:00
private func showLastDraftOrCreateNewLocalPost() {
if model.editor.lastDraftURL != nil {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
self.model.selectedPost = model.editor.fetchLastDraftFromAppStorage()
}
2021-09-24 19:29:20 +00:00
} else {
createNewLocalPost()
}
}
2020-11-04 20:23:03 +00:00
private func createNewLocalPost() {
withAnimation {
// Un-set the currently selected post
self.model.selectedPost = nil
}
// Create the new-post managed object
let managedPost = model.editor.generateNewLocalPost(withFont: model.preferences.font)
withAnimation {
// Set it as the selectedPost
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) {
self.model.selectedPost = managedPost
}
}
2020-11-04 20:23:03 +00:00
}
Fix bad merges (#215) * Alert on error: shared code commit 00e6fabe1dad243eb49d5ffdd9695bda287b8b53 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Thu Jul 28 07:16:22 2022 -0400 Replace CollectionListModel with FetchRequest in CollectionListView commit d54b9471ba9da5d22c904bbb38a555529d3c15a5 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Thu Jul 28 07:13:13 2022 -0400 Add error handling to iOS post editor commit b48fde47147572fe78379c2bd76430f474ac4822 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Wed Jul 27 12:13:06 2022 -0400 Add error handling to macOS commit 695da810854414620035005b83d9c366669f96ff Author: Angelo Stavrow <contact@angelostavrow.com> Date: Wed Jul 27 12:00:34 2022 -0400 Log fatal errors and present alert on next launch commit 2017a5b43768638089c24cc6ae5193d9342d528d Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun Jul 24 06:22:29 2022 -0400 Clean up todo comment commit 669e07ecd9411eb1de3832514158f025655de1d7 Merge: efe173c b93e0c3 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat Jun 25 12:08:17 2022 -0400 Merge branch 'show-downloadable-logs' into log-localstore-errors commit b93e0c3547e23db53e464a57e2d8df469ae319b2 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat Jun 25 12:07:38 2022 -0400 Refactor class to use protocol commit 9b2572ba41544870ac55a6dfbbe72c808a3f54ba Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat Jun 25 11:17:44 2022 -0400 Refactor logging into reuseable methods commit efe173cfca150e11f9fb3bf874f74602796277a3 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri Jun 24 08:40:10 2022 -0400 Update crash alert copy and navigate to help forum commit 5a1b40033345d216669c6f4b58ba4c28bc90b461 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat Jun 18 08:53:25 2022 -0400 Log fatal crashes and present alert on next launch commit f1b0a20643cb250b943ddc34ede6ae183ded8417 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Wed Jul 27 11:42:05 2022 -0400 Revert "Log fatal errors and present alert on next launch (#212)" This reverts commit 7475b577726faffec856dbdac4c69ed79501b972. commit 7475b577726faffec856dbdac4c69ed79501b972 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Wed Jul 27 09:47:06 2022 -0400 Log fatal errors and present alert on next launch (#212) * Log fatal crashes and present alert on next launch * Update crash alert copy and navigate to help forum * Refactor logging into reuseable methods * Refactor class to use protocol * Clean up todo comment commit a43bd801a8c8a350b488e05300fc9fb93a41af7a Author: Angelo Stavrow <contact@angelostavrow.com> Date: Tue May 31 07:35:40 2022 -0400 Add error handling to Mac app commit a315b0955351e326d1244205e6d879750c1c7543 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Tue May 31 06:51:40 2022 -0400 Cleanup commit 7863c2ba084332a9bae6b3a3a6008e83bd11638f Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat May 28 09:23:16 2022 -0400 Add error handling to post editor commit 2eba4c5c0483b8779068c52e9e6536b121e59d58 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat May 28 07:22:27 2022 -0400 Remove commented-out code commit 230f7a10762266f843b55279695a82d26d062e39 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat May 28 07:17:33 2022 -0400 Delete CollectionListModel in favour of FetchRequest in CollectionListView commit fd37a163b9ac3ec4f710e7847b81a7fb83112d3d Author: Angelo Stavrow <contact@angelostavrow.com> Date: Tue May 31 07:36:43 2022 -0400 Revert "Add error handling to Mac app" This reverts commit b1a8b8b29c7a745ea9733ed0d7266c775b534b47. commit b1a8b8b29c7a745ea9733ed0d7266c775b534b47 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Tue May 31 07:23:41 2022 -0400 Add error handling to Mac app commit 15f84b04c026749f88404a099df3fe840e2a13a0 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Thu May 26 08:08:12 2022 -0400 Handle errors in (most) shared code Two outliers to come back to are: - the LocalStoreManager, where we can’t set a current error in the WriteFreelyModel in methods that can’t throw - the CollectionListModel, where the initializer can’t throw because we use it as a property initializer in CollectionListView commit c5b611b39e16bd339282310ab3a65fdafa98e939 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Thu May 26 07:31:11 2022 -0400 Add FIXME to track silent failure on fetching collections As collections are fetched and added to the `list` property in the CollectionListModel’s initializer, it’s tricky to throw an error here: we call it as a property initializer in CollectionListView, which cannot throw. Consider refactoring this logic such that we’re using, for example, a @FetchRequest in CollectionListView instead. commit b017e21e066dbcf86a3166fc06d19222047b78b9 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Mon May 23 15:52:20 2022 -0400 Handle purging post errors commit 11d2e41ab5d58c405160b81dcdd8597d1e2c552c Author: Angelo Stavrow <contact@angelostavrow.com> Date: Mon May 23 15:12:33 2022 -0400 Add default values for some error strings commit dfb3a08608ed8ec2e2e62ad3010c9d2a67691e51 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri May 13 08:44:13 2022 -0400 Move User Defaults errors to ErrorConstants file commit 223ebf5b7cc1e34e98cc65b980673cbfdbbe527c Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri May 13 08:33:32 2022 -0400 Set current error on API call handlers commit faa557c2b48e3998ace6745a0b1e035ccc320a40 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri May 13 08:01:11 2022 -0400 Set current error on API call failures commit a3b805a31907fe045f47f41da54a1169df653834 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri May 13 07:20:47 2022 -0400 Add error handling to top-level content view commit 3a53bec1845d25853bae6c05fe858fcaa195c7eb Author: Angelo Stavrow <contact@angelostavrow.com> Date: Mon May 9 08:55:43 2022 -0400 Clean up WriteFreelyModel’s published vars commit aefcd0d7994393be7cafbde556cda29b8dad423d Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun May 8 10:18:21 2022 -0400 Fix for temporary debugging commit bf3573895726bfc69cde3fc44960b5d81d29a473 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun May 8 09:17:05 2022 -0400 Handle errors on logout commit 01ba57ae759c87a6ac40050f39bfa9e85e46c103 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun May 8 09:16:46 2022 -0400 Move Account-related error handling up the hierarchy commit 11200a01a0cf2ad453a7a2f6d4004e129d8d2ca6 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun May 1 12:06:36 2022 -0400 Initial work on presenting alert on error * Bump writefreely-swift package minimum version commit 91e28522437f54f00b4b4854458ce5137721a481 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat May 28 06:50:34 2022 -0400 Bump writefreely-swift package minimum version
2022-07-28 11:47:39 +00:00
2022-12-06 21:41:12 +00:00
@available(iOS 15, *)
private func generateCrashLogPost() {
logger.log("Generating local log post...")
DispatchQueue.main.asyncAfter(deadline: .now()) {
// Unset selected post and collection and navigate to local drafts.
self.model.selectedPost = nil
self.model.selectedCollection = nil
self.model.showAllPosts = false
// Create the new log post.
let newLogPost = model.editor.generateNewLocalPost(withFont: 2)
newLogPost.title = "Logs For Support"
var postBody: [String] = [
"WriteFreely-Multiplatform v\(Bundle.main.appMarketingVersion) (\(Bundle.main.appBuildVersion))",
"Generated \(Date())",
""
]
postBody.append(contentsOf: logger.fetchLogs())
newLogPost.body = postBody.joined(separator: "\n")
self.model.selectedPost = newLogPost
}
logger.log("Generated local log post.")
}
Fix bad merges (#215) * Alert on error: shared code commit 00e6fabe1dad243eb49d5ffdd9695bda287b8b53 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Thu Jul 28 07:16:22 2022 -0400 Replace CollectionListModel with FetchRequest in CollectionListView commit d54b9471ba9da5d22c904bbb38a555529d3c15a5 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Thu Jul 28 07:13:13 2022 -0400 Add error handling to iOS post editor commit b48fde47147572fe78379c2bd76430f474ac4822 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Wed Jul 27 12:13:06 2022 -0400 Add error handling to macOS commit 695da810854414620035005b83d9c366669f96ff Author: Angelo Stavrow <contact@angelostavrow.com> Date: Wed Jul 27 12:00:34 2022 -0400 Log fatal errors and present alert on next launch commit 2017a5b43768638089c24cc6ae5193d9342d528d Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun Jul 24 06:22:29 2022 -0400 Clean up todo comment commit 669e07ecd9411eb1de3832514158f025655de1d7 Merge: efe173c b93e0c3 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat Jun 25 12:08:17 2022 -0400 Merge branch 'show-downloadable-logs' into log-localstore-errors commit b93e0c3547e23db53e464a57e2d8df469ae319b2 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat Jun 25 12:07:38 2022 -0400 Refactor class to use protocol commit 9b2572ba41544870ac55a6dfbbe72c808a3f54ba Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat Jun 25 11:17:44 2022 -0400 Refactor logging into reuseable methods commit efe173cfca150e11f9fb3bf874f74602796277a3 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri Jun 24 08:40:10 2022 -0400 Update crash alert copy and navigate to help forum commit 5a1b40033345d216669c6f4b58ba4c28bc90b461 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat Jun 18 08:53:25 2022 -0400 Log fatal crashes and present alert on next launch commit f1b0a20643cb250b943ddc34ede6ae183ded8417 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Wed Jul 27 11:42:05 2022 -0400 Revert "Log fatal errors and present alert on next launch (#212)" This reverts commit 7475b577726faffec856dbdac4c69ed79501b972. commit 7475b577726faffec856dbdac4c69ed79501b972 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Wed Jul 27 09:47:06 2022 -0400 Log fatal errors and present alert on next launch (#212) * Log fatal crashes and present alert on next launch * Update crash alert copy and navigate to help forum * Refactor logging into reuseable methods * Refactor class to use protocol * Clean up todo comment commit a43bd801a8c8a350b488e05300fc9fb93a41af7a Author: Angelo Stavrow <contact@angelostavrow.com> Date: Tue May 31 07:35:40 2022 -0400 Add error handling to Mac app commit a315b0955351e326d1244205e6d879750c1c7543 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Tue May 31 06:51:40 2022 -0400 Cleanup commit 7863c2ba084332a9bae6b3a3a6008e83bd11638f Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat May 28 09:23:16 2022 -0400 Add error handling to post editor commit 2eba4c5c0483b8779068c52e9e6536b121e59d58 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat May 28 07:22:27 2022 -0400 Remove commented-out code commit 230f7a10762266f843b55279695a82d26d062e39 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat May 28 07:17:33 2022 -0400 Delete CollectionListModel in favour of FetchRequest in CollectionListView commit fd37a163b9ac3ec4f710e7847b81a7fb83112d3d Author: Angelo Stavrow <contact@angelostavrow.com> Date: Tue May 31 07:36:43 2022 -0400 Revert "Add error handling to Mac app" This reverts commit b1a8b8b29c7a745ea9733ed0d7266c775b534b47. commit b1a8b8b29c7a745ea9733ed0d7266c775b534b47 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Tue May 31 07:23:41 2022 -0400 Add error handling to Mac app commit 15f84b04c026749f88404a099df3fe840e2a13a0 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Thu May 26 08:08:12 2022 -0400 Handle errors in (most) shared code Two outliers to come back to are: - the LocalStoreManager, where we can’t set a current error in the WriteFreelyModel in methods that can’t throw - the CollectionListModel, where the initializer can’t throw because we use it as a property initializer in CollectionListView commit c5b611b39e16bd339282310ab3a65fdafa98e939 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Thu May 26 07:31:11 2022 -0400 Add FIXME to track silent failure on fetching collections As collections are fetched and added to the `list` property in the CollectionListModel’s initializer, it’s tricky to throw an error here: we call it as a property initializer in CollectionListView, which cannot throw. Consider refactoring this logic such that we’re using, for example, a @FetchRequest in CollectionListView instead. commit b017e21e066dbcf86a3166fc06d19222047b78b9 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Mon May 23 15:52:20 2022 -0400 Handle purging post errors commit 11d2e41ab5d58c405160b81dcdd8597d1e2c552c Author: Angelo Stavrow <contact@angelostavrow.com> Date: Mon May 23 15:12:33 2022 -0400 Add default values for some error strings commit dfb3a08608ed8ec2e2e62ad3010c9d2a67691e51 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri May 13 08:44:13 2022 -0400 Move User Defaults errors to ErrorConstants file commit 223ebf5b7cc1e34e98cc65b980673cbfdbbe527c Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri May 13 08:33:32 2022 -0400 Set current error on API call handlers commit faa557c2b48e3998ace6745a0b1e035ccc320a40 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri May 13 08:01:11 2022 -0400 Set current error on API call failures commit a3b805a31907fe045f47f41da54a1169df653834 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Fri May 13 07:20:47 2022 -0400 Add error handling to top-level content view commit 3a53bec1845d25853bae6c05fe858fcaa195c7eb Author: Angelo Stavrow <contact@angelostavrow.com> Date: Mon May 9 08:55:43 2022 -0400 Clean up WriteFreelyModel’s published vars commit aefcd0d7994393be7cafbde556cda29b8dad423d Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun May 8 10:18:21 2022 -0400 Fix for temporary debugging commit bf3573895726bfc69cde3fc44960b5d81d29a473 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun May 8 09:17:05 2022 -0400 Handle errors on logout commit 01ba57ae759c87a6ac40050f39bfa9e85e46c103 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun May 8 09:16:46 2022 -0400 Move Account-related error handling up the hierarchy commit 11200a01a0cf2ad453a7a2f6d4004e129d8d2ca6 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sun May 1 12:06:36 2022 -0400 Initial work on presenting alert on error * Bump writefreely-swift package minimum version commit 91e28522437f54f00b4b4854458ce5137721a481 Author: Angelo Stavrow <contact@angelostavrow.com> Date: Sat May 28 06:50:34 2022 -0400 Bump writefreely-swift package minimum version
2022-07-28 11:47:39 +00:00
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
}
2020-07-22 13:57:10 +00:00
}