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

Prefer focused target when dictation stops

altic-deve664395a9ef8
diff --git a/Sources/Fluid/ContentView.swift b/Sources/Fluid/ContentView.swift
index 7439e26c..ce60630c 100644
--- a/Sources/Fluid/ContentView.swift
+++ b/Sources/Fluid/ContentView.swift
@@ -1233,6 +1233,22 @@ struct ContentView: View {
)
}
+ private func resolveTypingTargetPID() -> (pid: pid_t?, shouldRestoreOriginalFocus: Bool) {
+ let originalPID = NotchContentState.shared.recordingTargetPID
+ let currentFocusedPID = TypingService.captureSystemFocusedPID()
+ ?? NSWorkspace.shared.frontmostApplication?.processIdentifier
+
+ let selfBundleID = Bundle.main.bundleIdentifier
+ if let currentFocusedPID,
+ let app = NSRunningApplication(processIdentifier: currentFocusedPID),
+ app.bundleIdentifier != selfBundleID
+ {
+ return (currentFocusedPID, currentFocusedPID == originalPID)
+ }
+
+ return (originalPID, true)
+ }
+
// MARK: - Commented out app-specific prompts - using general processing only
/*
@@ -1788,12 +1804,15 @@ struct ContentView: View {
)
if shouldTypeExternally {
+ let typingTarget = self.resolveTypingTargetPID()
// Await typing completion before proceeding to edit tracker
// This ensures the tracker window opens after text has been typed
- await self.restoreFocusToRecordingTarget()
+ if typingTarget.shouldRestoreOriginalFocus {
+ await self.restoreFocusToRecordingTarget()
+ }
self.asr.typeTextToActiveField(
finalText,
- preferredTargetPID: NotchContentState.shared.recordingTargetPID
+ preferredTargetPID: typingTarget.pid
)
didTypeExternally = true
}
@@ -1939,10 +1958,13 @@ struct ContentView: View {
let shouldTypeExternally = !isFluidFrontmost
if shouldTypeExternally {
- await self.restoreFocusToRecordingTarget()
+ let typingTarget = self.resolveTypingTargetPID()
+ if typingTarget.shouldRestoreOriginalFocus {
+ await self.restoreFocusToRecordingTarget()
+ }
self.asr.typeTextToActiveField(
finalText,
- preferredTargetPID: NotchContentState.shared.recordingTargetPID
+ preferredTargetPID: typingTarget.pid
)
}
}
@@ -1994,10 +2016,13 @@ struct ContentView: View {
let isFluidFrontmost = frontmostApp?.bundleIdentifier?.contains("fluid") == true
let shouldTypeExternally = !isFluidFrontmost || self.isTranscriptionFocused == false
if shouldTypeExternally {
- await self.restoreFocusToRecordingTarget()
+ let typingTarget = self.resolveTypingTargetPID()
+ if typingTarget.shouldRestoreOriginalFocus {
+ await self.restoreFocusToRecordingTarget()
+ }
self.asr.typeTextToActiveField(
finalText,
- preferredTargetPID: NotchContentState.shared.recordingTargetPID
+ preferredTargetPID: typingTarget.pid
)
}
@@ -2042,10 +2067,13 @@ struct ContentView: View {
}
// Type the rewritten text
- await self.restoreFocusToRecordingTarget()
+ let typingTarget = self.resolveTypingTargetPID()
+ if typingTarget.shouldRestoreOriginalFocus {
+ await self.restoreFocusToRecordingTarget()
+ }
self.asr.typeTextToActiveField(
self.rewriteModeService.rewrittenText,
- preferredTargetPID: NotchContentState.shared.recordingTargetPID
+ preferredTargetPID: typingTarget.pid
)
AnalyticsService.shared.capture(
.outputDelivered,