Cleanup the Save As destination feature a bit

This commit is contained in:
Damiano Galassi committed 2026-09-23 21:29:18 +02:00
1 parent c8fb950854
commit ce011a4d37
5 files changed
+85 -73

No files matched your search

+35 -24
View File
@@ -26,11 +26,6 @@ struct Stored<T> : Registable {
let key: String
let defaultValue: T
init(key: String, defaultValue: T) {
self.key = key
self.defaultValue = defaultValue
}
var wrappedValue: T {
get { ud.object(forKey: key) as? T ?? defaultValue }
set { ud.set(newValue, forKey: key) }
@@ -41,16 +36,41 @@ struct Stored<T> : Registable {
}
}
@propertyWrapper
struct StoredEnum<T: RawRepresentable> : Registable {
let key: String
let defaultValue: T
var wrappedValue: T {
get { T(rawValue: (ud.object(forKey: key) as? T.RawValue) ?? defaultValue.rawValue) ?? defaultValue }
set { ud.set(newValue.rawValue, forKey: key) }
}
func register(in dictionary: inout [String :Any]) {
dictionary[key] = defaultValue.rawValue
}
}
@propertyWrapper
struct StoredURL : Registable {
let key: String
let defaultValue: URL?
var wrappedValue: URL? {
get { ud.url(forKey: key) ?? defaultValue }
set { ud.set(newValue, forKey: key) }
}
func register(in dictionary: inout [String :Any]) {
dictionary[key] = defaultValue
}
}
@propertyWrapper
struct StoredCodable<T: Codable> : Registable {
let key: String
let defaultValue: T
init(key: String, defaultValue: T) {
self.key = key
self.defaultValue = defaultValue
}
var wrappedValue: T {
get {
guard let data = ud.data(forKey: key) else { return defaultValue }
@@ -88,7 +108,7 @@ enum Prefs {
_audioBitrate, _audioDRC, _audioConvertAC3, _audioKeepAC3, _audioConvertDts,
_audioDtsOptions, _subtitleConvertBitmap, _ratingsCountry, _chaptersPreviewPosition,
_chaptersPreviewTrack, _mp464bitOffset, _mp464bitTimes, _mp4SaveAsOptimize, _forceHvc1,
_logFormat, _saveAsLocationValue])
_logFormat, _saveAsLocation])
}
@Stored(key: "NSApplicationCrashOnException", defaultValue: true)
@@ -172,21 +192,12 @@ enum Prefs {
@Stored(key: "SBLogFormat", defaultValue: 0)
static var logFormat: Int // 0 = Time Only, 1 = Date and Time
@Stored(key: "SBSaveAsLocationMode", defaultValue: 0)
private static var saveAsLocationValue: Int
static var saveAsLocation: SaveAsLocation {
get { SaveAsLocation(rawValue: saveAsLocationValue) ?? .lastUsed }
set { saveAsLocationValue = newValue.rawValue }
}
private static let saveAsCustomLocationKey = "SBSaveAsCustomLocation"
@StoredEnum(key: "SBSaveAsLocationMode", defaultValue: .lastUsed)
static var saveAsLocation: SaveAsLocation
/// The folder used when saveAsLocation is set to custom.
static var saveAsCustomLocation: URL? {
get { ud.url(forKey: saveAsCustomLocationKey) }
set { ud.set(newValue, forKey: saveAsCustomLocationKey) }
}
@StoredURL(key: "SBSaveAsCustomLocation", defaultValue: nil)
static var saveAsCustomLocation: URL?
}
enum MetadataPrefs {