From 76cbf1a10272c47edb03542f6bd13bfa2ab760e4 Mon Sep 17 00:00:00 2001 From: PJ Date: Sun, 7 Jun 2026 15:50:46 +0530 Subject: [PATCH] fix(companion): synthesize gestures synchronously to avoid the async completion crash --- companion/Sources/Gesture.swift | 16 ++++------------ .../PrivateAutomation/PrivateAutomation.h | 3 +++ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/companion/Sources/Gesture.swift b/companion/Sources/Gesture.swift index 4357972..b4bb273 100644 --- a/companion/Sources/Gesture.swift +++ b/companion/Sources/Gesture.swift @@ -73,17 +73,9 @@ enum Gesture { let record = XCSynthesizedEventRecord(name: "companion", interfaceOrientation: 0) record.add(path) - let semaphore = DispatchSemaphore(value: 0) - var synthesisError: Error? - XCTRunnerDaemonSession.shared().synthesize(event: record) { error in - synthesisError = error - semaphore.signal() - } - if semaphore.wait(timeout: .now() + 30) == .timedOut { - throw GestureError.synthesisTimeout - } - if let synthesisError = synthesisError { - throw GestureError.synthesisFailed("\(synthesisError)") - } + // Synchronous delivery: returns whether the event was synthesized and + // populates the error out-pointer on failure. This avoids the async + // completion-block path. + try record.synthesize() } } diff --git a/companion/Sources/PrivateAutomation/PrivateAutomation.h b/companion/Sources/PrivateAutomation/PrivateAutomation.h index a86adbd..15be416 100644 --- a/companion/Sources/PrivateAutomation/PrivateAutomation.h +++ b/companion/Sources/PrivateAutomation/PrivateAutomation.h @@ -18,10 +18,13 @@ NS_ASSUME_NONNULL_BEGIN @end // A complete synthesized event composed of one or more pointer paths. +// synthesizeWithError: delivers the event synchronously and returns whether it +// succeeded, which avoids the asynchronous completion-block path. @interface XCSynthesizedEventRecord : NSObject - (instancetype)initWithName:(NSString *)name interfaceOrientation:(NSInteger)interfaceOrientation; - (void)addPointerEventPath:(XCPointerEventPath *)pointerEventPath; +- (BOOL)synthesizeWithError:(NSError *_Nullable *_Nullable)error; @end // The runner-side session that delivers synthesized events to the system under