@@ -216,24 +216,8 @@ public final class XcodeInspector: ObservableObject {
216216 for await notification in sequence {
217217 guard let self else { return }
218218 let toast = self . toast
219- if UserDefaults . shared
220- . value ( for: \. toastForTheReasonWhyXcodeInspectorNeedsToBeRestarted)
221- {
222- toast. toast (
223- content: """
224- Accessibility API malfunction detected: \
225- \( notification. object as? String ?? " " ) .
226- Resetting active Xcode.
227- """ ,
228- type: . warning
229- )
230- }
231- if let activeXcode {
232- await MainActor . run {
233- self . setActiveXcode ( activeXcode)
234- activeXcode. observeAXNotifications ( )
235- }
236- }
219+ await self
220+ . recoverFromAccessibilityMalfunctioning ( notification. object as? String )
237221 }
238222 }
239223 }
@@ -335,9 +319,14 @@ public final class XcodeInspector: ObservableObject {
335319 self ? . focusedWindow = window
336320 } . store ( in: & activeXcodeCancellable)
337321 }
322+
323+ private var lastRecoveryFromAccessibilityMalfunctioningTimeStamp = Date ( )
338324
339325 @MainActor
340326 private func checkForAccessibilityMalfunction( _ source: String ) {
327+ guard Date ( ) . timeIntervalSince ( lastRecoveryFromAccessibilityMalfunctioningTimeStamp) > 5
328+ else { return }
329+
341330 Logger . service. debug ( """
342331 Check for Accessibility Malfunctioning:
343332 Source Editor: \( {
@@ -387,5 +376,24 @@ public final class XcodeInspector: ObservableObject {
387376 }
388377 }
389378 }
379+
380+ @MainActor
381+ private func recoverFromAccessibilityMalfunctioning( _ source: String ? ) {
382+ if UserDefaults . shared. value ( for: \. toastForTheReasonWhyXcodeInspectorNeedsToBeRestarted) {
383+ toast. toast (
384+ content: """
385+ Accessibility API malfunction detected: \
386+ \( source ?? " " ) .
387+ Resetting active Xcode.
388+ """ ,
389+ type: . warning
390+ )
391+ }
392+ if let activeXcode {
393+ lastRecoveryFromAccessibilityMalfunctioningTimeStamp = Date ( )
394+ setActiveXcode ( activeXcode)
395+ activeXcode. observeAXNotifications ( )
396+ }
397+ }
390398}
391399
0 commit comments