feat(settings): 默认启用短动效并提供独立减弱动画选项
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import Foundation
|
||||
import Observation
|
||||
import CoreFoundation
|
||||
|
||||
nonisolated enum AppAppearance: String, CaseIterable, Identifiable {
|
||||
case system, light, dark
|
||||
@@ -11,8 +12,26 @@ final class AppearancePreferences {
|
||||
@ObservationIgnored private let defaults: UserDefaults
|
||||
var appearance: AppAppearance { didSet { defaults.set(appearance.rawValue, forKey: "appearance") } }
|
||||
|
||||
var reduceMotion: Bool {
|
||||
didSet { if reduceMotion != oldValue { defaults.set(reduceMotion, forKey: "appearance.reduceMotion") } }
|
||||
}
|
||||
|
||||
init(defaults: UserDefaults = .standard) {
|
||||
self.defaults = defaults
|
||||
let value = defaults.object(forKey: "appearance.reduceMotion") as? NSNumber
|
||||
if defaults.volatileDomain(forName: UserDefaults.argumentDomain)["appearance.reduceMotion"] != nil {
|
||||
// Foundation represents launch overrides as strings; do not persist them.
|
||||
reduceMotion = defaults.bool(forKey: "appearance.reduceMotion")
|
||||
} else {
|
||||
reduceMotion = value.map { CFGetTypeID($0) == CFBooleanGetTypeID() && $0.boolValue } ?? false
|
||||
}
|
||||
appearance = AppAppearance(rawValue: defaults.string(forKey: "appearance") ?? "") ?? .system
|
||||
}
|
||||
}
|
||||
|
||||
/// Motion changes presentation only; sampling preferences are deliberately absent.
|
||||
nonisolated enum MetricMotionPolicy {
|
||||
static func enabled(reduced: Bool, systemReduced: Bool, visible: Bool, paused: Bool, sleeping: Bool) -> Bool {
|
||||
!reduced && !systemReduced && visible && !paused && !sleeping
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user