diff --git a/frontend/wasm/src/editor_api.rs b/frontend/wasm/src/editor_api.rs index 0d5aecd6e..842f564f4 100644 --- a/frontend/wasm/src/editor_api.rs +++ b/frontend/wasm/src/editor_api.rs @@ -906,7 +906,7 @@ fn editor(callback: impl FnOnce(&mut editor::application::Editor) -> } /// Provides access to the `Editor` and its `EditorHandle` by calling the given closure with them as arguments. -pub(crate) fn editor_and_handle(mut callback: impl FnMut(&mut Editor, &mut EditorHandle)) { +pub(crate) fn editor_and_handle(callback: impl FnOnce(&mut Editor, &mut EditorHandle)) { EDITOR_HANDLE.with(|editor_handle| { editor(|editor| { let mut guard = editor_handle.try_lock(); diff --git a/frontend/wasm/src/lib.rs b/frontend/wasm/src/lib.rs index 6ef141719..2d67c9745 100644 --- a/frontend/wasm/src/lib.rs +++ b/frontend/wasm/src/lib.rs @@ -7,7 +7,9 @@ extern crate log; pub mod editor_api; pub mod helpers; +use editor::application::Editor; use editor::messages::prelude::*; +use editor_api::EditorHandle; use std::panic; use std::sync::Mutex; use std::sync::atomic::{AtomicBool, Ordering}; @@ -107,11 +109,15 @@ extern "C" { } #[wasm_bindgen] -extern "C" { - fn sendMessageToCefFromWasm(message: String); +pub fn send_message_to_frontend(message: String) { + let Ok(message) = serde_json::from_str::(&message) else { return }; + + let callback = move |_: &mut Editor, handle: &mut EditorHandle| { + handle.send_frontend_message_to_js_rust_proxy(message); + }; + editor_api::editor_and_handle(callback); } -#[wasm_bindgen] pub fn send_message_to_cef(message: String) { let global = js_sys::global();