mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-05-19 08:48:16 +00:00
d1209e6704
Co-authored-by: Jim Dovey <jimdovey@apple.com>
48 lines
973 B
Swift
48 lines
973 B
Swift
import Combine
|
|
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 var version: Float {
|
|
if let stringVersion = instance?.version {
|
|
if stringVersion.utf8.count > 2 {
|
|
return Float(stringVersion.prefix(3)) ?? 0
|
|
} else {
|
|
return Float(stringVersion.prefix(1)) ?? 0
|
|
}
|
|
}
|
|
return 0
|
|
}
|
|
|
|
public var isFiltersSupported: Bool {
|
|
version >= 4
|
|
}
|
|
|
|
public var isEditSupported: Bool {
|
|
version >= 4
|
|
}
|
|
|
|
public var isEditAltTextSupported: Bool {
|
|
version >= 4.1
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|