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
Add changes for prompt selection and insertion from notch
grohith32704776fe3f568
diff --git a/Sources/Fluid/ContentView.swift b/Sources/Fluid/ContentView.swiftindex bde206ae..32777b3f 100644--- a/Sources/Fluid/ContentView.swift+++ b/Sources/Fluid/ContentView.swift@@ -1535,7 +1535,13 @@ struct ContentView: View {)if shouldTypeExternally {- self.asr.typeTextToActiveField(finalText)+ Task { @MainActor in+ await self.restoreFocusToRecordingTarget()+ self.asr.typeTextToActiveField(+ finalText,+ preferredTargetPID: NotchContentState.shared.recordingTargetPID+ )+ }didTypeExternally = true}}@@ -1559,6 +1565,12 @@ struct ContentView: View {])}++ if didTypeExternally {+ Task { @MainActor in+ NotchOverlayManager.shared.hide()+ }+ }}// MARK: - Rewrite Mode Voice Processing@@ -1595,7 +1607,11 @@ struct ContentView: View {}// Type the rewritten text- self.asr.typeTextToActiveField(self.rewriteModeService.rewrittenText)+ await self.restoreFocusToRecordingTarget()+ self.asr.typeTextToActiveField(+ self.rewriteModeService.rewrittenText,+ preferredTargetPID: NotchContentState.shared.recordingTargetPID+ )AnalyticsService.shared.capture(.outputDelivered,properties: [@@ -1606,6 +1622,10 @@ struct ContentView: View {// Clear the rewrite service state for next useself.rewriteModeService.clearState()++ Task { @MainActor in+ NotchOverlayManager.shared.hide()+ }} else {DebugLogger.shared.error("Rewrite failed - no result", source: "ContentView")AnalyticsService.shared.capture(@@ -1643,6 +1663,12 @@ struct ContentView: View {self.menuBarManager.setOverlayMode(.dictation)}+ // Capture the focused target PID BEFORE any overlay/UI changes.+ // Used to restore focus when the user interacts with overlay dropdowns (e.g. prompt selection).+ let focusedPID = TypingService.captureSystemFocusedPID()+ ?? NSWorkspace.shared.frontmostApplication?.processIdentifier+ NotchContentState.shared.recordingTargetPID = focusedPID+let info = self.getCurrentAppInfo()self.recordingAppInfo = infoDebugLogger.shared.debug("Captured recording app context: app=\(info.name), bundleId=\(info.bundleId), title=\(info.windowTitle)", source: "ContentView")@@ -1659,6 +1685,17 @@ struct ContentView: View {}}+ /// Best-effort: re-activate the app that was focused when recording started.+ /// Adds a short delay after activation so macOS can deliver focus before typing begins.+ private func restoreFocusToRecordingTarget() async {+ guard let pid = NotchContentState.shared.recordingTargetPID else { return }+ let activated = TypingService.activateApp(pid: pid)+ if activated {+ // Small delay to allow window focus to settle before typing events fire.+ try? await Task.sleep(nanoseconds: 80_000_000) // 80ms+ }+ }+// MARK: - ASR Model Management/// Manual download trigger - downloads models when user clicks buttondiff --git a/Sources/Fluid/Services/ASRService.swift b/Sources/Fluid/Services/ASRService.swiftindex 91a2224e..fbc93529 100644--- a/Sources/Fluid/Services/ASRService.swift+++ b/Sources/Fluid/Services/ASRService.swift@@ -1826,6 +1826,10 @@ final class ASRService: ObservableObject {self.typingService.typeTextInstantly(text)}+ func typeTextToActiveField(_ text: String, preferredTargetPID: pid_t?) {+ self.typingService.typeTextInstantly(text, preferredTargetPID: preferredTargetPID)+ }+/// Removes filler sounds from transcribed textstatic func removeFillerWords(_ text: String) -> String {guard SettingsStore.shared.removeFillerWordsEnabled else { return text }diff --git a/Sources/Fluid/Services/TypingService.swift b/Sources/Fluid/Services/TypingService.swiftindex 491fb1c3..d836c2ff 100644--- a/Sources/Fluid/Services/TypingService.swift+++ b/Sources/Fluid/Services/TypingService.swift@@ -17,7 +17,58 @@ final class TypingService {private var isCurrentlyTyping = false+ // MARK: - Focus helpers (shared)++ /// Best-effort: returns the PID owning the currently focused accessibility element.+ /// This is more reliable than NSWorkspace.frontmostApplication for floating overlays/launchers.+ static func captureSystemFocusedPID() -> pid_t? {+ // Accessibility is required to query system-focused AX element.+ guard AXIsProcessTrusted() else { return nil }++ let systemWideElement = AXUIElementCreateSystemWide()+ var focusedElementRef: CFTypeRef?++ let result = AXUIElementCopyAttributeValue(+ systemWideElement,+ kAXFocusedUIElementAttribute as CFString,+ &focusedElementRef+ )+ guard result == .success, let focusedElementRef else { return nil }+ guard CFGetTypeID(focusedElementRef) == AXUIElementGetTypeID() else { return nil }++ let element = unsafeBitCast(focusedElementRef, to: AXUIElement.self)+ var pid: pid_t = 0+ AXUIElementGetPid(element, &pid)+ guard pid > 0 else { return nil }+ return pid+ }++ /// Best-effort: activates the app with the given PID, unless it's Fluid itself.+ @discardableResult+ static func activateApp(pid: pid_t) -> Bool {+ guard pid > 0 else { return false }+ guard let app = NSRunningApplication(processIdentifier: pid) else { return false }++ // Never try to re-activate ourselves; callers want focus to go back to the external app.+ if let selfBundleID = Bundle.main.bundleIdentifier,+ let targetBundleID = app.bundleIdentifier,+ selfBundleID == targetBundleID+ {+ return false+ }++ return app.activate(options: [.activateAllWindows, .activateIgnoringOtherApps])+ }++ // MARK: - Public API+func typeTextInstantly(_ text: String) {+ self.typeTextInstantly(text, preferredTargetPID: nil)+ }++ /// Types/inserts text, optionally preferring a specific target PID for CGEvent posting.+ /// This helps when our overlay temporarily has focus; we can still target the original app.+ func typeTextInstantly(_ text: String, preferredTargetPID: pid_t?) {self.log("[TypingService] ENTRY: typeTextInstantly called with text length: \(text.count)")self.log("[TypingService] Text preview: \"\(String(text.prefix(100)))\"")@@ -52,14 +103,25 @@ final class TypingService {// Longer delay to ensure target app is ready and focusedusleep(200_000) // 200ms delay - more reliable for app switchingself.log("[TypingService] Delay completed, calling insertTextInstantly")- self.insertTextInstantly(text)+ self.insertTextInstantly(text, preferredTargetPID: preferredTargetPID)}}- private func insertTextInstantly(_ text: String) {+ // MARK: - Internal insertion pipeline++ private func insertTextInstantly(_ text: String, preferredTargetPID: pid_t?) {self.log("[TypingService] insertTextInstantly called with \(text.count) characters")self.log("[TypingService] Attempting to type text: \"\(text.prefix(50))\(text.count > 50 ? "..." : "")\"")+ // Preferred: target a specific PID when provided (e.g., the app that was focused when recording started).+ if let preferredTargetPID, preferredTargetPID > 0 {+ self.log("[TypingService] Trying CGEvent insertion targeting preferred PID \(preferredTargetPID)")+ if self.insertTextBulkInstant(text, targetPID: preferredTargetPID) {+ self.log("[TypingService] SUCCESS: CGEvent preferred-PID insertion completed")+ return+ }+ }+// Get frontmost app infoif let frontApp = NSWorkspace.shared.frontmostApplication {self.log("[TypingService] Target app: \(frontApp.localizedName ?? "Unknown") (\(frontApp.bundleIdentifier ?? "Unknown"))")diff --git a/Sources/Fluid/Views/BottomOverlayView.swift b/Sources/Fluid/Views/BottomOverlayView.swiftindex 5539e522..c35cc7cf 100644--- a/Sources/Fluid/Views/BottomOverlayView.swift+++ b/Sources/Fluid/Views/BottomOverlayView.swift@@ -323,12 +323,20 @@ struct BottomOverlayView: View {Menu {Button("Default") {self.settings.selectedDictationPromptID = nil+ let pid = NotchContentState.shared.recordingTargetPID+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {+ if let pid { _ = TypingService.activateApp(pid: pid) }+ }}if !self.settings.dictationPromptProfiles.isEmpty {Divider()ForEach(self.settings.dictationPromptProfiles) { profile inButton(profile.name.isEmpty ? "Untitled" : profile.name) {self.settings.selectedDictationPromptID = profile.id+ let pid = NotchContentState.shared.recordingTargetPID+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {+ if let pid { _ = TypingService.activateApp(pid: pid) }+ }}}}diff --git a/Sources/Fluid/Views/NotchContentViews.swift b/Sources/Fluid/Views/NotchContentViews.swiftindex 6e7f5ddd..a9e950e4 100644--- a/Sources/Fluid/Views/NotchContentViews.swift+++ b/Sources/Fluid/Views/NotchContentViews.swift@@ -21,6 +21,10 @@ class NotchContentState: ObservableObject {// Icon of the target app (where text will be typed)@Published var targetAppIcon: NSImage?+ /// The PID of the app we should restore focus to after interacting with overlays.+ /// Captured at recording start to keep the target stable for the session.+ @Published var recordingTargetPID: pid_t? = nil+// Cached transcription lines to avoid recomputing on every render@Published private(set) var cachedLine1: String = ""@Published private(set) var cachedLine2: String = ""@@ -309,12 +313,20 @@ struct NotchExpandedView: View {Menu {Button("Default") {self.settings.selectedDictationPromptID = nil+ let pid = NotchContentState.shared.recordingTargetPID+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {+ if let pid { _ = TypingService.activateApp(pid: pid) }+ }}if !self.settings.dictationPromptProfiles.isEmpty {Divider()ForEach(self.settings.dictationPromptProfiles) { profile inButton(profile.name.isEmpty ? "Untitled" : profile.name) {self.settings.selectedDictationPromptID = profile.id+ let pid = NotchContentState.shared.recordingTargetPID+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {+ if let pid { _ = TypingService.activateApp(pid: pid) }+ }}}}