From b19a68e77f763c1a0d9c32efaf8f3a6c6ae48f30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=90=91=E5=A4=9C?= Date: Fri, 12 Jul 2024 23:24:27 +0800 Subject: [PATCH] feat(config): add config for grassator --- src-tauri/src/lib.rs | 9 ++++++++- src-tauri/src/state.rs | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src-tauri/src/state.rs diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index da038bd..6eb9554 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,6 +1,12 @@ mod models; +mod state; mod utils; +#[tauri::command] +fn get_config(config: tauri::State) -> Result { + Ok(config.inner().clone()) +} + #[tauri::command] async fn get_file_size(url: &str) -> Result { match utils::get_file_size(url).await { @@ -15,8 +21,9 @@ async fn get_file_size(url: &str) -> Result { #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() + .manage(state::Config::default()) .plugin(tauri_plugin_shell::init()) - .invoke_handler(tauri::generate_handler![get_file_size]) + .invoke_handler(tauri::generate_handler![get_config, get_file_size]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rs new file mode 100644 index 0000000..b4bf688 --- /dev/null +++ b/src-tauri/src/state.rs @@ -0,0 +1,16 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub(crate) struct Config { + pub(crate) preset_file: String, + pub(crate) threads_count: u32, +} + +impl Default for Config { + fn default() -> Self { + Self { + preset_file: String::from("presets/default.json"), + threads_count: 1, + } + } +}