2023-02-27 05:39:07 +00:00
|
|
|
import Combine
|
2022-12-28 07:06:46 +00:00
|
|
|
import Foundation
|
|
|
|
import Models
|
|
|
|
import Network
|
|
|
|
|
|
|
|
@MainActor
|
|
|
|
public class CurrentInstance: ObservableObject {
|
|
|
|
@Published public private(set) var instance: Instance?
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2022-12-28 07:06:46 +00:00
|
|
|
private var client: Client?
|
2023-01-17 10:36:01 +00:00
|
|
|
|
|
|
|
public static let shared = CurrentInstance()
|
2023-02-12 15:29:41 +00:00
|
|
|
|
2023-02-14 06:03:49 +00:00
|
|
|
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
|
2023-02-12 08:58:21 +00:00
|
|
|
}
|
2023-01-27 19:36:40 +00:00
|
|
|
|
2023-01-25 20:18:34 +00:00
|
|
|
public var isFiltersSupported: Bool {
|
2023-02-14 06:03:49 +00:00
|
|
|
version >= 4
|
2023-01-25 20:18:34 +00:00
|
|
|
}
|
2023-01-27 19:36:40 +00:00
|
|
|
|
2023-01-25 20:18:34 +00:00
|
|
|
public var isEditSupported: Bool {
|
2023-02-14 06:03:49 +00:00
|
|
|
version >= 4
|
2023-01-25 20:18:34 +00:00
|
|
|
}
|
2023-02-12 15:29:41 +00:00
|
|
|
|
2023-02-11 20:38:33 +00:00
|
|
|
public var isEditAltTextSupported: Bool {
|
2023-02-14 06:03:49 +00:00
|
|
|
version >= 4.1
|
2023-02-11 20:38:33 +00:00
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
|
|
|
private init() {}
|
|
|
|
|
2022-12-28 07:06:46 +00:00
|
|
|
public func setClient(client: Client) {
|
|
|
|
self.client = client
|
|
|
|
}
|
2023-01-17 10:36:01 +00:00
|
|
|
|
2022-12-28 07:06:46 +00:00
|
|
|
public func fetchCurrentInstance() async {
|
|
|
|
guard let client = client else { return }
|
2023-02-03 18:44:55 +00:00
|
|
|
instance = try? await client.get(endpoint: Instances.instance)
|
2022-12-28 07:06:46 +00:00
|
|
|
}
|
|
|
|
}
|