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

Stop reliable paste after successful paste dispatch

altic-deva5ed5472a2a9
diff --git a/Sources/Fluid/Services/TypingService.swift b/Sources/Fluid/Services/TypingService.swift
index 41d0300f..153ae3cb 100644
--- a/Sources/Fluid/Services/TypingService.swift
+++ b/Sources/Fluid/Services/TypingService.swift
@@ -31,12 +31,6 @@ final class TypingService {
let items: [PasteboardItemSnapshot]
}
- private struct FocusedTextSnapshot {
- let pid: pid_t
- let value: String?
- let selectedRange: CFRange?
- }
-
private static let focusSnapshotQueue = DispatchQueue(label: "TypingService.FocusSnapshot")
private static var focusSnapshot: FocusSnapshot?
@@ -299,33 +293,21 @@ final class TypingService {
private func tryReliablePasteInsertion(_ text: String, preferredTargetPID: pid_t?) -> Bool {
self.log("[TypingService] Trying global clipboard insertion")
- if self.performVerifiedPasteAttempt(
- methodName: "Global clipboard",
- action: { self.insertTextViaClipboard(text) }
- ) {
+ if self.insertTextViaClipboard(text) {
+ self.log("[TypingService] Reliable Paste dispatched via global clipboard paste")
return true
}
self.log("[TypingService] Global clipboard insertion failed, trying menu paste")
- if self.performVerifiedPasteAttempt(
- methodName: "Menu paste",
- action: { self.insertTextViaMenuPaste(text) }
- ) {
+ if self.insertTextViaMenuPaste(text) {
+ self.log("[TypingService] Reliable Paste dispatched via menu paste")
return true
}
if let preferredTargetPID, preferredTargetPID > 0 {
self.log("[TypingService] Menu paste failed, trying clipboard-to-PID fallback")
- if NSWorkspace.shared.frontmostApplication?.processIdentifier != preferredTargetPID {
- _ = Self.activateApp(pid: preferredTargetPID)
- usleep(80_000)
- }
-
- if self.performVerifiedPasteAttempt(
- methodName: "Clipboard-to-PID",
- expectedPID: preferredTargetPID,
- action: { self.insertTextViaClipboardToPid(text, targetPID: preferredTargetPID, activateTargetFirst: false) }
- ) {
+ if self.insertTextViaClipboardToPid(text, targetPID: preferredTargetPID) {
+ self.log("[TypingService] Reliable Paste dispatched via clipboard-to-PID")
return true
}
}
@@ -816,67 +798,6 @@ final class TypingService {
return ok ? range : nil
}
- private func captureFocusedTextSnapshot() -> FocusedTextSnapshot? {
- guard let focusInfo = self.getSystemFocusedElementAndPID() else { return nil }
- return FocusedTextSnapshot(
- pid: focusInfo.pid,
- value: self.getElementStringValue(focusInfo.element),
- selectedRange: self.getSelectedTextRange(focusInfo.element)
- )
- }
-
- private func focusedTextChanged(from snapshot: FocusedTextSnapshot, expectedPID: pid_t) -> Bool {
- for _ in 0..<4 {
- usleep(40_000)
-
- guard let current = self.captureFocusedTextSnapshot(),
- current.pid == expectedPID
- else {
- continue
- }
-
- if current.value != snapshot.value {
- return true
- }
-
- if let before = snapshot.selectedRange,
- let after = current.selectedRange,
- before.location != after.location || before.length != after.length
- {
- return true
- }
- }
-
- return false
- }
-
- private func performVerifiedPasteAttempt(
- methodName: String,
- expectedPID: pid_t? = nil,
- action: () -> Bool
- ) -> Bool {
- let snapshot = self.captureFocusedTextSnapshot()
-
- guard action() else {
- self.log("[TypingService] \(methodName) paste dispatch failed")
- return false
- }
-
- guard let snapshot else {
- self.log("[TypingService] \(methodName) paste dispatched but could not be verified; continuing fallbacks")
- return false
- }
-
- let expectedPID = expectedPID ?? snapshot.pid
- if self.focusedTextChanged(from: snapshot, expectedPID: expectedPID) {
- self.log("[TypingService] SUCCESS: \(methodName) insertion verified")
- return true
- }
-
- self.log("[TypingService] \(methodName) paste dispatched but no text change was observed; continuing fallbacks")
- return false
- }
-
private func insertTextAtCursorUsingSelectedRange(_ element: AXUIElement, _ text: String) -> Bool {
guard let currentValue = self.getElementStringValue(element) else {
self.log("[TypingService] Cursor insert failed: could not read kAXValueAttribute")