Skip to content

Commit 0c9c6ce

Browse files
fix(helper): retry AX trust check on backoff (100ms/400ms/1000ms)
A single 100ms re-check after a false AXIsProcessTrusted() didn't fully cover the TCC startup race — extend to a three-step backoff (100ms, +400ms, +1000ms; ~1.5s worst case). Each step short-circuits on first true. Vendor rebuilt: cdhash 27cb11725a76e8c880f4d412b242ecf31b57cb8a. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1a7982d commit 0c9c6ce

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

KeyStatsHelper/HelperXPCListener.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,29 @@ final class HelperXPCListener: NSObject, NSXPCListenerDelegate, KeyStatsHelperPr
118118
}
119119
// AXIsProcessTrusted() 在 helper 进程刚被 launchd spawn 出来时
120120
// 偶尔会先返回 false(TCC 还没把当前 PID 跟 helper 的 cdhash 关联好)。
121-
// 100ms 后重查一次,避免误报"未授权"导致主 app 弹错误提示。
122-
DispatchQueue.global().asyncAfter(deadline: .now() + 0.1) { [tap] in
123-
reply(HelperLocations.interfaceVersion, tap.isAccessibilityGranted())
121+
// 100ms / 400ms / 1000ms 后逐级重查,最多 ~1.5s 内若有任何一次返回
122+
// true 就立刻返回,否则才报"未授权"。
123+
Self.recheckAccessibility(tap: tap, delays: [0.1, 0.4, 1.0]) { granted in
124+
reply(HelperLocations.interfaceVersion, granted)
125+
}
126+
}
127+
128+
private static func recheckAccessibility(
129+
tap: EventTapController,
130+
delays: [TimeInterval],
131+
completion: @escaping (Bool) -> Void
132+
) {
133+
guard let next = delays.first else {
134+
completion(false)
135+
return
136+
}
137+
let rest = Array(delays.dropFirst())
138+
DispatchQueue.global().asyncAfter(deadline: .now() + next) {
139+
if tap.isAccessibilityGranted() {
140+
completion(true)
141+
} else {
142+
recheckAccessibility(tap: tap, delays: rest, completion: completion)
143+
}
124144
}
125145
}
126146

18.5 KB
Binary file not shown.

vendor/KeyStatsHelper.cdhash.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
227ddaa86249986061dd83c7ebf9efc86a70c44b
1+
27cb11725a76e8c880f4d412b242ecf31b57cb8a

0 commit comments

Comments
 (0)