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 countdownEndTimeKey = "FAPayRetainCountdownEndTime"
private var countdownTimer: Timer?
private var remainingSeconds: Int = 0
@ -252,8 +253,12 @@ extension FAPayRetainAlert {
// 4
private func startCountdown() {
stopCountdown()
remainingSeconds = Self.defaultCountdownSeconds
let endTime = resolveEndTime()
remainingSeconds = max(0, Int(endTime - Date().timeIntervalSince1970))
updateTimeLabels()
guard remainingSeconds > 0 else {
return
}
countdownTimer = Timer.scheduledTimer(timeInterval: 1,
target: YYTextWeakProxy(target: self),
selector: #selector(handleCountdownTimer),
@ -276,6 +281,18 @@ extension FAPayRetainAlert {
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() {
let hours = remainingSeconds / 3600
let minutes = (remainingSeconds % 3600) / 60