pub fn emit<D: ApplicationDispatcherExt, S: Serialize>(
  webview_dispatcher: &crate::WebviewDispatcher<D>,
  event: impl AsRef<str>,
  payload: Option<S>,
) -> crate::Result<()> {
  let salt = crate::salt::generate();

  let js_payload = if let Some(payload_value) = payload {
    serde_json::to_value(payload_value)?
  } else {
    JsonValue::Null
  };

  webview_dispatcher.eval(&format!(
    "window['{}']({{type: '{}', payload: {}}}, '{}')",
    emit_function_name(),
    event.as_ref(),
    js_payload,
    salt
  ))?;

  Ok(())
}
/// Emits an event to JS.
Emits an event to JS.
Emits an event to JS .
pub fn emit<D: ApplicationDispatcherExt, S: Serialize>(
  webview_dispatcher: &crate::WebviewDispatcher<D>,
  event: impl AsRef<str>,
  payload: Option<S>,
) -> crate::Result<()> {
  let salt = crate::salt::generate();
  let js_payload = if let Some(payload_value) = payload {
    serde_json::to_value(payload_value)?
  } else {
    JsonValue::Null
  };
  webview_dispatcher.eval(&format!(
    "window['{}']({{type: '{}', payload: {}}}, '{}')",
    emit_function_name(),
    event.as_ref(),
    js_payload,
    salt
  ))?;
  Ok(())
}
pub fn emit < D : ApplicationDispatcherExt , S : Serialize > ( webview_dispatcher : & crate :: WebviewDispatcher < D > , event : impl AsRef < str > , payload : Option < S > , ) -> crate :: Result < ( ) > { let salt = crate :: salt :: generate ( ) ; let js_payload = if let Some ( payload_value ) = payload { serde_json :: to_value ( payload_value ) ? } else { JsonValue :: Null } ; webview_dispatcher . eval ( & format ! ( " " emit_function_name ( ) event as_ref ( ) js_payload salt ) ) ? ; Ok ( ( ) ) }
Emits an event to JS.
Emits an event to JS .
webview_dispatcher
&crate::WebviewDispatcher<D>
event
impl AsRef<str>
payload
Option<S>
webview_dispatcher
&crate::WebviewDispatcher<D>
event
impl AsRef<str>
payload
Option<S>