mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-01-08 07:15:24 +00:00
df98e0f987
This reverts commit 380a6acfd1
.
46 lines
958 B
Swift
46 lines
958 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 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)
|
|
}
|
|
}
|