From 8f20923730c6104e57c0accc433d26c22917c1ff Mon Sep 17 00:00:00 2001 From: Sanket Chaudhari Date: Wed, 21 Oct 2020 12:25:31 +0530 Subject: [PATCH] feat: add event listener for database events --- src/event_handlers.rs | 13 +++++++++++++ src/lib.rs | 9 ++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/event_handlers.rs b/src/event_handlers.rs index dded67d..9c6aae0 100644 --- a/src/event_handlers.rs +++ b/src/event_handlers.rs @@ -124,3 +124,16 @@ pub fn sinix_install(mut webview: tauri::WebviewMut, msg: Option) { ) .expect("failed to emit"); } + +pub fn database(mut webview: tauri::WebviewMut, msg: Option) { + let reply = Reply { + data: "response".to_string(), + }; + + tauri::event::emit( + &mut webview, + String::from("sinix-database-response"), + Some(serde_json::to_string(&reply).unwrap()), + ) + .expect("failed to emit"); +} diff --git a/src/lib.rs b/src/lib.rs index 86464ed..ce53619 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,9 +42,16 @@ pub fn tauri_handler(webview: &mut Webview, _source: String) { // handler function for tauri app setup callback let webview = webview.as_mut(); + let webview_clone = webview.clone(); tauri::event::listen(String::from("sinix-install"), move |msg| { - event_handlers::sinix_install(webview.clone(), msg) + event_handlers::sinix_install(webview_clone.clone(), msg); + }); + + let webview_clone = webview.clone(); + + tauri::event::listen(String::from("sinix-database"), move |msg| { + event_handlers::database(webview_clone.clone(), msg); }); }