11use std:: collections:: HashMap ;
22use std:: path:: Path ;
3+ use std:: sync:: Arc ;
34
45use midoku_settings:: types:: Value ;
56use midoku_types:: chapter:: Chapter ;
@@ -23,7 +24,7 @@ use crate::state::State;
2324/// This struct contains the bindings to a Midoku source. It is used to call
2425/// functions in the WebAssembly component.
2526pub struct Bindings {
26- store : RwLock < Store < State > > ,
27+ store : Arc < RwLock < Store < State > > > ,
2728 initialize : Func < ( ) , Result < ( ) , ( ) > > ,
2829 get_manga_list : Func < ( Vec < Filter > , u32 ) , Result < ( Vec < Manga > , bool ) , ( ) > > ,
2930 get_manga_details : Func < ( String , ) , Result < Manga , ( ) > > ,
@@ -84,7 +85,7 @@ impl Bindings {
8485 let get_page_list = get_typed_func ! ( instance, store, api, "get-page-list" ) ?. into ( ) ;
8586
8687 Ok ( Self {
87- store : RwLock :: new ( store) ,
88+ store : Arc :: new ( RwLock :: new ( store) ) ,
8889 initialize,
8990 get_manga_list,
9091 get_manga_details,
@@ -99,9 +100,7 @@ impl Bindings {
99100 /// calling other functions. This may include setting up rate limiters or
100101 /// other configuration.
101102 pub async fn initialize ( & self ) -> Result < ( ) , ( ) > {
102- let mut store = self . store . write ( ) ;
103-
104- self . initialize . call ( & mut store, ( ) ) . await ?
103+ self . initialize . call ( self . store . clone ( ) , ( ) ) . await ?
105104 }
106105
107106 /// Get a list of manga from the source.
@@ -115,10 +114,8 @@ impl Bindings {
115114 filters : Vec < Filter > ,
116115 page : u32 ,
117116 ) -> Result < ( Vec < Manga > , bool ) , ( ) > {
118- let mut store = self . store . write ( ) ;
119-
120117 self . get_manga_list
121- . call ( & mut store, ( filters, page) )
118+ . call ( self . store . clone ( ) , ( filters, page) )
122119 . await ?
123120 }
124121
@@ -128,9 +125,9 @@ impl Bindings {
128125 ///
129126 /// * `id` - The ID of the manga to get details for.
130127 pub async fn get_manga_details ( & self , id : String ) -> Result < Manga , ( ) > {
131- let mut store = self . store . write ( ) ;
132-
133- self . get_manga_details . call ( & mut store , ( id , ) ) . await ?
128+ self . get_manga_details
129+ . call ( self . store . clone ( ) , ( id , ) )
130+ . await ?
134131 }
135132
136133 /// Get a list of chapters for a specific manga.
@@ -139,9 +136,9 @@ impl Bindings {
139136 ///
140137 /// * `id` - The ID of the manga to get chapters for.
141138 pub async fn get_chapter_list ( & self , id : String ) -> Result < Vec < Chapter > , ( ) > {
142- let mut store = self . store . write ( ) ;
143-
144- self . get_chapter_list . call ( & mut store , ( id , ) ) . await ?
139+ self . get_chapter_list
140+ . call ( self . store . clone ( ) , ( id , ) )
141+ . await ?
145142 }
146143
147144 /// Get a list of pages for a specific chapter.
@@ -151,10 +148,8 @@ impl Bindings {
151148 /// * `id` - The ID of the manga.
152149 /// * `chapter_id` - The ID of the chapter.
153150 pub async fn get_page_list ( & self , id : String , chapter_id : String ) -> Result < Vec < Page > , ( ) > {
154- let mut store = self . store . write ( ) ;
155-
156151 self . get_page_list
157- . call ( & mut store, ( id, chapter_id) )
152+ . call ( self . store . clone ( ) , ( id, chapter_id) )
158153 . await ?
159154 }
160155
0 commit comments