diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 7cb4db4..e34bbd3 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -45,7 +45,7 @@ fn hash256sum(hash_input: String) -> String { // Example command using managed state #[tauri::command] #[specta::specta] -fn store_set_key(key: String, value: String, store: State) -> () { +fn store_set_key(key: String, value: String, store: State) { store.add_key_val(key, value); } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 983b6ca..568f9a4 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -25,10 +25,9 @@ fn main() { // Run the app app.build(tauri::generate_context!()) .expect("error while running tauri application") - .run(|_, e| match e { - RunEvent::Ready => { + .run(|_, e| { + if let RunEvent::Ready = e { println!("Window is ready"); } - _ => {} }) } diff --git a/src-tauri/src/state.rs b/src-tauri/src/state.rs index 5492b7b..91f6eae 100644 --- a/src-tauri/src/state.rs +++ b/src-tauri/src/state.rs @@ -4,6 +4,7 @@ use std::{collections::HashMap, sync::Mutex}; use tauri::{Builder, Wry}; +#[derive(Default)] pub struct Store { store: Mutex>, } @@ -15,18 +16,17 @@ impl Store { .insert(key, val); } pub fn read_key(&self, key: &String) -> Option { - match self.store.lock().expect("cannot lock store").get(key) { - Some(s) => Some(s.to_string()), - None => None, - } + self.store + .lock() + .expect("cannot lock store") + .get(key) + .map(|val| val.to_string()) } } // Exports a function for the tauri app instance to use and register all commands defined as frontend IPC command handlers. pub fn register_managed_state(builder: Builder) -> Builder { - let store = Store { - store: Mutex::from(HashMap::new()), - }; + let store = Store::default(); builder.manage(store) }