(_ text: String, saveToHistory: Bool)
| 2737 | } |
| 2738 | |
| 2739 | private func applyHistoryTextOutput(_ text: String, saveToHistory: Bool) async { |
| 2740 | // Keep hotkey/recording state deterministic before applying output text. |
| 2741 | if self.asr.isRunning { |
| 2742 | DebugLogger.shared.info("Actions: stopping active recording before history action output", source: "ContentView") |
| 2743 | await self.asr.stopWithoutTranscription() |
| 2744 | self.cancelPrewarmDictationIfNeeded() |
| 2745 | } |
| 2746 | |
| 2747 | let appInfo = self.getCurrentAppInfo() |
| 2748 | let literalFormattedText = ASRService.applyDictationLiteralFormatting( |
| 2749 | text, |
| 2750 | appName: appInfo.name, |
| 2751 | bundleID: appInfo.bundleId, |
| 2752 | windowTitle: appInfo.windowTitle |
| 2753 | ) |
| 2754 | let gaavText = ASRService.applyGAAVFormatting(literalFormattedText) |
| 2755 | let precedingText = SettingsStore.shared.needsDictationFormattingContext |
| 2756 | ? TypingService.textBeforeCursorInFocusedField() |
| 2757 | : "" |
| 2758 | var finalText = ASRService.applyContinuousDictationFormatting(gaavText, precedingText: precedingText) |
| 2759 | finalText = ASRService.applyTerminalLiteralAutocompleteSpacing( |
| 2760 | finalText, |
| 2761 | appName: appInfo.name, |
| 2762 | bundleID: appInfo.bundleId, |
| 2763 | windowTitle: appInfo.windowTitle |
| 2764 | ) |
| 2765 | let outputPlan = ASRService.makeDictationLiteralOutputPlan( |
| 2766 | for: finalText, |
| 2767 | appName: appInfo.name, |
| 2768 | bundleID: appInfo.bundleId, |
| 2769 | windowTitle: appInfo.windowTitle |
| 2770 | ) |
| 2771 | |
| 2772 | if saveToHistory, SettingsStore.shared.saveTranscriptionHistory { |
| 2773 | TranscriptionHistoryStore.shared.addEntry( |
| 2774 | rawText: text, |
| 2775 | processedText: finalText, |
| 2776 | appName: appInfo.name, |
| 2777 | windowTitle: appInfo.windowTitle, |
| 2778 | wasAIProcessed: false |
| 2779 | ) |
| 2780 | } |
| 2781 | |
| 2782 | let frontmostApp = NSWorkspace.shared.frontmostApplication |
| 2783 | let isFluidFrontmost = frontmostApp?.bundleIdentifier == Bundle.main.bundleIdentifier |
| 2784 | |
| 2785 | if SettingsStore.shared.copyTranscriptionToClipboard, !isFluidFrontmost { |
| 2786 | ClipboardService.copyToClipboard(finalText) |
| 2787 | } |
| 2788 | |
| 2789 | let focusedPID = TypingService.captureSystemFocusedPID() |
| 2790 | ?? NSWorkspace.shared.frontmostApplication?.processIdentifier |
| 2791 | NotchContentState.shared.recordingTargetPID = focusedPID |
| 2792 | |
| 2793 | let shouldTypeExternally = !isFluidFrontmost |
| 2794 | if shouldTypeExternally { |
| 2795 | let typingTarget = self.resolveTypingTargetPID() |
| 2796 | if typingTarget.shouldRestoreOriginalFocus { |
no test coverage detected