mirror of
https://github.com/mastodon/mastodon-ios.git
synced 2024-12-16 10:48:49 +01:00
Store accounts in container (IOS-192)
In case you see an empty app: Add your account again. Background: As we need access to the account from the extensions and the extensions can't access the documents-directory but the group-container, well, the accounts will live there from now on.
This commit is contained in:
parent
7f26dfa6d6
commit
45028373d4
@ -17,9 +17,9 @@ public extension FileManager {
|
||||
}
|
||||
|
||||
func accounts(for userId: UserIdentifier) -> [Mastodon.Entity.Account] {
|
||||
guard let documentsDirectory else { return [] }
|
||||
guard let sharedDirectory else { return [] }
|
||||
|
||||
let accountPath = Persistence.accounts(userId).filepath(baseURL: documentsDirectory)
|
||||
let accountPath = Persistence.accounts(userId).filepath(baseURL: sharedDirectory)
|
||||
|
||||
guard let data = try? Data(contentsOf: accountPath) else { return [] }
|
||||
|
||||
@ -38,14 +38,14 @@ public extension FileManager {
|
||||
|
||||
private extension FileManager {
|
||||
private func storeJSON(_ encodable: Encodable, userID: UserIdentifier) {
|
||||
guard let documentsDirectory else { return }
|
||||
guard let sharedDirectory else { return }
|
||||
|
||||
let jsonEncoder = JSONEncoder()
|
||||
jsonEncoder.dateEncodingStrategy = .iso8601
|
||||
do {
|
||||
let data = try jsonEncoder.encode(encodable)
|
||||
|
||||
let accountsPath = Persistence.accounts( userID).filepath(baseURL: documentsDirectory)
|
||||
let accountsPath = Persistence.accounts( userID).filepath(baseURL: sharedDirectory)
|
||||
try data.write(to: accountsPath)
|
||||
} catch {
|
||||
debugPrint(error.localizedDescription)
|
||||
|
@ -1,6 +1,7 @@
|
||||
// Copyright © 2023 Mastodon gGmbH. All rights reserved.
|
||||
|
||||
import Foundation
|
||||
import MastodonCommon
|
||||
|
||||
public extension FileManager {
|
||||
var documentsDirectory: URL? {
|
||||
@ -10,4 +11,8 @@ public extension FileManager {
|
||||
var cachesDirectory: URL? {
|
||||
urls(for: .cachesDirectory, in: .userDomainMask).first
|
||||
}
|
||||
|
||||
var sharedDirectory: URL? {
|
||||
containerURL(forSecurityApplicationGroupIdentifier: AppName.groupID)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user