46 lines
2.1 KiB
Swift
46 lines
2.1 KiB
Swift
import Foundation
|
|
|
|
/// User-facing app preferences that aren't host/franchise specific. Persisted to
|
|
/// `~/.local/state/tv-anarchy/settings.json`. Kept deliberately small — one file,
|
|
/// tolerant decode, sensible defaults — so adding a preference is one field here
|
|
/// plus its wiring, no migration.
|
|
public struct AppSettings: Codable, Sendable, Equatable {
|
|
/// When false (the default), the Home screen hides everything from the `porn`
|
|
/// media dir — its category rails, plus any adult item in Continue Watching or
|
|
/// Recently Added. Independent of the Library tab's own porn browse toggle, so
|
|
/// you can deliberately browse adult content in Library without it leaking onto
|
|
/// the landing screen.
|
|
public var surfaceAdultOnHome: Bool
|
|
/// When true, hovering a poster plays a short muted preview clip (built on
|
|
/// black, seeked past the intro, cached). Off by default — it triggers ffmpeg
|
|
/// work on black, so it's opt-in.
|
|
public var hoverPreviews: Bool
|
|
|
|
public init(surfaceAdultOnHome: Bool = false, hoverPreviews: Bool = false) {
|
|
self.surfaceAdultOnHome = surfaceAdultOnHome
|
|
self.hoverPreviews = hoverPreviews
|
|
}
|
|
|
|
public init(from decoder: Decoder) throws {
|
|
let c = try decoder.container(keyedBy: CodingKeys.self)
|
|
surfaceAdultOnHome = try c.decodeIfPresent(Bool.self, forKey: .surfaceAdultOnHome) ?? false
|
|
hoverPreviews = try c.decodeIfPresent(Bool.self, forKey: .hoverPreviews) ?? false
|
|
}
|
|
}
|
|
|
|
public enum SettingsStore {
|
|
private static var url: URL { StatePaths.url("settings.json") }
|
|
|
|
public static func load() -> AppSettings {
|
|
guard let d = try? Data(contentsOf: url),
|
|
let s = try? JSONDecoder().decode(AppSettings.self, from: d) else { return AppSettings() }
|
|
return s
|
|
}
|
|
|
|
public static func save(_ s: AppSettings) {
|
|
guard let d = try? JSONEncoder().encode(s) else { return }
|
|
try? FileManager.default.createDirectory(at: url.deletingLastPathComponent(),
|
|
withIntermediateDirectories: true)
|
|
try? d.write(to: url, options: .atomic)
|
|
}
|
|
}
|