krz/hutch

an ios client for sourcehut

clone: git clone https://gitbay.org/krz/hutch.git

v3.9.0: Hutch/App/AccountSession.swift · raw

 1import Foundation
 2
 3struct AccountSession: Sendable {
 4    let account: AccountEntry
 5    let user: User
 6    let client: SRHTClient
 7    let defaults: UserDefaults
 8    let systemStatusRepository: SystemStatusRepository
 9
10    var id: String {
11        account.id
12    }
13}
14
15enum AccountDefaultsStore {
16    private static let suitePrefix = "net.cleberg.Hutch.account"
17
18    static func userDefaults(for accountID: String) -> UserDefaults {
19        let suiteName = suiteName(for: accountID)
20        return UserDefaults(suiteName: suiteName) ?? .standard
21    }
22
23    static func clear(accountID: String) {
24        let suiteName = suiteName(for: accountID)
25        guard let defaults = UserDefaults(suiteName: suiteName) else { return }
26        defaults.removePersistentDomain(forName: suiteName)
27    }
28
29    private static func suiteName(for accountID: String) -> String {
30        "\(suitePrefix).\(accountID)"
31    }
32}