Skip to content

Commit 2b4cdaf

Browse files
Fix naming
1 parent 4827cfb commit 2b4cdaf

File tree

5 files changed

+64
-65
lines changed

5 files changed

+64
-65
lines changed

desktop/src/desktop_wrapper.rs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,48 @@
1-
mod editor_wrapper;
2-
pub use editor_wrapper::{DesktopWrapper, NodeGraphExecutionResult};
1+
use graph_craft::wasm_application_io::WasmApplicationIo;
2+
use graphite_editor::application::Editor;
33

4-
pub mod messages;
54
pub use wgpu_executor::Context as WgpuContext;
5+
6+
pub mod messages;
7+
use messages::{DesktopFrontendMessage, DesktopWrapperMessage};
8+
9+
mod message_executor;
10+
use message_executor::DesktopWrapperMessageExecutor;
11+
12+
mod handle_desktop_wrapper_message;
13+
mod intercept_frontend_message;
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 = DesktopWrapperMessageExecutor::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+
}

desktop/src/desktop_wrapper/handle_editor_message.rs renamed to desktop/src/desktop_wrapper/handle_desktop_wrapper_message.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use graphite_editor::messages::prelude::{DocumentMessage, Message, PortfolioMessage};
22

3-
use crate::desktop_wrapper::messages::{DesktopFrontendMessage, DesktopWrapperMessage, OpenFileDialogContext, SaveFileDialogContext};
3+
use super::DesktopWrapperMessageExecutor;
4+
use super::messages::{DesktopFrontendMessage, DesktopWrapperMessage, OpenFileDialogContext, SaveFileDialogContext};
45

5-
use super::EditorMessageExecutor;
6-
7-
pub(super) fn handle_editor_message(executor: &mut EditorMessageExecutor, message: DesktopWrapperMessage) {
6+
pub(super) fn handle_desktop_wrapper_message(executor: &mut DesktopWrapperMessageExecutor, message: DesktopWrapperMessage) {
87
match message {
98
DesktopWrapperMessage::FromWeb(data) => {
109
let string = std::str::from_utf8(&data).unwrap();

desktop/src/desktop_wrapper/intercept_frontend_message.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ use std::path::PathBuf;
22

33
use graphite_editor::messages::prelude::FrontendMessage;
44

5-
use crate::desktop_wrapper::messages::{DesktopFrontendMessage, FileFilter, OpenFileDialogContext, SaveFileDialogContext};
5+
use super::DesktopWrapperMessageExecutor;
6+
use super::messages::{DesktopFrontendMessage, FileFilter, OpenFileDialogContext, SaveFileDialogContext};
67

7-
use super::EditorMessageExecutor;
8-
9-
pub(super) fn intercept_frontend_message(executor: &mut EditorMessageExecutor, message: FrontendMessage) -> Option<FrontendMessage> {
8+
pub(super) fn intercept_frontend_message(executor: &mut DesktopWrapperMessageExecutor, message: FrontendMessage) -> Option<FrontendMessage> {
109
match message {
1110
FrontendMessage::RenderOverlays(overlay_context) => {
1211
executor.respond(DesktopFrontendMessage::UpdateOverlays(overlay_context.take_scene()));

desktop/src/desktop_wrapper/intercept_message.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use graphite_editor::messages::prelude::{InputPreprocessorMessage, Message};
22

3-
use crate::desktop_wrapper::messages::DesktopFrontendMessage;
3+
use super::DesktopWrapperMessageExecutor;
4+
use super::messages::DesktopFrontendMessage;
45

5-
use super::EditorMessageExecutor;
6-
7-
pub(super) fn intercept_message(executor: &mut EditorMessageExecutor, message: Message) -> Option<Message> {
6+
pub(super) fn intercept_message(executor: &mut DesktopWrapperMessageExecutor, message: Message) -> Option<Message> {
87
match message {
98
Message::InputPreprocessor(message) => {
109
if let InputPreprocessorMessage::BoundsOfViewports { bounds_of_viewports } = &message {

desktop/src/desktop_wrapper/editor_wrapper.rs renamed to desktop/src/desktop_wrapper/message_executor.rs

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,19 @@
1-
use graph_craft::wasm_application_io::WasmApplicationIo;
21
use graphite_editor::{application::Editor, messages::prelude::Message};
32
use std::collections::VecDeque;
43

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};
78

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> {
5110
editor: &'a mut Editor,
5211
queue: VecDeque<DesktopWrapperMessage>,
5312
messages: Vec<Message>,
5413
responses: Vec<DesktopFrontendMessage>,
5514
}
5615

57-
impl<'a> EditorMessageExecutor<'a> {
16+
impl<'a> DesktopWrapperMessageExecutor<'a> {
5817
pub(crate) fn new(editor: &'a mut Editor) -> Self {
5918
Self {
6019
editor,
@@ -74,7 +33,7 @@ impl<'a> EditorMessageExecutor<'a> {
7433
}
7534

7635
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) {
7837
self.messages.push(message);
7938
}
8039
}
@@ -98,15 +57,15 @@ impl<'a> EditorMessageExecutor<'a> {
9857
fn process_queue(&mut self) {
9958
while !self.queue.is_empty() || !self.messages.is_empty() {
10059
while let Some(message) = self.queue.pop_front() {
101-
handle_editor_message::handle_editor_message(self, message);
60+
handle_desktop_wrapper_message(self, message);
10261
}
10362
let frontend_messages = self
10463
.editor
10564
.handle_message(Message::Batched {
10665
messages: std::mem::take(&mut self.messages).into_boxed_slice(),
10766
})
10867
.into_iter()
109-
.filter_map(|m| intercept_frontend_message::intercept_frontend_message(self, m))
68+
.filter_map(|m| intercept_frontend_message(self, m))
11069
.collect::<Vec<_>>();
11170
self.respond(DesktopFrontendMessage::ToWeb(ron::to_string(&frontend_messages).unwrap().into_bytes()));
11271
}

0 commit comments

Comments
 (0)