@@ -15,7 +15,7 @@ pub use serde_json::Value as JsonValue;
1515use std:: {
1616 collections:: HashMap ,
1717 path:: { Path , PathBuf } ,
18- sync:: { Arc , Mutex } ,
18+ sync:: { Arc , RwLock } ,
1919 time:: Duration ,
2020} ;
2121pub use store:: { resolve_store_path, DeserializeFn , SerializeFn , Store , StoreBuilder } ;
@@ -39,7 +39,7 @@ struct ChangePayload<'a> {
3939
4040#[ derive( Debug ) ]
4141struct StoreState {
42- stores : Arc < Mutex < HashMap < PathBuf , ResourceId > > > ,
42+ stores : Arc < RwLock < HashMap < PathBuf , ResourceId > > > ,
4343 serialize_fns : HashMap < String , SerializeFn > ,
4444 deserialize_fns : HashMap < String , DeserializeFn > ,
4545 default_serialize : SerializeFn ,
@@ -139,7 +139,7 @@ async fn get_store<R: Runtime>(
139139 store_state : State < ' _ , StoreState > ,
140140 path : PathBuf ,
141141) -> Result < Option < ResourceId > > {
142- let stores = store_state. stores . lock ( ) . unwrap ( ) ;
142+ let stores = store_state. stores . read ( ) . unwrap ( ) ;
143143 Ok ( stores. get ( & resolve_store_path ( & app, path) ?) . copied ( ) )
144144}
145145
@@ -317,7 +317,7 @@ impl<R: Runtime, T: Manager<R>> StoreExt<R> for T {
317317
318318 fn get_store ( & self , path : impl AsRef < Path > ) -> Option < Arc < Store < R > > > {
319319 let collection = self . state :: < StoreState > ( ) ;
320- let stores = collection. stores . lock ( ) . unwrap ( ) ;
320+ let stores = collection. stores . read ( ) . unwrap ( ) ;
321321 stores
322322 . get ( & resolve_store_path ( self . app_handle ( ) , path. as_ref ( ) ) . ok ( ) ?)
323323 . and_then ( |rid| self . resources_table ( ) . get ( * rid) . ok ( ) )
@@ -437,7 +437,7 @@ impl Builder {
437437 ] )
438438 . setup ( move |app_handle, _api| {
439439 app_handle. manage ( StoreState {
440- stores : Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ,
440+ stores : Arc :: new ( RwLock :: new ( HashMap :: new ( ) ) ) ,
441441 serialize_fns : self . serialize_fns ,
442442 deserialize_fns : self . deserialize_fns ,
443443 default_serialize : self . default_serialize ,
@@ -448,7 +448,7 @@ impl Builder {
448448 . on_event ( |app_handle, event| {
449449 if let RunEvent :: Exit = event {
450450 let collection = app_handle. state :: < StoreState > ( ) ;
451- let stores = collection. stores . lock ( ) . unwrap ( ) ;
451+ let stores = collection. stores . read ( ) . unwrap ( ) ;
452452 for ( path, rid) in stores. iter ( ) {
453453 if let Ok ( store) = app_handle. resources_table ( ) . get :: < Store < R > > ( * rid) {
454454 if let Err ( err) = store. save ( ) {
0 commit comments