chore: Progress on amend_settings command

Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
quexeky
2025-01-07 12:54:50 +11:00
parent 4e93eb440c
commit 97850a38f1
2 changed files with 11 additions and 10 deletions

View File

@@ -280,5 +280,6 @@ async function deleteDirectory(index: number) {
async function saveDownloadThreads() {
//Would save download threads downloadThreads.value);
await invoke("amend_settings", { newSettings: { max_download_threads: downloadThreads.value } })
}
</script>

View File

@@ -4,6 +4,7 @@ use serde_json::Value;
use crate::DB;
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Settings {
pub autostart: bool,
pub max_download_threads: usize,
@@ -17,19 +18,18 @@ impl Default for Settings {
}
}
}
fn deserialize_into<T>(v: serde_json::Value, t: &mut T) -> Result<(), serde_json::Error>
where T: for<'a> Deserialize<'a>
{
*t = serde_json::from_value(v)?;
Ok(())
}
// Ideally use pointers instead of a macro to assign the settings
// fn deserialize_into<T>(v: serde_json::Value, t: &mut T) -> Result<(), serde_json::Error>
// where T: for<'a> Deserialize<'a>
// {
// *t = serde_json::from_value(v)?;
// Ok(())
// }
#[tauri::command]
pub fn amend_settings(new_settings: Value) {
println!("{}", new_settings);
let db_lock = DB.borrow_data_mut().unwrap();
let mut current_settings = db_lock.settings.clone();
let e = deserialize_into(new_settings, &mut current_settings);
println!("Amend status: {:?}", e);
println!("New settings: {:?}", current_settings);
}