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
feat(debug): trace clipboard shortcut event sources
altic-dev208566c257d7
diff --git a/Sources/Fluid/Services/ClipboardService.swift b/Sources/Fluid/Services/ClipboardService.swiftindex 5ab8185c..8dd3b992 100644--- a/Sources/Fluid/Services/ClipboardService.swift+++ b/Sources/Fluid/Services/ClipboardService.swift@@ -38,6 +38,23 @@ enum ClipboardService {/// Event-bound metadata only: no clipboard text, URLs, data payloads, or polling.enum ClipboardAudit {+ /// Physical ANSI C/X/V candidates only; do not collect ordinary typing.+ /// Raw key codes avoid doing keyboard-layout queries in the event tap.+ nonisolated static func shortcutMetadata(type: CGEventType, event: CGEvent) -> String? {+ guard type == .keyDown, event.flags.contains(.maskCommand) else { return nil }+ let keyCode = event.getIntegerValueField(.keyboardEventKeycode)+ guard [7, 8, 9].contains(keyCode) else { return nil }+ let sourcePID = event.getIntegerValueField(.eventSourceUnixProcessID)+ let targetPID = event.getIntegerValueField(.eventTargetUnixProcessID)+ let userData = event.getIntegerValueField(.eventSourceUserData)+ return "keyCode=\(keyCode) flags=\(event.flags.rawValue) sourcePID=\(sourcePID) targetPID=\(targetPID) userData=\(userData) eventTimestamp=\(event.timestamp)"+ }++ nonisolated static func recordShortcut(type: CGEventType, event: CGEvent) {+ guard let metadata = self.shortcutMetadata(type: type, event: event) else { return }+ DebugLogger.shared.benchmark("CLIPBOARD_INPUT", message: metadata, source: "ClipboardAudit")+ }+static func metadata(for pasteboard: NSPasteboard) -> String {let before = pasteboard.changeCountlet items = pasteboard.pasteboardItems ?? []diff --git a/Sources/Fluid/Services/GlobalHotkeyManager.swift b/Sources/Fluid/Services/GlobalHotkeyManager.swiftindex 1551000b..2da46da5 100644--- a/Sources/Fluid/Services/GlobalHotkeyManager.swift+++ b/Sources/Fluid/Services/GlobalHotkeyManager.swift@@ -694,6 +694,7 @@ final class GlobalHotkeyManager: NSObject {eventsOfInterest: Self.keyboardEventMask(),callback: { proxy, type, event, refcon -> Unmanaged<CGEvent>? inguard let refcon = refcon else { return Unmanaged.passUnretained(event) }+ ClipboardAudit.recordShortcut(type: type, event: event)if GlobalHotkeyManager.isSynthesizedTypingEvent(event) {return Unmanaged.passUnretained(event)}diff --git a/Tests/FluidDictationIntegrationTests/TypingServiceTransientPasteboardTests.swift b/Tests/FluidDictationIntegrationTests/TypingServiceTransientPasteboardTests.swiftindex 9d9cd2bc..182fae73 100644--- a/Tests/FluidDictationIntegrationTests/TypingServiceTransientPasteboardTests.swift+++ b/Tests/FluidDictationIntegrationTests/TypingServiceTransientPasteboardTests.swift@@ -99,6 +99,25 @@ final class TypingServiceTransientPasteboardTests: XCTestCase {XCTAssertEqual(pasteboard.string(forType: .string), secret)}+ func testClipboardShortcutAuditIgnoresOrdinaryTypingAndDoesNotMutateEvents() throws {+ let event = try XCTUnwrap(CGEvent(keyboardEventSource: nil, virtualKey: 8, keyDown: true))+ event.flags = []+ XCTAssertNil(ClipboardAudit.shortcutMetadata(type: .keyDown, event: event))+ event.flags = .maskCommand+ event.setIntegerValueField(.eventSourceUserData, value: 1234)+ let flags = event.flags+ let timestamp = event.timestamp+ let result = try XCTUnwrap(ClipboardAudit.shortcutMetadata(type: .keyDown, event: event))+ XCTAssertTrue(result.contains("keyCode=8"))+ XCTAssertTrue(result.contains("userData=1234"))+ XCTAssertEqual(event.flags, flags)+ XCTAssertEqual(event.timestamp, timestamp)+ XCTAssertEqual(event.getIntegerValueField(.eventSourceUserData), 1234)+ XCTAssertNil(ClipboardAudit.shortcutMetadata(type: .keyUp, event: event))+ event.setIntegerValueField(.keyboardEventKeycode, value: 0)+ XCTAssertNil(ClipboardAudit.shortcutMetadata(type: .keyDown, event: event))+ }+func testRecoveryActivationDoesNotRaiseAllWindowsOfTargetApp() {// Issue #748: recovery must NOT raise every window of the target app.let options = TypingService.recoveryActivationOptions