diff --git a/plugins/store/examples/AppSettingsManager/src-tauri/src/app/settings.rs b/plugins/store/examples/AppSettingsManager/src-tauri/src/app/settings.rs index 30514a00..99b30609 100644 --- a/plugins/store/examples/AppSettingsManager/src-tauri/src/app/settings.rs +++ b/plugins/store/examples/AppSettingsManager/src-tauri/src/app/settings.rs @@ -10,10 +10,8 @@ pub struct AppSettings { pub theme: String, } -impl AppSettings { - pub fn load_from_store( - store: &Store, - ) -> Result> { +impl From<&Store> for AppSettings { + fn from(store: &Store) -> Self { let launch_at_login = store .get("appSettings.launchAtLogin") .and_then(|v| v.as_bool()) @@ -24,9 +22,9 @@ impl AppSettings { .and_then(|v| v.as_str().map(String::from)) .unwrap_or_else(|| "dark".to_owned()); - Ok(AppSettings { + AppSettings { launch_at_login, theme, - }) + } } } diff --git a/plugins/store/examples/AppSettingsManager/src-tauri/src/main.rs b/plugins/store/examples/AppSettingsManager/src-tauri/src/main.rs index f20db4fc..a23585ba 100644 --- a/plugins/store/examples/AppSettingsManager/src-tauri/src/main.rs +++ b/plugins/store/examples/AppSettingsManager/src-tauri/src/main.rs @@ -18,28 +18,22 @@ fn main() { .setup(|app| { // Init store and load it from disk let store = app.store("settings.json")?; + app.listen("store://change", |event| { dbg!(event); }); - let app_settings = AppSettings::load_from_store(&store); - match app_settings { - Ok(app_settings) => { - let theme = app_settings.theme; - let launch_at_login = app_settings.launch_at_login; - println!("theme {theme}"); - println!("launch_at_login {launch_at_login}"); - store.set( - "appSettings", - json!({ "theme": theme, "launchAtLogin": launch_at_login }), - ); - } - Err(err) => { - eprintln!("Error loading settings: {err}"); - // Handle the error case if needed - return Err(err); // Convert the error to a Box and return Err(err) here - } - } + let app_settings = AppSettings::from(store.as_ref()); + let theme = app_settings.theme; + let launch_at_login = app_settings.launch_at_login; + + println!("theme {theme}"); + println!("launch_at_login {launch_at_login}"); + store.set( + "appSettings", + json!({ "theme": theme, "launchAtLogin": launch_at_login }), + ); + Ok(()) }) .run(tauri::generate_context!())