This commit is contained in:
zeng 2026-01-13 17:46:21 +08:00
parent f903e4cfae
commit d8fd08c58c

View File

@ -166,6 +166,7 @@ extension FAPayRetainAlert {
} }
private static let defaultCountdownSeconds = 4 * 60 * 60 private static let defaultCountdownSeconds = 4 * 60 * 60
private static let countdownEndTimeKey = "FAPayRetainCountdownEndTime"
private var countdownTimer: Timer? private var countdownTimer: Timer?
private var remainingSeconds: Int = 0 private var remainingSeconds: Int = 0
@ -252,8 +253,12 @@ extension FAPayRetainAlert {
// 4 // 4
private func startCountdown() { private func startCountdown() {
stopCountdown() stopCountdown()
remainingSeconds = Self.defaultCountdownSeconds let endTime = resolveEndTime()
remainingSeconds = max(0, Int(endTime - Date().timeIntervalSince1970))
updateTimeLabels() updateTimeLabels()
guard remainingSeconds > 0 else {
return
}
countdownTimer = Timer.scheduledTimer(timeInterval: 1, countdownTimer = Timer.scheduledTimer(timeInterval: 1,
target: YYTextWeakProxy(target: self), target: YYTextWeakProxy(target: self),
selector: #selector(handleCountdownTimer), selector: #selector(handleCountdownTimer),
@ -276,6 +281,18 @@ extension FAPayRetainAlert {
updateTimeLabels() updateTimeLabels()
} }
private func resolveEndTime() -> TimeInterval {
let defaults = UserDefaults.standard
let now = Date().timeIntervalSince1970
let storedEndTime = defaults.double(forKey: Self.countdownEndTimeKey)
if storedEndTime > now {
return storedEndTime
}
let newEndTime = now + TimeInterval(Self.defaultCountdownSeconds)
defaults.set(newEndTime, forKey: Self.countdownEndTimeKey)
return newEndTime
}
private func updateTimeLabels() { private func updateTimeLabels() {
let hours = remainingSeconds / 3600 let hours = remainingSeconds / 3600
let minutes = (remainingSeconds % 3600) / 60 let minutes = (remainingSeconds % 3600) / 60