5
5
// on the dispatcher messaging system and more complex Rust data types.
6
6
//
7
7
use 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 } ;
10
9
use editor:: consts:: FILE_SAVE_SUFFIX ;
11
10
use editor:: messages:: input_mapper:: utility_types:: input_keyboard:: ModifierKeys ;
12
11
use editor:: messages:: input_mapper:: utility_types:: input_mouse:: { EditorMouseState , ScrollDelta , ViewportBounds } ;
@@ -28,6 +27,11 @@ use wasm_bindgen::JsCast;
28
27
use wasm_bindgen:: prelude:: * ;
29
28
use web_sys:: { CanvasRenderingContext2d , HtmlCanvasElement , ImageData , window} ;
30
29
30
+ #[ cfg( not( feature = "native" ) ) ]
31
+ use crate :: EDITOR ;
32
+ #[ cfg( not( feature = "native" ) ) ]
33
+ use editor:: application:: Editor ;
34
+
31
35
static IMAGE_DATA_HASH : AtomicU64 = AtomicU64 :: new ( 0 ) ;
32
36
33
37
fn calculate_hash < T : std:: hash:: Hash > ( t : & T ) -> u64 {
@@ -140,6 +144,7 @@ impl EditorHandle {
140
144
141
145
#[ wasm_bindgen]
142
146
impl EditorHandle {
147
+ #[ cfg( not( feature = "native" ) ) ]
143
148
#[ wasm_bindgen( constructor) ]
144
149
pub fn new ( frontend_message_handler_callback : js_sys:: Function ) -> Self {
145
150
let editor = Editor :: new ( ) ;
@@ -153,6 +158,16 @@ impl EditorHandle {
153
158
editor_handle
154
159
}
155
160
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
+
156
171
// Sends a message to the dispatcher in the Editor Backend
157
172
#[ cfg( not( feature = "native" ) ) ]
158
173
fn dispatch < T : Into < Message > > ( & self , message : T ) {
@@ -247,6 +262,7 @@ impl EditorHandle {
247
262
let g = f. clone ( ) ;
248
263
249
264
* g. borrow_mut ( ) = Some ( Closure :: new ( move |_timestamp| {
265
+ #[ cfg( not( feature = "native" ) ) ]
250
266
wasm_bindgen_futures:: spawn_local ( poll_node_graph_evaluation ( ) ) ;
251
267
252
268
if !EDITOR_HAS_CRASHED . load ( Ordering :: SeqCst ) {
@@ -929,6 +945,7 @@ fn set_timeout(f: &Closure<dyn FnMut()>, delay: Duration) {
929
945
}
930
946
931
947
/// Provides access to the `Editor` by calling the given closure with it as an argument.
948
+ #[ cfg( not( feature = "native" ) ) ]
932
949
fn editor < T : Default > ( callback : impl FnOnce ( & mut editor:: application:: Editor ) -> T ) -> T {
933
950
EDITOR . with ( |editor| {
934
951
let mut guard = editor. try_lock ( ) ;
@@ -942,6 +959,7 @@ fn editor<T: Default>(callback: impl FnOnce(&mut editor::application::Editor) ->
942
959
}
943
960
944
961
/// Provides access to the `Editor` and its `EditorHandle` by calling the given closure with them as arguments.
962
+ #[ cfg( not( feature = "native" ) ) ]
945
963
pub ( crate ) fn editor_and_handle ( callback : impl FnOnce ( & mut Editor , & mut EditorHandle ) ) {
946
964
handle ( |editor_handle| {
947
965
editor ( |editor| {
@@ -964,6 +982,7 @@ pub(crate) fn handle(callback: impl FnOnce(&mut EditorHandle)) {
964
982
} ) ;
965
983
}
966
984
985
+ #[ cfg( not( feature = "native" ) ) ]
967
986
async fn poll_node_graph_evaluation ( ) {
968
987
// Process no further messages after a crash to avoid spamming the console
969
988
if EDITOR_HAS_CRASHED . load ( Ordering :: SeqCst ) {
0 commit comments