feat: group playback settings under a TOML section
This commit is contained in:
@@ -20,6 +20,7 @@ public struct PlayerConfiguration: Equatable, Sendable {
|
||||
let encoder = JSONEncoder()
|
||||
encoder.outputFormatting = .withoutEscapingSlashes
|
||||
var lines = [
|
||||
"[playback]",
|
||||
"automatic_quality = \(defaults.automaticQuality)",
|
||||
"", "[ui]",
|
||||
"buffer_info = \(defaults.showBufferInfo)",
|
||||
@@ -74,7 +75,7 @@ public struct PlayerConfiguration: Equatable, Sendable {
|
||||
do {
|
||||
let values = try TOMLDecoder(isLenient: false).decode(FileConfiguration.self, from: data)
|
||||
return Self(showBufferInfo: values.ui?.bufferInfo ?? false,
|
||||
automaticQuality: values.automaticQuality ?? false,
|
||||
automaticQuality: values.playback?.automaticQuality ?? false,
|
||||
snapToEdges: values.ui?.compactSnapToEdges ?? true,
|
||||
keys: try KeyBindings(overrides: values.keys?.overrides ?? [:]))
|
||||
} catch {
|
||||
@@ -131,14 +132,16 @@ public struct PlayerConfiguration: Equatable, Sendable {
|
||||
}
|
||||
|
||||
private struct FileConfiguration: Decodable {
|
||||
let automaticQuality: Bool?
|
||||
let playback: PlaybackConfiguration?
|
||||
let ui: UIConfiguration?
|
||||
let keys: KeysConfiguration?
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: SettingKey.self)
|
||||
try validate(container, allowed: ["automatic_quality", "ui", "keys"])
|
||||
automaticQuality = try container.decodeIfPresent(Bool.self, forKey: SettingKey("automatic_quality"))
|
||||
try validate(container, allowed: ["playback", "ui", "keys"])
|
||||
if container.contains(SettingKey("playback")) {
|
||||
playback = try PlaybackConfiguration(container: container.nestedContainer(keyedBy: SettingKey.self, forKey: SettingKey("playback")))
|
||||
} else { playback = nil }
|
||||
if container.contains(SettingKey("ui")) {
|
||||
ui = try UIConfiguration(container: container.nestedContainer(keyedBy: SettingKey.self, forKey: SettingKey("ui")))
|
||||
} else { ui = nil }
|
||||
@@ -148,6 +151,15 @@ public struct PlayerConfiguration: Equatable, Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
private struct PlaybackConfiguration {
|
||||
let automaticQuality: Bool?
|
||||
|
||||
init(container: KeyedDecodingContainer<SettingKey>) throws {
|
||||
try validate(container, allowed: ["automatic_quality"])
|
||||
automaticQuality = try container.decodeIfPresent(Bool.self, forKey: SettingKey("automatic_quality"))
|
||||
}
|
||||
}
|
||||
|
||||
private struct UIConfiguration {
|
||||
let bufferInfo: Bool?
|
||||
let compactSnapToEdges: Bool?
|
||||
|
||||
Reference in New Issue
Block a user