From 95e57bf3f7b801c6dcf0f9a7d3bed1b6bd7b5172 Mon Sep 17 00:00:00 2001 From: Beingpax Date: Sat, 6 Sep 2025 09:36:55 +0545 Subject: [PATCH] Added support for retry functionality --- VoiceInk/HotkeyManager.swift | 11 +++++++++-- VoiceInk/Services/ImportExportService.swift | 5 +++++ VoiceInk/Views/Settings/SettingsView.swift | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/VoiceInk/HotkeyManager.swift b/VoiceInk/HotkeyManager.swift index 407986e..ae9f3a5 100644 --- a/VoiceInk/HotkeyManager.swift +++ b/VoiceInk/HotkeyManager.swift @@ -7,6 +7,7 @@ extension KeyboardShortcuts.Name { static let toggleMiniRecorder = Self("toggleMiniRecorder") static let toggleMiniRecorder2 = Self("toggleMiniRecorder2") static let pasteLastTranscription = Self("pasteLastTranscription") + static let retryLastTranscription = Self("retryLastTranscription") } @MainActor @@ -140,18 +141,24 @@ class HotkeyManager: ObservableObject { self.whisperState = whisperState self.miniRecorderShortcutManager = MiniRecorderShortcutManager(whisperState: whisperState) - if KeyboardShortcuts.getShortcut(for: .pasteLastTranscription) == nil { let defaultPasteShortcut = KeyboardShortcuts.Shortcut(.v, modifiers: [.command, .option]) KeyboardShortcuts.setShortcut(defaultPasteShortcut, for: .pasteLastTranscription) } - + KeyboardShortcuts.onKeyUp(for: .pasteLastTranscription) { [weak self] in guard let self = self else { return } Task { @MainActor in LastTranscriptionService.pasteLastTranscription(from: self.whisperState.modelContext) } } + + KeyboardShortcuts.onKeyUp(for: .retryLastTranscription) { [weak self] in + guard let self = self else { return } + Task { @MainActor in + LastTranscriptionService.retryLastTranscription(from: self.whisperState.modelContext, whisperState: self.whisperState) + } + } Task { @MainActor in try? await Task.sleep(nanoseconds: 100_000_000) diff --git a/VoiceInk/Services/ImportExportService.swift b/VoiceInk/Services/ImportExportService.swift index 2b08313..1578ffc 100644 --- a/VoiceInk/Services/ImportExportService.swift +++ b/VoiceInk/Services/ImportExportService.swift @@ -7,6 +7,7 @@ import LaunchAtLogin struct GeneralSettings: Codable { let toggleMiniRecorderShortcut: KeyboardShortcuts.Shortcut? let toggleMiniRecorderShortcut2: KeyboardShortcuts.Shortcut? + let retryLastTranscriptionShortcut: KeyboardShortcuts.Shortcut? let selectedHotkey1RawValue: String? let selectedHotkey2RawValue: String? let launchAtLoginEnabled: Bool? @@ -86,6 +87,7 @@ class ImportExportService { let generalSettingsToExport = GeneralSettings( toggleMiniRecorderShortcut: KeyboardShortcuts.getShortcut(for: .toggleMiniRecorder), toggleMiniRecorderShortcut2: KeyboardShortcuts.getShortcut(for: .toggleMiniRecorder2), + retryLastTranscriptionShortcut: KeyboardShortcuts.getShortcut(for: .retryLastTranscription), selectedHotkey1RawValue: hotkeyManager.selectedHotkey1.rawValue, selectedHotkey2RawValue: hotkeyManager.selectedHotkey2.rawValue, launchAtLoginEnabled: LaunchAtLogin.isEnabled, @@ -218,6 +220,9 @@ class ImportExportService { if let shortcut2 = general.toggleMiniRecorderShortcut2 { KeyboardShortcuts.setShortcut(shortcut2, for: .toggleMiniRecorder2) } + if let retryShortcut = general.retryLastTranscriptionShortcut { + KeyboardShortcuts.setShortcut(retryShortcut, for: .retryLastTranscription) + } if let hotkeyRaw = general.selectedHotkey1RawValue, let hotkey = HotkeyManager.HotkeyOption(rawValue: hotkeyRaw) { hotkeyManager.selectedHotkey1 = hotkey diff --git a/VoiceInk/Views/Settings/SettingsView.swift b/VoiceInk/Views/Settings/SettingsView.swift index e54ae0a..93b7f0e 100644 --- a/VoiceInk/Views/Settings/SettingsView.swift +++ b/VoiceInk/Views/Settings/SettingsView.swift @@ -130,6 +130,25 @@ struct SettingsView: View { Divider() + // Retry Last Transcription + HStack(spacing: 12) { + Text("Retry Last Transcription") + .font(.system(size: 13, weight: .medium)) + .foregroundColor(.secondary) + + KeyboardShortcuts.Recorder(for: .retryLastTranscription) + .controlSize(.small) + + InfoTip( + title: "Retry Last Transcription", + message: "Re-transcribe the last recorded audio using the current model and copy the result." + ) + + Spacer() + } + + Divider() + // Middle-Click Toggle VStack(alignment: .leading, spacing: 12) { HStack(spacing: 8) {