feat: add optional loop field to DeviceInfo

This commit is contained in:
km2023
2026-05-06 10:34:34 +08:00
parent be851b05ec
commit 4b1017df42
2 changed files with 40 additions and 1 deletions

View File

@@ -7,11 +7,13 @@ public struct DeviceInfo: Equatable {
public let size: String
public let brand: String
public let powerlevel: Int
/// nil
public let loop: PlayMode?
}
extension DeviceInfo: Codable {
enum CodingKeys: String, CodingKey {
case allspace, freespace, name, size, brand, powerlevel
case allspace, freespace, name, size, brand, powerlevel, loop
}
public init(from decoder: Decoder) throws {
@@ -35,6 +37,13 @@ extension DeviceInfo: Codable {
// allspace/freespace: may come as number, string, or be missing
allspace = Self.decodeFlexibleUInt64(container: container, key: .allspace)
freespace = Self.decodeFlexibleUInt64(container: container, key: .freespace)
// loop: optional. Accept Int 0/1; anything else nil.
if let raw = try? container.decode(Int.self, forKey: .loop), let mode = PlayMode(rawValue: raw) {
loop = mode
} else {
loop = nil
}
}
private static func decodeFlexibleUInt64(