From 95a6ae47468790baf8f59202c629bb7fa6aedcd2 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Thu, 7 Aug 2025 10:28:39 -0400 Subject: [PATCH] fields for frontend events --- .../enqueue_image_bg_removal_command.rs | 16 +++++++++- .../enqueue_image_inpaint_command.rs | 16 +++++++++- .../commands/enqueue/task_enqueue_success.rs | 32 ++++++++++--------- 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/crates/desktop/artcraft/src/core/commands/enqueue/image_bg_removal/enqueue_image_bg_removal_command.rs b/crates/desktop/artcraft/src/core/commands/enqueue/image_bg_removal/enqueue_image_bg_removal_command.rs index 8e1d630e79..7de058387f 100644 --- a/crates/desktop/artcraft/src/core/commands/enqueue/image_bg_removal/enqueue_image_bg_removal_command.rs +++ b/crates/desktop/artcraft/src/core/commands/enqueue/image_bg_removal/enqueue_image_bg_removal_command.rs @@ -55,6 +55,16 @@ pub struct EnqueueImageBgRemovalCommand { /// Base64-encoded image pub base64_image: Option, + + /// OPTIONAL. + /// A frontend-defined identifier that we'll send back to the frontend + /// as a Tauri event on task completion. + pub frontend_subscriber_id: Option, + + /// OPTIONAL. + /// A frontend-defined payload that we'll send back to the frontend + /// as a Tauri event on task completion. + pub frontend_subscriber_payload: Option, } #[derive(Serialize, Debug)] @@ -169,7 +179,11 @@ pub async fn handle_request( ).await?; let result = success_event - .insert_into_task_database(task_database) + .insert_into_task_database_with_frontend_payload( + task_database, + request.frontend_subscriber_id.as_deref(), + request.frontend_subscriber_payload.as_deref() + ) .await; if let Err(err) = result { diff --git a/crates/desktop/artcraft/src/core/commands/enqueue/image_inpaint/enqueue_image_inpaint_command.rs b/crates/desktop/artcraft/src/core/commands/enqueue/image_inpaint/enqueue_image_inpaint_command.rs index 78d5e749a8..be27f37c83 100644 --- a/crates/desktop/artcraft/src/core/commands/enqueue/image_inpaint/enqueue_image_inpaint_command.rs +++ b/crates/desktop/artcraft/src/core/commands/enqueue/image_inpaint/enqueue_image_inpaint_command.rs @@ -80,6 +80,16 @@ pub struct EnqueueInpaintImageCommand { /// If true, force the dimensions of the source image and mask image to match. pub require_matching_dimensions: Option, + + /// OPTIONAL. + /// A frontend-defined identifier that we'll send back to the frontend + /// as a Tauri event on task completion. + pub frontend_subscriber_id: Option, + + /// OPTIONAL. + /// A frontend-defined payload that we'll send back to the frontend + /// as a Tauri event on task completion. + pub frontend_subscriber_payload: Option, } #[derive(Serialize, Debug)] @@ -216,7 +226,11 @@ pub async fn handle_request( }; let result = success_event - .insert_into_task_database(task_database) + .insert_into_task_database_with_frontend_payload( + task_database, + request.frontend_subscriber_id.as_deref(), + request.frontend_subscriber_payload.as_deref() + ) .await; if let Err(err) = result { diff --git a/crates/desktop/artcraft/src/core/commands/enqueue/task_enqueue_success.rs b/crates/desktop/artcraft/src/core/commands/enqueue/task_enqueue_success.rs index 204905cc17..44a17efa2c 100644 --- a/crates/desktop/artcraft/src/core/commands/enqueue/task_enqueue_success.rs +++ b/crates/desktop/artcraft/src/core/commands/enqueue/task_enqueue_success.rs @@ -35,6 +35,20 @@ impl TaskEnqueueSuccess{ } pub async fn insert_into_task_database(&self, task_database: &TaskDatabase) -> Result { + self.insert_into_task_database_with_frontend_payload( + task_database, + None, + None, + ).await + } + + // TODO: This belongs somewhere else, not as a method of an event struct. + pub async fn insert_into_task_database_with_frontend_payload( + &self, + task_database: &TaskDatabase, + frontend_subscriber_id: Option<&str>, + frontend_subscriber_payload: Option<&str>, + ) -> Result { // TODO: Move this mapping elsewhere, or remove the other models. let model_type = match self.model { None => None, @@ -63,23 +77,11 @@ impl TaskEnqueueSuccess{ db: task_database.get_connection(), status: TaskStatus::Pending, task_type: self.task_type, - model_type: model_type, + model_type, provider: self.provider, provider_job_id: self.provider_job_id.as_deref(), - frontend_subscriber_id: None, - frontend_subscriber_payload: None, + frontend_subscriber_id, + frontend_subscriber_payload, }).await } - -// pub fn tauri_event_model(&self) -> GenerationModel { -// match self.model { -// ImageModel::Flux1Dev => GenerationModel::Flux1Dev, -// ImageModel::Flux1Schnell => GenerationModel::Flux1Schnell, -// ImageModel::FluxPro11 => GenerationModel::FluxPro11, -// ImageModel::FluxPro11Ultra => GenerationModel::FluxPro11Ultra, -// ImageModel::GptImage1 => GenerationModel::GptImage1, -// ImageModel::Recraft3 => GenerationModel::Recraft3, -// } -// } - } \ No newline at end of file