mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-12-23 10:11:54 +00:00
Start implementing wasm -> js communication for native
This commit is contained in:
parent
efe31918e3
commit
0248fcba77
2 changed files with 10 additions and 4 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue