IceCubes/Packages/Env/Sources/Env/CurrentInstance.swift
2023-02-03 19:44:55 +01:00

32 lines
679 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()
public var isFiltersSupported: Bool {
instance?.version.hasPrefix("4") == true
}
public var isEditSupported: Bool {
instance?.version.hasPrefix("4") == true
}
private init() {}
public func setClient(client: Client) {
self.client = client
}
public func fetchCurrentInstance() async {
guard let client = client else { return }
instance = try? await client.get(endpoint: Instances.instance)
}
}