feat: Update Power Mode session dynamically
This commit is contained in:
parent
1db6716539
commit
b9fad57d3e
5
VoiceInk/Notifications/AppNotifications.swift
Normal file
5
VoiceInk/Notifications/AppNotifications.swift
Normal file
@ -0,0 +1,5 @@
|
||||
import Foundation
|
||||
|
||||
extension Notification.Name {
|
||||
static let AppSettingsDidChange = Notification.Name("appSettingsDidChange")
|
||||
}
|
||||
@ -56,6 +56,8 @@ class PowerModeSessionManager {
|
||||
originalState: originalState
|
||||
)
|
||||
saveSession(newSession)
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(updateSessionSnapshot), name: .AppSettingsDidChange, object: nil)
|
||||
|
||||
await applyConfiguration(config)
|
||||
}
|
||||
@ -64,9 +66,28 @@ class PowerModeSessionManager {
|
||||
guard let session = loadSession() else { return }
|
||||
|
||||
await restoreState(session.originalState)
|
||||
|
||||
NotificationCenter.default.removeObserver(self, name: .AppSettingsDidChange, object: nil)
|
||||
|
||||
clearSession()
|
||||
}
|
||||
|
||||
@objc private func updateSessionSnapshot() {
|
||||
guard var session = loadSession(), let whisperState = whisperState, let enhancementService = enhancementService else { return }
|
||||
|
||||
let updatedState = ApplicationState(
|
||||
isEnhancementEnabled: enhancementService.isEnhancementEnabled,
|
||||
useScreenCaptureContext: enhancementService.useScreenCaptureContext,
|
||||
selectedPromptId: enhancementService.selectedPromptId?.uuidString,
|
||||
selectedAIProvider: enhancementService.getAIService()?.selectedProvider.rawValue,
|
||||
selectedAIModel: enhancementService.getAIService()?.currentModel,
|
||||
selectedLanguage: UserDefaults.standard.string(forKey: "SelectedLanguage"),
|
||||
transcriptionModelName: whisperState.currentTranscriptionModel?.name
|
||||
)
|
||||
|
||||
session.originalState = updatedState
|
||||
saveSession(session)
|
||||
}
|
||||
|
||||
private func applyConfiguration(_ config: PowerModeConfig) async {
|
||||
guard let enhancementService = enhancementService else { return }
|
||||
|
||||
@ -17,6 +17,7 @@ class AIEnhancementService: ObservableObject {
|
||||
if isEnhancementEnabled && selectedPromptId == nil {
|
||||
selectedPromptId = customPrompts.first?.id
|
||||
}
|
||||
NotificationCenter.default.post(name: .AppSettingsDidChange, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,6 +30,7 @@ class AIEnhancementService: ObservableObject {
|
||||
@Published var useScreenCaptureContext: Bool {
|
||||
didSet {
|
||||
UserDefaults.standard.set(useScreenCaptureContext, forKey: "useScreenCaptureContext")
|
||||
NotificationCenter.default.post(name: .AppSettingsDidChange, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,6 +45,7 @@ class AIEnhancementService: ObservableObject {
|
||||
@Published var selectedPromptId: UUID? {
|
||||
didSet {
|
||||
UserDefaults.standard.set(selectedPromptId?.uuidString, forKey: "selectedPromptId")
|
||||
NotificationCenter.default.post(name: .AppSettingsDidChange, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -171,6 +171,7 @@ class AIService: ObservableObject {
|
||||
}
|
||||
}
|
||||
}
|
||||
NotificationCenter.default.post(name: .AppSettingsDidChange, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
@ -261,6 +262,7 @@ class AIService: ObservableObject {
|
||||
}
|
||||
|
||||
objectWillChange.send()
|
||||
NotificationCenter.default.post(name: .AppSettingsDidChange, object: nil)
|
||||
}
|
||||
|
||||
func saveAPIKey(_ key: String, completion: @escaping (Bool) -> Void) {
|
||||
|
||||
@ -22,6 +22,7 @@ struct LanguageSelectionView: View {
|
||||
|
||||
// Post notification for language change
|
||||
NotificationCenter.default.post(name: .languageDidChange, object: nil)
|
||||
NotificationCenter.default.post(name: .AppSettingsDidChange, object: nil)
|
||||
}
|
||||
|
||||
// Function to check if current model is multilingual
|
||||
|
||||
@ -25,9 +25,9 @@ extension WhisperState {
|
||||
if model.provider != .local {
|
||||
self.isModelLoaded = true
|
||||
}
|
||||
|
||||
// Post notification about the model change
|
||||
NotificationCenter.default.post(name: .didChangeModel, object: nil, userInfo: ["modelName": model.name])
|
||||
NotificationCenter.default.post(name: .AppSettingsDidChange, object: nil)
|
||||
}
|
||||
|
||||
func refreshAllAvailableModels() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user