mirror of
https://github.com/samsonjs/Peekaboo.git
synced 2026-04-27 15:07:41 +00:00
- Replace problematic DispatchSemaphore usage with NSCondition-based async bridge - Revert to ParsableCommand for compatibility while maintaining async operations - Use CGWindowListCopyWindowInfo for sync permission checking instead of async ScreenCaptureKit - Remove all RunLoop workarounds in favor of proper Task.runBlocking pattern - Eliminate all deadlock sources while preserving async capture functionality
33 lines
No EOL
1,009 B
Swift
33 lines
No EOL
1,009 B
Swift
import Foundation
|
|
|
|
extension Task where Success == Void, Failure == Never {
|
|
/// Runs an async operation synchronously by blocking the current thread.
|
|
/// This is a safer alternative to using DispatchSemaphore with Swift concurrency.
|
|
static func runBlocking<T>(operation: @escaping () async throws -> T) throws -> T {
|
|
var result: Result<T, Error>?
|
|
let condition = NSCondition()
|
|
|
|
Task {
|
|
do {
|
|
let value = try await operation()
|
|
condition.lock()
|
|
result = .success(value)
|
|
condition.signal()
|
|
condition.unlock()
|
|
} catch {
|
|
condition.lock()
|
|
result = .failure(error)
|
|
condition.signal()
|
|
condition.unlock()
|
|
}
|
|
}
|
|
|
|
condition.lock()
|
|
while result == nil {
|
|
condition.wait()
|
|
}
|
|
condition.unlock()
|
|
|
|
return try result!.get()
|
|
}
|
|
} |