(input: web::Json<RunInput>)
| 30 | tauri: AppHandle, |
| 31 | } |
| 32 | |
| 33 | #[derive(Deserialize)] |
| 34 | struct RunInput { |
| 35 | slug: String, |
| 36 | } |
| 37 | |
| 38 | #[post("/run")] |
| 39 | async fn run(input: web::Json<RunInput>) -> HttpResponse { |
| 40 | let slug = input.slug.clone(); |
| 41 | log::info!("Opening stack file: {:#?}", slug); |
| 42 | println!("Running {}!", slug); |
| 43 | |
| 44 | // Create a channel for streaming output |
| 45 | let (tx, mut rx) = tokio::sync::mpsc::channel(100); |
| 46 | |
| 47 | // Spawn the CLI command in a separate task |
| 48 | tokio::spawn(async move { |
| 49 | let output_callback = Box::new(move |line: String| { |
| 50 | let tx = tx.clone(); |
| 51 | tokio::spawn(async move { |
| 52 | let _ = tx.send(line).await; |
| 53 | }); |
| 54 | }); |
| 55 | |
| 56 | cli::run_with_callback(&slug, output_callback).await; |
| 57 | }); |
| 58 | |
| 59 | // Create a streaming response |
| 60 | HttpResponse::Ok() |
| 61 | .content_type("text/event-stream") |
| 62 | .streaming(Box::pin(async_stream::stream! { |
| 63 | while let Some(line) = rx.recv().await { |
nothing calls this directly
no test coverage detected