@@ -125,14 +125,12 @@ impl JunoModule {
125
125
args : HashMap < String , Value > ,
126
126
) -> Result < Value > {
127
127
let fn_name = fn_name. to_string ( ) ;
128
- self . ensure_registered ( ) ?;
129
128
let request = self . protocol . call_function ( fn_name, args) ;
130
129
self . send_request ( request) . await
131
130
}
132
131
133
132
pub async fn register_hook ( & mut self , hook : & str , callback : fn ( Value ) ) -> Result < ( ) > {
134
133
let hook = hook. to_string ( ) ;
135
- self . ensure_registered ( ) ?;
136
134
let mut hook_listeners = self . hook_listeners . lock ( ) . await ;
137
135
if hook_listeners. contains_key ( & hook) {
138
136
hook_listeners. get_mut ( & hook) . unwrap ( ) . push ( callback) ;
@@ -157,15 +155,6 @@ impl JunoModule {
157
155
self . connection . close_connection ( ) . await ;
158
156
}
159
157
160
- fn ensure_registered ( & self ) -> Result < ( ) > {
161
- if !* self . registered . read ( ) . unwrap ( ) {
162
- return Err ( Error :: Internal ( String :: from (
163
- "Module not registered. Did you .await the call to initialize?" ,
164
- ) ) ) ;
165
- }
166
- Ok ( ( ) )
167
- }
168
-
169
158
async fn setup_connections ( & mut self ) -> Result < ( ) > {
170
159
self . connection . setup_connection ( ) . await ?;
171
160
@@ -206,6 +195,10 @@ impl JunoModule {
206
195
let request_id = request. get_request_id ( ) . clone ( ) ;
207
196
let mut encoded = self . protocol . encode ( request) ;
208
197
if * self . registered . read ( ) . unwrap ( ) || request_type == 1 {
198
+ if self . message_buffer . len ( ) != 0 {
199
+ self . connection . send ( self . message_buffer . clone ( ) ) . await ;
200
+ self . message_buffer . clear ( ) ;
201
+ }
209
202
self . connection . send ( encoded) . await ;
210
203
} else {
211
204
self . message_buffer . append ( & mut encoded) ;
@@ -300,7 +293,7 @@ async fn execute_hook_triggered(
300
293
registered_store : & Arc < RwLock < bool > > ,
301
294
hook_listeners : & ArcHookListenerList ,
302
295
) -> Result < Value > {
303
- if let BaseMessage :: TriggerHookResponse { hook, .. } = message {
296
+ if let BaseMessage :: TriggerHookResponse { hook, data , .. } = message {
304
297
if hook. is_some ( ) {
305
298
let hook = hook. unwrap ( ) ;
306
299
if hook == "juno.activated" {
@@ -313,7 +306,7 @@ async fn execute_hook_triggered(
313
306
todo ! ( "Wtf do I do now? Need to propogate errors. How do I do that?" ) ;
314
307
}
315
308
for listener in & hook_listeners[ & hook] {
316
- listener ( Value :: Null ) ;
309
+ listener ( data . clone ( ) ) ;
317
310
}
318
311
}
319
312
} else {
0 commit comments