mirror of
https://github.com/Drop-OSS/drop-app.git
synced 2025-11-14 00:31:33 +10:00
feat(settings): Added max_download_threads setting and separated settings from db
Signed-off-by: quexeky <git@quexeky.dev>
This commit is contained in:
35
src-tauri/src/settings.rs
Normal file
35
src-tauri/src/settings.rs
Normal file
@ -0,0 +1,35 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::DB;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct Settings {
|
||||
pub autostart: bool,
|
||||
pub max_download_threads: usize,
|
||||
// ... other settings ...
|
||||
}
|
||||
impl Default for Settings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
autostart: false,
|
||||
max_download_threads: 4
|
||||
}
|
||||
}
|
||||
}
|
||||
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) {
|
||||
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