perf(efficiency): 落实首批采样减负与发行包瘦身
This commit is contained in:
@@ -10,6 +10,16 @@ import CoreFoundation
|
||||
@ObservationIgnored var onChange: (() -> Void)?
|
||||
private var panelValue: Int
|
||||
private var backgroundValue: Int
|
||||
private var backgroundEnabledValue: Bool
|
||||
var backgroundEnabled: Bool {
|
||||
get { backgroundEnabledValue }
|
||||
set {
|
||||
guard newValue != backgroundEnabledValue else { return }
|
||||
backgroundEnabledValue = newValue
|
||||
defaults.set(newValue, forKey: "sampling.backgroundEnabled")
|
||||
onChange?()
|
||||
}
|
||||
}
|
||||
var panelMilliseconds: Int {
|
||||
get { panelValue }
|
||||
set {
|
||||
@@ -34,7 +44,17 @@ import CoreFoundation
|
||||
init(defaults: UserDefaults = .standard) {
|
||||
self.defaults = defaults
|
||||
panelValue = Self.read(defaults, key: "sampling.panelMilliseconds", fallback: 2_000)
|
||||
backgroundValue = Self.read(defaults, key: "sampling.backgroundMilliseconds", fallback: 5_000)
|
||||
backgroundValue = Self.read(defaults, key: "sampling.backgroundMilliseconds", fallback: 30_000)
|
||||
// Retain an existing explicit background interval; new installs have no hidden consumer.
|
||||
if let number = defaults.object(forKey: "sampling.backgroundEnabled") as? NSNumber,
|
||||
CFGetTypeID(number) == CFBooleanGetTypeID() {
|
||||
backgroundEnabledValue = number.boolValue
|
||||
} else if let number = defaults.object(forKey: "sampling.backgroundMilliseconds") as? NSNumber,
|
||||
CFGetTypeID(number) != CFBooleanGetTypeID(), number.doubleValue.isFinite {
|
||||
backgroundEnabledValue = true
|
||||
} else {
|
||||
backgroundEnabledValue = false
|
||||
}
|
||||
}
|
||||
|
||||
static func normalized(_ value: Int) -> Int {
|
||||
|
||||
Reference in New Issue
Block a user