mirror of
https://github.com/Drop-OSS/drop-app-kt.git
synced 2026-02-04 06:51:18 +01:00
chore: Progress on amend_settings command
Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user