Start implementing wasm -> js communication for native

This commit is contained in:
Dennis Kobert 2025-07-25 23:41:22 +02:00
parent efe31918e3
commit 0248fcba77
No known key found for this signature in database
GPG key ID: 5A4358CB9530F933
2 changed files with 10 additions and 4 deletions

View file

@ -906,7 +906,7 @@ fn editor<T: Default>(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();

View file

@ -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::<FrontendMessage>(&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();