mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-29 02:28:13 +08:00
Start implementing wasm -> js communication for native
This commit is contained in:
@@ -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.
|
/// 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_HANDLE.with(|editor_handle| {
|
||||||
editor(|editor| {
|
editor(|editor| {
|
||||||
let mut guard = editor_handle.try_lock();
|
let mut guard = editor_handle.try_lock();
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ extern crate log;
|
|||||||
pub mod editor_api;
|
pub mod editor_api;
|
||||||
pub mod helpers;
|
pub mod helpers;
|
||||||
|
|
||||||
|
use editor::application::Editor;
|
||||||
use editor::messages::prelude::*;
|
use editor::messages::prelude::*;
|
||||||
|
use editor_api::EditorHandle;
|
||||||
use std::panic;
|
use std::panic;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
@@ -107,11 +109,15 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern "C" {
|
pub fn send_message_to_frontend(message: String) {
|
||||||
fn sendMessageToCefFromWasm(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) {
|
pub fn send_message_to_cef(message: String) {
|
||||||
let global = js_sys::global();
|
let global = js_sys::global();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user