swiftui-multiplatform/Shared/Extensions/UserDefaults+Extensions.swift

60 lines
2.2 KiB
Swift
Raw Normal View History

2021-11-05 18:18:36 +00:00
import Foundation
enum WFDefaults {
static let isLoggedIn = "isLoggedIn"
static let showAllPostsFlag = "showAllPostsFlag"
static let selectedCollectionURL = "selectedCollectionURL"
static let lastDraftURL = "lastDraftURL"
2021-11-19 20:41:54 +00:00
static let colorSchemeIntegerKey = "colorSchemeIntegerKey"
static let defaultFontIntegerKey = "defaultFontIntegerKey"
static let usernameStringKey = "usernameStringKey"
static let serverStringKey = "serverStringKey"
2021-11-05 18:18:36 +00:00
#if os(macOS)
static let automaticallyChecksForUpdates = "automaticallyChecksForUpdates"
static let subscribeToBetaUpdates = "subscribeToBetaUpdates"
#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
static let didHaveFatalError = "didHaveFatalError"
static let fatalErrorDescription = "fatalErrorDescription"
2021-11-05 18:18:36 +00:00
}
extension UserDefaults {
private static let appGroupName: String = "group.com.abunchtell.writefreely"
private static let didMigrateDefaultsToAppGroup: String = "didMigrateDefaultsToAppGroup"
private static let didRemoveStandardDefaults: String = "didRemoveStandardDefaults"
static var shared: UserDefaults {
if let groupDefaults = UserDefaults(suiteName: UserDefaults.appGroupName),
groupDefaults.bool(forKey: UserDefaults.didMigrateDefaultsToAppGroup) {
return groupDefaults
} else {
do {
let groupDefaults = try UserDefaults.standard.migrateDefaultsToAppGroup()
return groupDefaults
} catch {
return UserDefaults.standard
}
}
}
private func migrateDefaultsToAppGroup() throws -> UserDefaults {
let userDefaults = UserDefaults.standard
let groupDefaults = UserDefaults(suiteName: UserDefaults.appGroupName)
if let groupDefaults = groupDefaults {
if groupDefaults.bool(forKey: UserDefaults.didMigrateDefaultsToAppGroup) {
return groupDefaults
}
for (key, value) in userDefaults.dictionaryRepresentation() {
groupDefaults.set(value, forKey: key)
}
groupDefaults.set(true, forKey: UserDefaults.didMigrateDefaultsToAppGroup)
return groupDefaults
} else {
throw UserDefaultsError.couldNotMigrateStandardDefaults
2021-11-05 18:18:36 +00:00
}
}
}