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
This commit is contained in:
Beingpax 2025-02-24 16:46:42 +05:45
parent d250a00465
commit 763967bc35
4 changed files with 24 additions and 32 deletions

View File

@ -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()

View File

@ -43,7 +43,7 @@ class PowerModeManager: ObservableObject {
defaultConfig = PowerModeConfig(
bundleIdentifier: "default",
appName: "Default Configuration",
isAIEnhancementEnabled: true,
isAIEnhancementEnabled: false,
selectedPrompt: nil
)
saveDefaultConfig()

View File

@ -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",

View File

@ -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"
}
}
}