From 65059b87d4f61f4450ad96110d4c9af9f854c664 Mon Sep 17 00:00:00 2001 From: theo Date: Thu, 25 Jul 2024 09:21:17 +0200 Subject: [PATCH] chore: run cargo fmt --- crates/app/src/main.rs | 2 +- crates/app/src/templates/mod.rs | 2 +- crates/desktop/src/lib.rs | 48 ++++++++++++++------------------- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 6d2d784..0f11472 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -1,6 +1,6 @@ use ::app::get_router; +use std::env; use std::path::Path; -use std::env; #[tokio::main] async fn main() { diff --git a/crates/app/src/templates/mod.rs b/crates/app/src/templates/mod.rs index 3f635aa..bb7cbb8 100644 --- a/crates/app/src/templates/mod.rs +++ b/crates/app/src/templates/mod.rs @@ -1,2 +1,2 @@ -pub mod index; pub mod hello; +pub mod index; diff --git a/crates/desktop/src/lib.rs b/crates/desktop/src/lib.rs index daa8cd9..09e2db9 100644 --- a/crates/desktop/src/lib.rs +++ b/crates/desktop/src/lib.rs @@ -1,15 +1,9 @@ use std::sync::Arc; -use tauri::{path::BaseDirectory, Manager}; -use tauri::http::{ - Request as TauriRequest, - Response as TauriResponse, -}; -use axum::body::{ - Body as AxumBody, - to_bytes, -}; +use axum::body::{to_bytes, Body as AxumBody}; use axum::extract::Request as AxumRequest; +use tauri::http::{Request as TauriRequest, Response as TauriResponse}; +use tauri::{path::BaseDirectory, Manager}; use tokio::sync::{Mutex, MutexGuard}; use tower::{Service, ServiceExt}; @@ -25,14 +19,17 @@ async fn process_tauri_request( // Process the request with the router let response = router .as_service() - .ready().await + .ready() + .await .expect("Failed to get ready service") - .call(request).await + .call(request) + .await .expect("Failed to get response from router"); // Convert the Axum response to a Tauri response let (parts, body) = response.into_parts(); - let body = to_bytes(body, usize::MAX).await + let body = to_bytes(body, usize::MAX) + .await .expect("Failed to convert body to bytes") .to_vec(); let response = TauriResponse::from_parts(parts, body); @@ -51,27 +48,22 @@ pub fn run() { // Adds the router to the application state // This makes it so we can retrieve it from any app instance (see bellow) - let router = Arc::new(Mutex::new( - app::get_router(assets_path.as_path()).clone(), - )); + let router = Arc::new(Mutex::new(app::get_router(assets_path.as_path()).clone())); app.manage(router); Ok(()) }) - .register_asynchronous_uri_scheme_protocol( - "axum", - move |app, request, responder| { - // Retrieve the router from the application state and clone it for the async block - let router = Arc::clone(&app.state::>>()); + .register_asynchronous_uri_scheme_protocol("axum", move |app, request, responder| { + // Retrieve the router from the application state and clone it for the async block + let router = Arc::clone(&app.state::>>()); - // Spawn a new async task to process the request - tauri::async_runtime::spawn(async move { - let router = router.lock().await; - let response = process_tauri_request(request, router).await; - responder.respond(response); - }); - } - ) + // Spawn a new async task to process the request + tauri::async_runtime::spawn(async move { + let router = router.lock().await; + let response = process_tauri_request(request, router).await; + responder.respond(response); + }); + }) .run(tauri::generate_context!()) .expect("error while running tauri application"); }