File tree Expand file tree Collapse file tree
plugins/store/examples/AppSettingsManager/src-tauri/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,10 +10,8 @@ pub struct AppSettings {
1010 pub theme : String ,
1111}
1212
13- impl AppSettings {
14- pub fn load_from_store < R : tauri:: Runtime > (
15- store : & Store < R > ,
16- ) -> Result < Self , Box < dyn std:: error:: Error > > {
13+ impl < R : tauri:: Runtime > From < & Store < R > > for AppSettings {
14+ fn from ( store : & Store < R > ) -> Self {
1715 let launch_at_login = store
1816 . get ( "appSettings.launchAtLogin" )
1917 . and_then ( |v| v. as_bool ( ) )
@@ -24,9 +22,9 @@ impl AppSettings {
2422 . and_then ( |v| v. as_str ( ) . map ( String :: from) )
2523 . unwrap_or_else ( || "dark" . to_owned ( ) ) ;
2624
27- Ok ( AppSettings {
25+ AppSettings {
2826 launch_at_login,
2927 theme,
30- } )
28+ }
3129 }
3230}
Original file line number Diff line number Diff line change @@ -18,28 +18,22 @@ fn main() {
1818 . setup ( |app| {
1919 // Init store and load it from disk
2020 let store = app. store ( "settings.json" ) ?;
21+
2122 app. listen ( "store://change" , |event| {
2223 dbg ! ( event) ;
2324 } ) ;
24- let app_settings = AppSettings :: load_from_store ( & store) ;
25- match app_settings {
26- Ok ( app_settings) => {
27- let theme = app_settings. theme ;
28- let launch_at_login = app_settings. launch_at_login ;
29-
30- println ! ( "theme {theme}" ) ;
31- println ! ( "launch_at_login {launch_at_login}" ) ;
32- store. set (
33- "appSettings" ,
34- json ! ( { "theme" : theme, "launchAtLogin" : launch_at_login } ) ,
35- ) ;
36- }
37- Err ( err) => {
38- eprintln ! ( "Error loading settings: {err}" ) ;
39- // Handle the error case if needed
40- return Err ( err) ; // Convert the error to a Box<dyn Error> and return Err(err) here
41- }
42- }
25+
26+ let app_settings = AppSettings :: from ( store. as_ref ( ) ) ;
27+ let theme = app_settings. theme ;
28+ let launch_at_login = app_settings. launch_at_login ;
29+
30+ println ! ( "theme {theme}" ) ;
31+ println ! ( "launch_at_login {launch_at_login}" ) ;
32+ store. set (
33+ "appSettings" ,
34+ json ! ( { "theme" : theme, "launchAtLogin" : launch_at_login } ) ,
35+ ) ;
36+
4337 Ok ( ( ) )
4438 } )
4539 . run ( tauri:: generate_context!( ) )
You can’t perform that action at this time.
0 commit comments