chore: run cargo fmt

This commit is contained in:
theo 2024-07-25 09:21:17 +02:00
parent f8d7f82c50
commit 65059b87d4
No known key found for this signature in database
3 changed files with 22 additions and 30 deletions

View File

@ -1,6 +1,6 @@
use ::app::get_router; use ::app::get_router;
use std::path::Path;
use std::env; use std::env;
use std::path::Path;
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {

View File

@ -1,2 +1,2 @@
pub mod index;
pub mod hello; pub mod hello;
pub mod index;

View File

@ -1,15 +1,9 @@
use std::sync::Arc; use std::sync::Arc;
use tauri::{path::BaseDirectory, Manager}; use axum::body::{to_bytes, Body as AxumBody};
use tauri::http::{
Request as TauriRequest,
Response as TauriResponse,
};
use axum::body::{
Body as AxumBody,
to_bytes,
};
use axum::extract::Request as AxumRequest; 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 tokio::sync::{Mutex, MutexGuard};
use tower::{Service, ServiceExt}; use tower::{Service, ServiceExt};
@ -25,14 +19,17 @@ async fn process_tauri_request(
// Process the request with the router // Process the request with the router
let response = router let response = router
.as_service() .as_service()
.ready().await .ready()
.await
.expect("Failed to get ready service") .expect("Failed to get ready service")
.call(request).await .call(request)
.await
.expect("Failed to get response from router"); .expect("Failed to get response from router");
// Convert the Axum response to a Tauri response // Convert the Axum response to a Tauri response
let (parts, body) = response.into_parts(); 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") .expect("Failed to convert body to bytes")
.to_vec(); .to_vec();
let response = TauriResponse::from_parts(parts, body); let response = TauriResponse::from_parts(parts, body);
@ -51,16 +48,12 @@ pub fn run() {
// Adds the router to the application state // Adds the router to the application state
// This makes it so we can retrieve it from any app instance (see bellow) // This makes it so we can retrieve it from any app instance (see bellow)
let router = Arc::new(Mutex::new( let router = Arc::new(Mutex::new(app::get_router(assets_path.as_path()).clone()));
app::get_router(assets_path.as_path()).clone(),
));
app.manage(router); app.manage(router);
Ok(()) Ok(())
}) })
.register_asynchronous_uri_scheme_protocol( .register_asynchronous_uri_scheme_protocol("axum", move |app, request, responder| {
"axum",
move |app, request, responder| {
// Retrieve the router from the application state and clone it for the async block // Retrieve the router from the application state and clone it for the async block
let router = Arc::clone(&app.state::<Arc<Mutex<axum::Router>>>()); let router = Arc::clone(&app.state::<Arc<Mutex<axum::Router>>>());
@ -70,8 +63,7 @@ pub fn run() {
let response = process_tauri_request(request, router).await; let response = process_tauri_request(request, router).await;
responder.respond(response); responder.respond(response);
}); });
} })
)
.run(tauri::generate_context!()) .run(tauri::generate_context!())
.expect("error while running tauri application"); .expect("error while running tauri application");
} }