mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-04-29 03:08:46 +00:00
42 lines
1.1 KiB
Swift
42 lines
1.1 KiB
Swift
import Foundation
|
|
import Models
|
|
import Network
|
|
import SwiftUI
|
|
|
|
@MainActor
|
|
public class UserPreferences: ObservableObject {
|
|
public static let sharedDefault = UserDefaults(suiteName: "group.icecubesapps")
|
|
public static let shared = UserPreferences()
|
|
|
|
private var client: Client?
|
|
|
|
@AppStorage("remote_local_timeline") public var remoteLocalTimelines: [String] = []
|
|
@AppStorage("preferred_browser") public var preferredBrowser: PreferredBrowser = .inAppSafari
|
|
@AppStorage("draft_posts") public var draftsPosts: [String] = []
|
|
|
|
public var pushNotificationsCount: Int {
|
|
get {
|
|
Self.sharedDefault?.integer(forKey: "push_notifications_count") ?? 0
|
|
}
|
|
set {
|
|
Self.sharedDefault?.set(newValue, forKey: "push_notifications_count")
|
|
}
|
|
}
|
|
|
|
@Published public var serverPreferences: ServerPreferences?
|
|
|
|
private init() {}
|
|
|
|
public func setClient(client: Client) {
|
|
self.client = client
|
|
Task {
|
|
await refreshServerPreferences()
|
|
}
|
|
}
|
|
|
|
public func refreshServerPreferences() async {
|
|
guard let client, client.isAuth else { return }
|
|
serverPreferences = try? await client.get(endpoint: Accounts.preferences)
|
|
}
|
|
}
|