fix(client): keep a stored voice mode and default to voice activation only for new profiles
This commit is contained in:
parent
14543f981f
commit
8dcd3311bc
2 changed files with 15 additions and 16 deletions
|
|
@ -18,9 +18,9 @@ struct AudioPreferences {
|
|||
/// Stable id of the chosen output; empty or missing is the system default.
|
||||
output_device_id: Option<String>,
|
||||
bitrate: Option<f32>,
|
||||
mode: usize,
|
||||
/// True once the person picked the voice input mode. Files from older versions lack it and
|
||||
/// stored `mode: 0` for everybody, so an unmarked push-to-talk is not a real choice.
|
||||
/// Voice input mode stored by the app. Missing only on a profile that never saved one.
|
||||
mode: Option<usize>,
|
||||
/// True once the person picked the voice input mode explicitly.
|
||||
mode_chosen: bool,
|
||||
volume: Option<f32>,
|
||||
/// Notification sound switches and volume.
|
||||
|
|
@ -33,15 +33,14 @@ fn path() -> PathBuf {
|
|||
.join("vnox/audio.json")
|
||||
}
|
||||
|
||||
/// Resolves the voice mode to use: an explicit choice is kept, and so is any non-default mode
|
||||
/// written by older versions (those could only come from the person), but a legacy file that
|
||||
/// merely records the old push-to-talk default becomes voice activation.
|
||||
/// Resolves the voice mode to use. Voice activation is the default only for a profile that has
|
||||
/// no stored mode yet. Any mode already stored, including push-to-talk written by older
|
||||
/// versions, is kept: switching an existing profile to an open microphone would start
|
||||
/// transmitting without the person agreeing to it.
|
||||
fn resolve_mode(prefs: &AudioPreferences) -> (usize, bool) {
|
||||
let stored = prefs.mode.min(2);
|
||||
if prefs.mode_chosen || stored != 0 {
|
||||
(stored, true)
|
||||
} else {
|
||||
(DEFAULT_VOICE_MODE, false)
|
||||
match prefs.mode {
|
||||
Some(mode) => (mode.min(2), true),
|
||||
None => (DEFAULT_VOICE_MODE, false),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +86,7 @@ pub fn save(state: &UiState) -> anyhow::Result<()> {
|
|||
input_device_id: Some(state.mic_device_id.clone()),
|
||||
output_device_id: Some(state.output_device_id.clone()),
|
||||
bitrate: Some(state.voice_bitrate),
|
||||
mode: state.vad_mode,
|
||||
mode: Some(state.vad_mode),
|
||||
mode_chosen: state.vad_mode_chosen,
|
||||
volume: Some(state.output_volume),
|
||||
sounds: state.sounds,
|
||||
|
|
@ -110,10 +109,10 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_push_to_talk_default_becomes_voice_activation() {
|
||||
fn legacy_push_to_talk_is_kept_not_silently_opened() {
|
||||
assert_eq!(
|
||||
resolve_mode(&parse(r#"{"mode":0,"volume":50.0}"#)),
|
||||
(1, false)
|
||||
(0, true)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -126,7 +125,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_non_default_modes_are_kept() {
|
||||
fn stored_modes_are_kept_and_clamped() {
|
||||
assert_eq!(resolve_mode(&parse(r#"{"mode":1}"#)), (1, true));
|
||||
assert_eq!(resolve_mode(&parse(r#"{"mode":2}"#)), (2, true));
|
||||
assert_eq!(resolve_mode(&parse(r#"{"mode":9}"#)), (2, true));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue