From 763967bc35dae7929bee3e624f1023f7bd08d8fd Mon Sep 17 00:00:00 2001 From: Beingpax Date: Mon, 24 Feb 2025 16:46:42 +0545 Subject: [PATCH] refactor: improve default settings and task execution - Change default push-to-talk key to Right Command - Disable AI enhancement by default in Power Mode - Set English as default language for multilingual models - Make task execution sequential in WhisperState for better control flow --- VoiceInk/HotkeyManager.swift | 2 +- VoiceInk/Models/PowerModeConfig.swift | 2 +- VoiceInk/Views/LanguageSelectionView.swift | 2 +- VoiceInk/WhisperState.swift | 50 +++++++++------------- 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/VoiceInk/HotkeyManager.swift b/VoiceInk/HotkeyManager.swift index 9a0344f..8103166 100644 --- a/VoiceInk/HotkeyManager.swift +++ b/VoiceInk/HotkeyManager.swift @@ -71,7 +71,7 @@ class HotkeyManager: ObservableObject { init(whisperState: WhisperState) { self.isPushToTalkEnabled = UserDefaults.standard.bool(forKey: "isPushToTalkEnabled") - self.pushToTalkKey = PushToTalkKey(rawValue: UserDefaults.standard.string(forKey: "pushToTalkKey") ?? "") ?? .rightOption + self.pushToTalkKey = PushToTalkKey(rawValue: UserDefaults.standard.string(forKey: "pushToTalkKey") ?? "") ?? .rightCommand self.whisperState = whisperState updateShortcutStatus() diff --git a/VoiceInk/Models/PowerModeConfig.swift b/VoiceInk/Models/PowerModeConfig.swift index 5b93bd5..e932402 100644 --- a/VoiceInk/Models/PowerModeConfig.swift +++ b/VoiceInk/Models/PowerModeConfig.swift @@ -43,7 +43,7 @@ class PowerModeManager: ObservableObject { defaultConfig = PowerModeConfig( bundleIdentifier: "default", appName: "Default Configuration", - isAIEnhancementEnabled: true, + isAIEnhancementEnabled: false, selectedPrompt: nil ) saveDefaultConfig() diff --git a/VoiceInk/Views/LanguageSelectionView.swift b/VoiceInk/Views/LanguageSelectionView.swift index f8e7dec..2b7f200 100644 --- a/VoiceInk/Views/LanguageSelectionView.swift +++ b/VoiceInk/Views/LanguageSelectionView.swift @@ -2,7 +2,7 @@ import SwiftUI struct LanguageSelectionView: View { @ObservedObject var whisperState: WhisperState - @State private var selectedLanguage: String = UserDefaults.standard.string(forKey: "SelectedLanguage") ?? "auto" + @State private var selectedLanguage: String = UserDefaults.standard.string(forKey: "SelectedLanguage") ?? "en" let languages = [ "auto": "Auto-detect", diff --git a/VoiceInk/WhisperState.swift b/VoiceInk/WhisperState.swift index a0a627b..81c4d2d 100644 --- a/VoiceInk/WhisperState.swift +++ b/VoiceInk/WhisperState.swift @@ -270,36 +270,28 @@ class WhisperState: NSObject, ObservableObject, AVAudioRecorderDelegate { self.recordedFile = file self.transcriptionStartTime = Date() - // Handle all parallel tasks - await withTaskGroup(of: Void.self) { group in - // Task 1: Configuration detection - group.addTask { - await ActiveWindowService.shared.applyConfigurationForCurrentApp() + // Handle tasks sequentially + // Step 1: Apply power mode configuration + await ActiveWindowService.shared.applyConfigurationForCurrentApp() + + // Step 2: Handle screen capture if enabled by the configuration + if let enhancementService = self.enhancementService, + enhancementService.isEnhancementEnabled && + enhancementService.useScreenCaptureContext { + await MainActor.run { + self.messageLog += "Capturing screen context...\n" } - - // Task 2: Screen capture if enabled - if let enhancementService = self.enhancementService, - enhancementService.isEnhancementEnabled && - enhancementService.useScreenCaptureContext { - group.addTask { - await MainActor.run { - self.messageLog += "Capturing screen context...\n" - } - await enhancementService.captureScreenContext() - } - } - - // Task 3: Model loading if needed - if let currentModel = self.currentModel, self.whisperContext == nil { - group.addTask { - do { - try await self.loadModel(currentModel) - } catch { - await MainActor.run { - print("Error preloading model: \(error.localizedDescription)") - self.messageLog += "Error preloading model: \(error.localizedDescription)\n" - } - } + await enhancementService.captureScreenContext() + } + + // Step 3: Load model if needed + if let currentModel = self.currentModel, self.whisperContext == nil { + do { + try await self.loadModel(currentModel) + } catch { + await MainActor.run { + print("Error preloading model: \(error.localizedDescription)") + self.messageLog += "Error preloading model: \(error.localizedDescription)\n" } } }