Skip to content

Commit

Permalink
Fix voice search settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Bunn committed Jan 26, 2024
1 parent 56da839 commit ef28848
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo/SettingsCustomizeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct SettingsCustomizeView: View {
SettingsCellView(label: UserText.settingsAutocomplete,
accesory: .toggle(isOn: viewModel.autocompleteBinding))

if viewModel.state.speechRecognitionEnabled {
if viewModel.state.speechRecognitionAvailable {
SettingsCellView(label: UserText.settingsVoiceSearch,
accesory: .toggle(isOn: viewModel.voiceSearchEnabledBinding))
}
Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/SettingsState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ struct SettingsState {
// Features
var debugModeEnabled: Bool
var voiceSearchEnabled: Bool
var speechRecognitionEnabled: Bool
var speechRecognitionAvailable: Bool // Returns if the device has speech recognition available
var loginsEnabled: Bool

// Network Protection properties
Expand Down Expand Up @@ -108,7 +108,7 @@ struct SettingsState {
version: "0.0.0.0",
debugModeEnabled: false,
voiceSearchEnabled: false,
speechRecognitionEnabled: false,
speechRecognitionAvailable: false,
loginsEnabled: false,
networkProtection: NetworkProtection(enabled: false, status: ""),
subscription: Subscription(enabled: false, canPurchase: false,
Expand Down
14 changes: 8 additions & 6 deletions DuckDuckGo/SettingsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ final class SettingsViewModel: ObservableObject {
private var legacyViewProvider: SettingsLegacyViewProvider
private lazy var versionProvider: AppVersion = AppVersion.shared
private var accountManager: AccountManager
private let voiceSearchHelper: VoiceSearchHelperProtocol

#if NETWORK_PROTECTION
private let connectionObserver = ConnectionStatusObserverThroughSession()
Expand Down Expand Up @@ -160,15 +161,15 @@ final class SettingsViewModel: ObservableObject {
self.enableVoiceSearch { [weak self] result in
DispatchQueue.main.async {
self?.state.voiceSearchEnabled = result
self?.appSettings.voiceSearchEnabled = result
self?.voiceSearchHelper.enableVoiceSearch(true)
if !result {
// Permission is denied
self?.shouldShowNoMicrophonePermissionAlert = true
}
}
}
} else {
self.appSettings.voiceSearchEnabled = false
self.voiceSearchHelper.enableVoiceSearch(false)
self.state.voiceSearchEnabled = false
}
}
Expand Down Expand Up @@ -198,11 +199,13 @@ final class SettingsViewModel: ObservableObject {
init(state: SettingsState? = nil,
legacyViewProvider: SettingsLegacyViewProvider,
accountManager: AccountManager,
navigateOnAppearDestination: SettingsSection = .none) {
navigateOnAppearDestination: SettingsSection = .none,
voiceSearchHelper: VoiceSearchHelperProtocol = AppDependencyProvider.shared.voiceSearchHelper) {
self.state = SettingsState.defaults
self.legacyViewProvider = legacyViewProvider
self.accountManager = accountManager
self.onAppearNavigationTarget = navigateOnAppearDestination
self.voiceSearchHelper = voiceSearchHelper
}
}

Expand All @@ -229,8 +232,8 @@ extension SettingsViewModel {
activeWebsiteAccount: nil,
version: versionProvider.versionAndBuildNumber,
debugModeEnabled: featureFlagger.isFeatureOn(.debugMenu) || isDebugBuild,
voiceSearchEnabled: AppDependencyProvider.shared.voiceSearchHelper.isSpeechRecognizerAvailable,
speechRecognitionEnabled: AppDependencyProvider.shared.voiceSearchHelper.isSpeechRecognizerAvailable,
voiceSearchEnabled: AppDependencyProvider.shared.voiceSearchHelper.isVoiceSearchEnabled,
speechRecognitionAvailable: AppDependencyProvider.shared.voiceSearchHelper.isSpeechRecognizerAvailable,
loginsEnabled: featureFlagger.isFeatureOn(.autofillAccessCredentialManagement),
networkProtection: getNetworkProtectionState(),
subscription: getSubscriptionState(),
Expand Down Expand Up @@ -299,7 +302,6 @@ extension SettingsViewModel {
completion(false)
return
}
AppDependencyProvider.shared.voiceSearchHelper.enableVoiceSearch(true)
completion(true)
}
}
Expand Down

0 comments on commit ef28848

Please sign in to comment.