fix(companion): synthesize gestures synchronously to avoid the async completion crash

This commit is contained in:
pj committed 2026-06-07 15:50:46 +05:30
1 parent c3e0de547e
commit 76cbf1a102
2 files changed
+7 -12

No files matched your search

+4 -12
View File
@@ -73,17 +73,9 @@ enum Gesture {
let record = XCSynthesizedEventRecord(name: "companion", interfaceOrientation: 0) let record = XCSynthesizedEventRecord(name: "companion", interfaceOrientation: 0)
record.add(path) record.add(path)
let semaphore = DispatchSemaphore(value: 0) // Synchronous delivery: returns whether the event was synthesized and
var synthesisError: Error? // populates the error out-pointer on failure. This avoids the async
XCTRunnerDaemonSession.shared().synthesize(event: record) { error in // completion-block path.
synthesisError = error try record.synthesize()
semaphore.signal()
}
if semaphore.wait(timeout: .now() + 30) == .timedOut {
throw GestureError.synthesisTimeout
}
if let synthesisError = synthesisError {
throw GestureError.synthesisFailed("\(synthesisError)")
}
} }
} }
@@ -18,10 +18,13 @@ NS_ASSUME_NONNULL_BEGIN
@end @end
// A complete synthesized event composed of one or more pointer paths. // 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 @interface XCSynthesizedEventRecord : NSObject
- (instancetype)initWithName:(NSString *)name - (instancetype)initWithName:(NSString *)name
interfaceOrientation:(NSInteger)interfaceOrientation; interfaceOrientation:(NSInteger)interfaceOrientation;
- (void)addPointerEventPath:(XCPointerEventPath *)pointerEventPath; - (void)addPointerEventPath:(XCPointerEventPath *)pointerEventPath;
- (BOOL)synthesizeWithError:(NSError *_Nullable *_Nullable)error;
@end @end
// The runner-side session that delivers synthesized events to the system under // The runner-side session that delivers synthesized events to the system under