mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-01-05 13:58:40 +00:00
28 lines
573 B
Swift
28 lines
573 B
Swift
import Foundation
|
|
import Models
|
|
import Network
|
|
|
|
@MainActor
|
|
public class CurrentInstance: ObservableObject {
|
|
@Published public private(set) var instance: Instance?
|
|
|
|
private var client: Client?
|
|
|
|
public static let shared = CurrentInstance()
|
|
|
|
private init() {}
|
|
|
|
public func setClient(client: Client) {
|
|
self.client = client
|
|
Task {
|
|
await fetchCurrentInstance()
|
|
}
|
|
}
|
|
|
|
public func fetchCurrentInstance() async {
|
|
guard let client = client else { return }
|
|
Task {
|
|
instance = try? await client.get(endpoint: Instances.instance)
|
|
}
|
|
}
|
|
}
|