1
- use graph_craft:: wasm_application_io:: WasmApplicationIo ;
2
1
use graphite_editor:: { application:: Editor , messages:: prelude:: Message } ;
3
2
use std:: collections:: VecDeque ;
4
3
5
- use crate :: desktop_wrapper:: WgpuContext ;
6
- use crate :: desktop_wrapper:: messages:: { DesktopFrontendMessage , DesktopWrapperMessage } ;
4
+ use super :: handle_desktop_wrapper_message:: handle_desktop_wrapper_message;
5
+ use super :: intercept_frontend_message:: intercept_frontend_message;
6
+ use super :: intercept_message:: intercept_message;
7
+ use super :: messages:: { DesktopFrontendMessage , DesktopWrapperMessage } ;
7
8
8
- #[ path = "handle_editor_message.rs" ]
9
- mod handle_editor_message;
10
-
11
- #[ path = "intercept_frontend_message.rs" ]
12
- mod intercept_frontend_message;
13
- #[ path = "intercept_message.rs" ]
14
- mod intercept_message;
15
-
16
- pub struct DesktopWrapper {
17
- editor : Editor ,
18
- }
19
-
20
- impl DesktopWrapper {
21
- pub fn new ( ) -> Self {
22
- Self { editor : Editor :: new ( ) }
23
- }
24
-
25
- pub fn init ( & self , wgpu_context : WgpuContext ) {
26
- let application_io = WasmApplicationIo :: new_with_context ( wgpu_context) ;
27
- futures:: executor:: block_on ( graphite_editor:: node_graph_executor:: replace_application_io ( application_io) ) ;
28
- }
29
-
30
- pub fn dispatch ( & mut self , message : DesktopWrapperMessage ) -> Vec < DesktopFrontendMessage > {
31
- let mut executor = EditorMessageExecutor :: new ( & mut self . editor ) ;
32
- executor. queue ( message) ;
33
- executor. execute ( )
34
- }
35
-
36
- pub async fn run_node_graph ( ) -> NodeGraphExecutionResult {
37
- let result = graphite_editor:: node_graph_executor:: run_node_graph ( ) . await ;
38
- match result {
39
- ( true , texture) => NodeGraphExecutionResult :: HasRun ( texture. map ( |t| t. texture ) ) ,
40
- ( false , _) => NodeGraphExecutionResult :: NotRun ,
41
- }
42
- }
43
- }
44
-
45
- pub enum NodeGraphExecutionResult {
46
- HasRun ( Option < wgpu:: Texture > ) ,
47
- NotRun ,
48
- }
49
-
50
- struct EditorMessageExecutor < ' a > {
9
+ pub ( crate ) struct DesktopWrapperMessageExecutor < ' a > {
51
10
editor : & ' a mut Editor ,
52
11
queue : VecDeque < DesktopWrapperMessage > ,
53
12
messages : Vec < Message > ,
54
13
responses : Vec < DesktopFrontendMessage > ,
55
14
}
56
15
57
- impl < ' a > EditorMessageExecutor < ' a > {
16
+ impl < ' a > DesktopWrapperMessageExecutor < ' a > {
58
17
pub ( crate ) fn new ( editor : & ' a mut Editor ) -> Self {
59
18
Self {
60
19
editor,
@@ -74,7 +33,7 @@ impl<'a> EditorMessageExecutor<'a> {
74
33
}
75
34
76
35
pub ( super ) fn queue_message ( & mut self , message : Message ) {
77
- if let Some ( message) = intercept_message:: intercept_message ( self , message) {
36
+ if let Some ( message) = intercept_message ( self , message) {
78
37
self . messages . push ( message) ;
79
38
}
80
39
}
@@ -98,15 +57,15 @@ impl<'a> EditorMessageExecutor<'a> {
98
57
fn process_queue ( & mut self ) {
99
58
while !self . queue . is_empty ( ) || !self . messages . is_empty ( ) {
100
59
while let Some ( message) = self . queue . pop_front ( ) {
101
- handle_editor_message :: handle_editor_message ( self , message) ;
60
+ handle_desktop_wrapper_message ( self , message) ;
102
61
}
103
62
let frontend_messages = self
104
63
. editor
105
64
. handle_message ( Message :: Batched {
106
65
messages : std:: mem:: take ( & mut self . messages ) . into_boxed_slice ( ) ,
107
66
} )
108
67
. into_iter ( )
109
- . filter_map ( |m| intercept_frontend_message:: intercept_frontend_message ( self , m) )
68
+ . filter_map ( |m| intercept_frontend_message ( self , m) )
110
69
. collect :: < Vec < _ > > ( ) ;
111
70
self . respond ( DesktopFrontendMessage :: ToWeb ( ron:: to_string ( & frontend_messages) . unwrap ( ) . into_bytes ( ) ) ) ;
112
71
}
0 commit comments