Files
dudu/ios/dudu/Shared/PendingTextStore.swift
T
wangjia b5ab92a57e
ci / server (push) Failing after 13s
ci / design-tokens (push) Failing after 11s
fix: 应用 xhigh 代码评审的跨端修复
来自 xhigh code review 的正确性/健壮性修复,覆盖全部五端:
- server:鉴权 fail-closed、计量交叉校验与配额扣穿处理、WS 网关并发与关闭顺序、
  billing 行锁、redis Lua 过期与设备槽刷新、config 解析
- desktop:会话 epoch 防串话、WS 重连与 401 处理、api 客户端复用、统一 usePoll 轮询
- android:握手时序、请求头封装、账户状态派生、按需重组
- ios:finalize 宽限、串行采集、错误文案服务端优先、删除死代码 CommitController

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-13 11:50:08 +08:00

60 lines
2.8 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 14D deep link App Group UserDefaults
// App write(text) App dudu
// consume() insertText
// 21GApp Group pending_text write
// App Group App Group DictationController
//
// ""iOS " App" API
// extensionContext.open App
// return
// 120s
import Foundation
public enum PendingTextStore {
private enum Key {
static let text = "dictation.pending_text"
static let ts = "dictation.pending_ts" // Unix
}
///
public static let maxAgeSeconds: TimeInterval = 120
/// App Group suite
///
private static var appGroupDefaults: UserDefaults? {
UserDefaults(suiteName: AccountStore.appGroupID)
}
private static var defaults: UserDefaults {
appGroupDefaults ?? .standard
}
/// App
/// App Groupfalse App Group
/// 21G
@discardableResult
public static func write(_ text: String) -> Bool {
guard !text.isEmpty else { return false }
guard let group = appGroupDefaults else { return false } // App Group
group.set(text, forKey: Key.text)
group.set(Date().timeIntervalSince1970, forKey: Key.ts)
return true
}
///
/// " " / nil
public static func consume() -> (text: String, delaySeconds: TimeInterval)? {
guard let text = defaults.string(forKey: Key.text), !text.isEmpty else { return nil }
let ts = defaults.double(forKey: Key.ts)
clear()
let age = Date().timeIntervalSince1970 - ts
guard age >= 0, age < maxAgeSeconds else { return nil }
return (text, age)
}
public static func clear() {
defaults.removeObject(forKey: Key.text)
defaults.removeObject(forKey: Key.ts)
}
}