mirror of
https://github.com/xtool-org/xtool.git
synced 2026-11-15 12:04:55 +03:00
Default DeviceInfoProvider
This commit is contained in:
@@ -83,7 +83,7 @@ extension DeviceInfo {
|
||||
}
|
||||
|
||||
}
|
||||
#elseif os(Linux) || os(Windows)
|
||||
#else
|
||||
extension DeviceInfo {
|
||||
public static func current() -> DeviceInfo? {
|
||||
return DeviceInfo(
|
||||
@@ -97,5 +97,5 @@ extension DeviceInfo {
|
||||
}
|
||||
#endif
|
||||
|
||||
// FIXME: Figure out DeviceInfo.current() on Windows/Linux
|
||||
// FIXME: Figure out DeviceInfo.current() outside macOS
|
||||
// (see above)
|
||||
|
||||
@@ -92,14 +92,28 @@ public struct DeviceInfo: Codable, Sendable {
|
||||
|
||||
}
|
||||
|
||||
public struct DeviceInfoProvider: TestDependencyKey, Sendable {
|
||||
extension DeviceInfo {
|
||||
public enum FetchError: Error {
|
||||
case couldNotFetch
|
||||
}
|
||||
|
||||
fileprivate static func fetch() throws -> Self {
|
||||
guard let deviceInfo = DeviceInfo.current() else {
|
||||
throw FetchError.couldNotFetch
|
||||
}
|
||||
return deviceInfo
|
||||
}
|
||||
}
|
||||
|
||||
public struct DeviceInfoProvider: DependencyKey, Sendable {
|
||||
public var fetch: @Sendable () throws -> DeviceInfo
|
||||
|
||||
public init(fetch: @escaping @Sendable () throws -> DeviceInfo) {
|
||||
self.fetch = fetch
|
||||
}
|
||||
|
||||
public static let testValue = DeviceInfoProvider(fetch: unimplemented())
|
||||
private static let current = Result { try DeviceInfo.fetch() }
|
||||
public static let liveValue = DeviceInfoProvider { try current.get() }
|
||||
}
|
||||
|
||||
extension DependencyValues {
|
||||
|
||||
@@ -201,17 +201,3 @@ struct AuthCommand: AsyncParsableCommand {
|
||||
defaultSubcommand: AuthLoginCommand.self
|
||||
)
|
||||
}
|
||||
|
||||
extension DeviceInfo {
|
||||
static func fetch() throws -> Self {
|
||||
guard let deviceInfo = DeviceInfo.current() else {
|
||||
throw Console.Error("Could not fetch client info.")
|
||||
}
|
||||
return deviceInfo
|
||||
}
|
||||
}
|
||||
|
||||
extension DeviceInfoProvider: DependencyKey {
|
||||
private static let current = Result { try DeviceInfo.fetch() }
|
||||
public static let liveValue = DeviceInfoProvider { try current.get() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user