Add reset_audio_settings Rust command
Adds reset_all() to both AudioSettingsStore and PlaybackPreferencesStore. The reset_audio_settings tauri command resets both audio and playback preferences to their default values in a single call.
This commit is contained in:
1 parent
1a5b8ae428
commit
2d94430c0a
4 files changed
+88
No files matched your search
@@ -319,6 +319,60 @@ impl AudioSettingsStore {
|
||||
.map_err(|e| format!("Failed to set normalization target LUFS: {}", e))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Reset all audio settings to their default values
|
||||
pub fn reset_all(&self) -> Result<AudioSettings, String> {
|
||||
let defaults = AudioSettings::default();
|
||||
let backend_json: Option<String> = defaults.backend_type
|
||||
.map(|b| serde_json::to_string(&b))
|
||||
.transpose()
|
||||
.map_err(|e| format!("Failed to serialize backend type: {}", e))?;
|
||||
let plugin_json: Option<String> = defaults.alsa_plugin
|
||||
.map(|p| serde_json::to_string(&p))
|
||||
.transpose()
|
||||
.map_err(|e| format!("Failed to serialize ALSA plugin: {}", e))?;
|
||||
|
||||
self.conn
|
||||
.execute(
|
||||
"UPDATE audio_settings SET
|
||||
output_device = ?1,
|
||||
exclusive_mode = ?2,
|
||||
dac_passthrough = ?3,
|
||||
preferred_sample_rate = ?4,
|
||||
backend_type = ?5,
|
||||
alsa_plugin = ?6,
|
||||
alsa_hardware_volume = ?7,
|
||||
stream_first_track = ?8,
|
||||
stream_buffer_seconds = ?9,
|
||||
streaming_only = ?10,
|
||||
limit_quality_to_device = ?11,
|
||||
device_max_sample_rate = ?12,
|
||||
normalization_enabled = ?13,
|
||||
normalization_target_lufs = ?14,
|
||||
gapless_enabled = ?15
|
||||
WHERE id = 1",
|
||||
params![
|
||||
defaults.output_device,
|
||||
defaults.exclusive_mode as i64,
|
||||
defaults.dac_passthrough as i64,
|
||||
defaults.preferred_sample_rate.map(|r| r as i64),
|
||||
backend_json,
|
||||
plugin_json,
|
||||
defaults.alsa_hardware_volume as i64,
|
||||
defaults.stream_first_track as i64,
|
||||
defaults.stream_buffer_seconds as i64,
|
||||
defaults.streaming_only as i64,
|
||||
defaults.limit_quality_to_device as i64,
|
||||
defaults.device_max_sample_rate.map(|r| r as i64),
|
||||
defaults.normalization_enabled as i64,
|
||||
defaults.normalization_target_lufs as f64,
|
||||
defaults.gapless_enabled as i64,
|
||||
],
|
||||
)
|
||||
.map_err(|e| format!("Failed to reset audio settings: {}", e))?;
|
||||
|
||||
Ok(defaults)
|
||||
}
|
||||
}
|
||||
|
||||
/// Thread-safe wrapper
|
||||
@@ -529,3 +583,23 @@ pub fn set_audio_gapless_enabled(
|
||||
let store = guard.as_ref().ok_or("No active session - please log in")?;
|
||||
store.set_gapless_enabled(enabled)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn reset_audio_settings(
|
||||
audio_state: tauri::State<'_, AudioSettingsState>,
|
||||
playback_state: tauri::State<'_, crate::config::playback_preferences::PlaybackPreferencesState>,
|
||||
) -> Result<AudioSettings, String> {
|
||||
log::info!("Command: reset_audio_settings (resetting audio + playback to defaults)");
|
||||
|
||||
// Reset audio settings
|
||||
let guard = audio_state.store.lock().map_err(|e| format!("Lock error: {}", e))?;
|
||||
let store = guard.as_ref().ok_or("No active session - please log in")?;
|
||||
let defaults = store.reset_all()?;
|
||||
|
||||
// Reset playback preferences
|
||||
let pb_guard = playback_state.store.lock().map_err(|e| format!("Lock error: {}", e))?;
|
||||
let pb_store = pb_guard.as_ref().ok_or("No active session - please log in")?;
|
||||
pb_store.reset_all()?;
|
||||
|
||||
Ok(defaults)
|
||||
}
|
||||
@@ -27,6 +27,7 @@ pub use audio_settings::{
|
||||
set_audio_exclusive_mode,
|
||||
set_audio_dac_passthrough,
|
||||
set_audio_sample_rate,
|
||||
reset_audio_settings,
|
||||
};
|
||||
|
||||
pub use download_settings::{
|
||||
|
||||
@@ -162,6 +162,18 @@ impl PlaybackPreferencesStore {
|
||||
.map_err(|e| format!("Failed to set show context icon: {}", e))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Reset all playback preferences to their default values
|
||||
pub fn reset_all(&self) -> Result<PlaybackPreferences, String> {
|
||||
let defaults = PlaybackPreferences::default();
|
||||
self.conn
|
||||
.execute(
|
||||
"UPDATE playback_preferences SET autoplay_mode = ?1, show_context_icon = ?2 WHERE id = 1",
|
||||
params![defaults.autoplay_mode.to_db_value(), if defaults.show_context_icon { 1 } else { 0 }],
|
||||
)
|
||||
.map_err(|e| format!("Failed to reset playback preferences: {}", e))?;
|
||||
Ok(defaults)
|
||||
}
|
||||
}
|
||||
|
||||
/// Global state wrapper for thread-safe access
|
||||
|
||||
@@ -741,6 +741,7 @@ pub fn run() {
|
||||
config::audio_settings::set_audio_normalization_enabled,
|
||||
config::audio_settings::set_audio_normalization_target,
|
||||
config::audio_settings::set_audio_gapless_enabled,
|
||||
config::audio_settings::reset_audio_settings,
|
||||
// Audio backend commands
|
||||
commands::get_available_backends,
|
||||
commands::get_devices_for_backend,
|
||||
|
||||
Reference in new issue
Block a user