55// on the dispatcher messaging system and more complex Rust data types.
66//
77use crate :: helpers:: translate_key;
8- use crate :: { EDITOR , EDITOR_HANDLE , EDITOR_HAS_CRASHED , Error , MESSAGE_BUFFER } ;
9- use editor:: application:: Editor ;
8+ use crate :: { EDITOR_HANDLE , EDITOR_HAS_CRASHED , Error , MESSAGE_BUFFER } ;
109use editor:: consts:: FILE_SAVE_SUFFIX ;
1110use editor:: messages:: input_mapper:: utility_types:: input_keyboard:: ModifierKeys ;
1211use editor:: messages:: input_mapper:: utility_types:: input_mouse:: { EditorMouseState , ScrollDelta , ViewportBounds } ;
@@ -28,6 +27,11 @@ use wasm_bindgen::JsCast;
2827use wasm_bindgen:: prelude:: * ;
2928use web_sys:: { CanvasRenderingContext2d , HtmlCanvasElement , ImageData , window} ;
3029
30+ #[ cfg( not( feature = "native" ) ) ]
31+ use crate :: EDITOR ;
32+ #[ cfg( not( feature = "native" ) ) ]
33+ use editor:: application:: Editor ;
34+
3135static IMAGE_DATA_HASH : AtomicU64 = AtomicU64 :: new ( 0 ) ;
3236
3337fn calculate_hash < T : std:: hash:: Hash > ( t : & T ) -> u64 {
@@ -140,6 +144,7 @@ impl EditorHandle {
140144
141145#[ wasm_bindgen]
142146impl EditorHandle {
147+ #[ cfg( not( feature = "native" ) ) ]
143148 #[ wasm_bindgen( constructor) ]
144149 pub fn new ( frontend_message_handler_callback : js_sys:: Function ) -> Self {
145150 let editor = Editor :: new ( ) ;
@@ -153,6 +158,16 @@ impl EditorHandle {
153158 editor_handle
154159 }
155160
161+ #[ cfg( feature = "native" ) ]
162+ #[ wasm_bindgen( constructor) ]
163+ pub fn new ( frontend_message_handler_callback : js_sys:: Function ) -> Self {
164+ let editor_handle = EditorHandle { frontend_message_handler_callback } ;
165+ if EDITOR_HANDLE . with ( |handle| handle. lock ( ) . ok ( ) . map ( |mut guard| * guard = Some ( editor_handle. clone ( ) ) ) ) . is_none ( ) {
166+ log:: error!( "Attempted to initialize the editor handle more than once" ) ;
167+ }
168+ editor_handle
169+ }
170+
156171 // Sends a message to the dispatcher in the Editor Backend
157172 #[ cfg( not( feature = "native" ) ) ]
158173 fn dispatch < T : Into < Message > > ( & self , message : T ) {
@@ -247,6 +262,7 @@ impl EditorHandle {
247262 let g = f. clone ( ) ;
248263
249264 * g. borrow_mut ( ) = Some ( Closure :: new ( move |_timestamp| {
265+ #[ cfg( not( feature = "native" ) ) ]
250266 wasm_bindgen_futures:: spawn_local ( poll_node_graph_evaluation ( ) ) ;
251267
252268 if !EDITOR_HAS_CRASHED . load ( Ordering :: SeqCst ) {
@@ -929,6 +945,7 @@ fn set_timeout(f: &Closure<dyn FnMut()>, delay: Duration) {
929945}
930946
931947/// Provides access to the `Editor` by calling the given closure with it as an argument.
948+ #[ cfg( not( feature = "native" ) ) ]
932949fn editor < T : Default > ( callback : impl FnOnce ( & mut editor:: application:: Editor ) -> T ) -> T {
933950 EDITOR . with ( |editor| {
934951 let mut guard = editor. try_lock ( ) ;
@@ -942,6 +959,7 @@ fn editor<T: Default>(callback: impl FnOnce(&mut editor::application::Editor) ->
942959}
943960
944961/// Provides access to the `Editor` and its `EditorHandle` by calling the given closure with them as arguments.
962+ #[ cfg( not( feature = "native" ) ) ]
945963pub ( crate ) fn editor_and_handle ( callback : impl FnOnce ( & mut Editor , & mut EditorHandle ) ) {
946964 handle ( |editor_handle| {
947965 editor ( |editor| {
@@ -964,6 +982,7 @@ pub(crate) fn handle(callback: impl FnOnce(&mut EditorHandle)) {
964982 } ) ;
965983}
966984
985+ #[ cfg( not( feature = "native" ) ) ]
967986async fn poll_node_graph_evaluation ( ) {
968987 // Process no further messages after a crash to avoid spamming the console
969988 if EDITOR_HAS_CRASHED . load ( Ordering :: SeqCst ) {
0 commit comments