Move LocalData to app group
This commit is contained in:
parent
b3522a76e1
commit
1dc9903e39
|
@ -20,6 +20,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||||
|
LocalData.migrateIfNecessary()
|
||||||
|
|
||||||
swizzleWKWebView()
|
swizzleWKWebView()
|
||||||
|
|
||||||
Preferences.shared.objectWillChange
|
Preferences.shared.objectWillChange
|
||||||
|
|
|
@ -16,9 +16,11 @@ struct LocalData {
|
||||||
private static let encoder = JSONEncoder()
|
private static let encoder = JSONEncoder()
|
||||||
private static let decoder = JSONDecoder()
|
private static let decoder = JSONDecoder()
|
||||||
|
|
||||||
|
private static var defaults = UserDefaults(suiteName: "group.net.shadowfacts.Reader")!
|
||||||
|
|
||||||
static var accounts: [Account] {
|
static var accounts: [Account] {
|
||||||
get {
|
get {
|
||||||
guard let data = UserDefaults.standard.data(forKey: "accounts"),
|
guard let data = defaults.data(forKey: "accounts"),
|
||||||
let accounts = try? decoder.decode([Account].self, from: data) else {
|
let accounts = try? decoder.decode([Account].self, from: data) else {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
@ -26,16 +28,16 @@ struct LocalData {
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
let data = try! encoder.encode(newValue)
|
let data = try! encoder.encode(newValue)
|
||||||
UserDefaults.standard.set(data, forKey: "accounts")
|
defaults.set(data, forKey: "accounts")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static var mostRecentAccountID: Data? {
|
static var mostRecentAccountID: Data? {
|
||||||
get {
|
get {
|
||||||
return UserDefaults.standard.data(forKey: "mostRecentAccountID")
|
return defaults.data(forKey: "mostRecentAccountID")
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
UserDefaults.standard.set(newValue, forKey: "mostRecentAccountID")
|
defaults.set(newValue, forKey: "mostRecentAccountID")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +52,17 @@ struct LocalData {
|
||||||
return accounts.first(where: { $0.id == id })
|
return accounts.first(where: { $0.id == id })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static func migrateIfNecessary() {
|
||||||
|
if let accounts = UserDefaults.standard.object(forKey: "accounts") {
|
||||||
|
UserDefaults.standard.removeObject(forKey: "accounts")
|
||||||
|
defaults.set(accounts, forKey: "accounts")
|
||||||
|
}
|
||||||
|
if let mostRecentAccountID = UserDefaults.standard.object(forKey: "mostRecentAccountID") {
|
||||||
|
UserDefaults.standard.removeObject(forKey: "mostRecentAccountID")
|
||||||
|
defaults.set(mostRecentAccountID, forKey: "mostRecentAccountID")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct Account: Codable {
|
struct Account: Codable {
|
||||||
let id: Data
|
let id: Data
|
||||||
let instanceURL: URL
|
let instanceURL: URL
|
||||||
|
|
Loading…
Reference in New Issue