feat: add optional loop field to DeviceInfo
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user