Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions editor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ spin = { workspace = true }
image = { workspace = true }
color = { workspace = true }
zip = { workspace = true }
reqwest = { workspace = true }
url = { workspace = true }

# Optional local dependencies
wgpu-executor = { workspace = true, optional = true }
Expand Down
13 changes: 4 additions & 9 deletions editor/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct DispatcherMessageHandlers {
key_mapping_message_handler: KeyMappingMessageHandler,
layout_message_handler: LayoutMessageHandler,
menu_bar_message_handler: MenuBarMessageHandler,
network_message_handler: NetworkMessageHandler,
pub(crate) portfolio_message_handler: PortfolioMessageHandler,
preferences_message_handler: PreferencesMessageHandler,
pub(crate) resource_storage_message_handler: ResourceStorageMessageHandler,
Expand Down Expand Up @@ -79,8 +80,6 @@ const FRONTEND_UPDATE_MESSAGES: &[MessageDiscriminant] = &[
MessageDiscriminant::Portfolio(PortfolioMessageDiscriminant::Document(DocumentMessageDiscriminant::RenderScrollbars)),
MessageDiscriminant::Frontend(FrontendMessageDiscriminant::UpdateDocumentLayerStructure),
];
// FrontendMessages that should be sent immediately
const IMMEDIATE_FRONTEND_MESSAGES: &[FrontendMessageDiscriminant] = &[FrontendMessageDiscriminant::TriggerResolveResource, FrontendMessageDiscriminant::TriggerFontCatalogLoad];
const DEBUG_MESSAGE_BLOCK_LIST: &[MessageDiscriminant] = &[
MessageDiscriminant::Broadcast(BroadcastMessageDiscriminant::TriggerEvent(EventMessageDiscriminant::AnimationFrame)),
MessageDiscriminant::Animation(AnimationMessageDiscriminant::IncrementFrameCounter),
Expand Down Expand Up @@ -206,14 +205,7 @@ impl Dispatcher {
self.message_handlers.dialog_message_handler.process_message(message, &mut queue, context);
}
Message::Frontend(message) => {
let decreminant = message.to_discriminant();
self.responses.push(message);

// Handle these message immediately by returning early
if IMMEDIATE_FRONTEND_MESSAGES.contains(&decreminant) {
self.cleanup_queues(false);
return;
}
}
Message::InputPreprocessor(message) => {
self.message_handlers.input_preprocessor_message_handler.process_message(
Expand All @@ -238,6 +230,9 @@ impl Dispatcher {

self.message_handlers.layout_message_handler.process_message(message, &mut queue, context);
}
Message::Network(message) => {
self.message_handlers.network_message_handler.process_message(message, &mut queue, NetworkMessageContext {});
}
Message::ResourceStorage(message) => {
self.message_handlers
.resource_storage_message_handler
Expand Down
9 changes: 0 additions & 9 deletions editor/src/messages/frontend/frontend_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::messages::portfolio::document::utility_types::wires::{WirePath, WireP
use crate::messages::portfolio::utility_types::WorkspacePanelLayout;
use crate::messages::prelude::*;
use crate::messages::tool::tool_messages::eyedropper_tool::PrimarySecondary;
use graph_craft::application_io::resource::ResourceId;
use graph_craft::document::NodeId;
use graphene_std::color::SRGBA8;
use graphene_std::raster::Image;
Expand Down Expand Up @@ -111,14 +110,6 @@ pub enum FrontendMessage {
name: String,
filename: String,
},
TriggerFontCatalogLoad,
TriggerResolveResource {
#[serde(rename = "documentId")]
document_id: DocumentId,
#[serde(rename = "resourceId")]
resource_id: ResourceId,
url: String,
},
TriggerPersistenceReadState,
TriggerPersistenceReadDocument {
#[serde(rename = "documentId")]
Expand Down
8 changes: 6 additions & 2 deletions editor/src/messages/future/future_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ use std::future::{Future, IntoFuture};
use std::pin::Pin;
use std::sync::{Arc, Mutex};

use dyn_any::WasmNotSend;
use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender, unbounded};

use crate::messages::prelude::*;

#[cfg(not(target_family = "wasm"))]
type InnerMessageFuture = Pin<Box<dyn Future<Output = Message> + Send + 'static>>;
#[cfg(target_family = "wasm")]
type InnerMessageFuture = Pin<Box<dyn Future<Output = Message> + 'static>>;

/// Invoked by the spawner after a result is sent, to wake the platform event loop.
pub type Wake = Arc<dyn Fn() + Send + Sync>;
Expand All @@ -23,7 +27,7 @@ pub struct MessageFuture {
}

impl MessageFuture {
pub fn new(future: impl Future<Output = Message> + Send + 'static) -> Self {
pub fn new(future: impl Future<Output = Message> + WasmNotSend + 'static) -> Self {
Self {
inner: Arc::new(Mutex::new(Some(Box::pin(future)))),
}
Expand Down Expand Up @@ -51,7 +55,7 @@ impl From<MessageFuture> for Message {

impl<T> From<T> for Message
where
T: Future<Output = Message> + Send + 'static,
T: Future<Output = Message> + WasmNotSend + 'static,
{
fn from(future: T) -> Self {
MessageFuture::new(future).into()
Expand Down
2 changes: 2 additions & 0 deletions editor/src/messages/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub enum Message {
#[child]
MenuBar(MenuBarMessage),
#[child]
Network(NetworkMessage),
#[child]
Portfolio(PortfolioMessage),
#[child]
Preferences(PreferencesMessage),
Expand Down
1 change: 1 addition & 0 deletions editor/src/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod input_preprocessor;
pub mod layout;
pub mod menu_bar;
pub mod message;
pub mod network;
pub mod portfolio;
pub mod preferences;
pub mod prelude;
Expand Down
10 changes: 10 additions & 0 deletions editor/src/messages/network/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mod network_message;
mod network_message_handler;
pub mod utility_types;

#[doc(inline)]
pub use network_message::{NetworkMessage, NetworkMessageDiscriminant};
#[doc(inline)]
pub use network_message_handler::{NetworkMessageContext, NetworkMessageHandler};
#[doc(inline)]
pub use utility_types::Client;
49 changes: 49 additions & 0 deletions editor/src/messages/network/network_message.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use std::pin::Pin;

use dyn_any::WasmNotSend;

use crate::messages::network::utility_types::Client;
use crate::messages::prelude::*;

#[impl_message(Message, Network)]
#[derive(derivative::Derivative, serde::Serialize, serde::Deserialize)]
#[derivative(Debug, PartialEq)]
pub enum NetworkMessage {
Request {
#[serde(skip, default)]
#[derivative(Debug = "ignore", PartialEq = "ignore")]
request: Option<RequestFn>,
},
}
impl NetworkMessage {
pub fn request<F, Fut>(f: F) -> Self
where
F: FnOnce(Client) -> Fut + WasmNotSend + 'static,
Fut: Future<Output = Message> + WasmNotSend + 'static,
{
NetworkMessage::Request {
request: Some(Box::new(move |c| Box::pin(f(c)))),
}
}
}

#[cfg(not(target_family = "wasm"))]
type RequestFuture = Pin<Box<dyn Future<Output = Message> + Send>>;
#[cfg(target_family = "wasm")]
type RequestFuture = Pin<Box<dyn Future<Output = Message>>>;

#[cfg(not(target_family = "wasm"))]
type RequestFn = Box<dyn FnOnce(Client) -> RequestFuture + Send>;
#[cfg(target_family = "wasm")]
type RequestFn = Box<dyn FnOnce(Client) -> RequestFuture>;

impl Clone for NetworkMessage {
fn clone(&self) -> Self {
match self {
NetworkMessage::Request { .. } => {
log::error!("Cloning a NetworkMessage::Request is not supported");
NetworkMessage::Request { request: None }
}
}
}
}
27 changes: 27 additions & 0 deletions editor/src/messages/network/network_message_handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use crate::messages::network::utility_types::Client;
use crate::messages::prelude::*;

#[derive(ExtractField)]
pub struct NetworkMessageContext {}

#[derive(Debug, Default, ExtractField)]
pub struct NetworkMessageHandler {
client: Client,
}
#[message_handler_data]
impl MessageHandler<NetworkMessage, NetworkMessageContext> for NetworkMessageHandler {
fn process_message(&mut self, message: NetworkMessage, responses: &mut VecDeque<Message>, _context: NetworkMessageContext) {
match message {
NetworkMessage::Request { request } => {
if let Some(request) = request {
responses.add(request(self.client.clone()));
} else {
log::error!("received a empty NetworkMessage::Request");
}
}
}
}

advertise_actions!(NetworkMessageDiscriminant;
);
}
30 changes: 30 additions & 0 deletions editor/src/messages/network/utility_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use reqwest::IntoUrl;

#[derive(Debug, Clone)]
pub struct Client {
inner: Option<reqwest::Client>,
}

impl Default for Client {
fn default() -> Self {
Self {
#[cfg(not(target_family = "wasm"))]
inner: reqwest::Client::builder().timeout(std::time::Duration::from_secs(100)).build().ok(),
#[cfg(target_family = "wasm")]
inner: reqwest::Client::builder().build().ok(),
}
}
}

impl Client {
pub async fn fetch<U: IntoUrl>(&self, url: U) -> Option<Box<[u8]>> {
let Some(client) = &self.inner else {
log::error!("HTTP client failed to initialize, cannot fetch");
return None;
};
let response = client.get(url).send().await;
let response = response.and_then(|r| r.error_for_status()).map_err(|err| log::error!("failed to fetch: {err}")).ok()?;
let bytes = response.bytes().await.map_err(|err| log::error!("failed to read response body: {err}")).ok()?;
Some(bytes.to_vec().into_boxed_slice())
}
Comment thread
timon-schelling marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::messages::prelude::*;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Custom agent: PR title enforcement

PR title is not in imperative mood and lacks a leading action verb required by the PR title convention.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At editor/src/messages/portfolio/document/resource/resource_message.rs, line 2:

<comment>PR title is not in imperative mood and lacks a leading action verb required by the PR title convention.</comment>

<file context>
@@ -1,5 +1,5 @@
 use crate::messages::prelude::*;
-use graph_craft::application_io::resource::ResourceId;
+use graph_craft::application_io::resource::{DataSource, ResourceHash, ResourceId};
 use graphene_std::text::Font;
 use std::sync::Arc;
</file context>

use graph_craft::application_io::resource::ResourceId;
use graph_craft::application_io::resource::{DataSource, ResourceHash, ResourceId};
use graphene_std::text::Font;
use std::sync::Arc;

Expand All @@ -8,7 +8,8 @@ use std::sync::Arc;
pub enum ResourceMessage {
StoreEmbedded { resource_id: ResourceId, data: Arc<[u8]> },
AddFont { resource_id: ResourceId, font: Font },
Resolve,
ResolveStep { resource_id: ResourceId },
Resolved { resource_id: ResourceId, data: Arc<[u8]> },
ResolveAll,
Resolve { resource_id: ResourceId },
Resolved { resource_id: ResourceId, source: DataSource, hash: ResourceHash },
ResolveFailed { resource_id: ResourceId },
}
Loading
Loading