mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-10-10 22:38:44 +02:00
refactor(store-example): replace load_from_store with TryFrom impl in example (#3277)
This commit is contained in:
1 parent
2971289252
commit
2574ec89e7
2 files changed
+16
-24
No files matched your search
@@ -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<dyn Error> 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!())
|
||||
|
||||
Reference in new issue
Block a user