1use std::ffi::CString;
2use crate::callbacks::get_host_callbacks;
3
4pub fn send_to_frontend(event: &str, payload: &str) -> bool {
7 host_send_to_frontend(event, payload)
8}
9
10pub fn host_send_to_frontend(event: &str, payload: &str) -> bool {
13 if let Some(callbacks) = get_host_callbacks() {
14 if let (Ok(event_str), Ok(payload_str)) = (CString::new(event), CString::new(payload)) {
15 return (callbacks.send_to_frontend)(event_str.as_ptr(), payload_str.as_ptr());
17 }
18 }
19 false
20}
21
22pub fn get_app_config(key: &str) -> Option<String> {
24 if let Some(callbacks) = get_host_callbacks() {
25 if let Ok(key_str) = CString::new(key) {
26 let result_ptr = (callbacks.get_app_config)(key_str.as_ptr());
27 if !result_ptr.is_null() {
28 unsafe {
29 let c_str = std::ffi::CStr::from_ptr(result_ptr);
30 return c_str.to_str().ok().map(|s| s.to_string());
31 }
32 }
33 }
34 }
35 None
36}
37
38pub fn call_other_plugin(plugin_id: &str, message: &str) -> Option<String> {
40 if let Some(callbacks) = get_host_callbacks() {
41 if let (Ok(id_str), Ok(msg_str)) = (CString::new(plugin_id), CString::new(message)) {
42 let result_ptr = (callbacks.call_other_plugin)(id_str.as_ptr(), msg_str.as_ptr());
43 if !result_ptr.is_null() {
44 unsafe {
45 let c_str = std::ffi::CStr::from_ptr(result_ptr);
46 return c_str.to_str().ok().map(|s| s.to_string());
47 }
48 }
49 }
50 }
51 None
52}