Skip to content

Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more

Serialize temporary clipboard sessions

altic-dev3f6a6e71de34
diff --git a/Sources/Fluid/Services/TypingService.swift b/Sources/Fluid/Services/TypingService.swift
index d8cb4705..b0976577 100644
--- a/Sources/Fluid/Services/TypingService.swift
+++ b/Sources/Fluid/Services/TypingService.swift
@@ -51,6 +51,7 @@ final class TypingService {
}
private static let focusSnapshotQueue = DispatchQueue(label: "TypingService.FocusSnapshot")
+ private static let pasteboardSessionSemaphore = DispatchSemaphore(value: 1)
private static let pasteboardRestoreQueue = DispatchQueue(label: "TypingService.PasteboardRestore", qos: .utility)
private static var focusSnapshot: FocusSnapshot?
@@ -522,6 +523,14 @@ final class TypingService {
restoreDelayMicros: useconds_t,
action: () -> Bool
) -> Bool {
+ Self.pasteboardSessionSemaphore.wait()
+ var releasesPasteboardSessionOnReturn = true
+ defer {
+ if releasesPasteboardSessionOnReturn {
+ Self.pasteboardSessionSemaphore.signal()
+ }
+ }
+
let pasteboard = NSPasteboard.general
let snapshot = self.capturePasteboardSnapshot(pasteboard)
@@ -540,7 +549,9 @@ final class TypingService {
return false
}
+ releasesPasteboardSessionOnReturn = false
Self.pasteboardRestoreQueue.async {
+ defer { Self.pasteboardSessionSemaphore.signal() }
_ = self.waitForFocusedTextVerification(
from: focusedTextSnapshot,
expectedText: text,