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 std::path::Path;
use std::env;
use std::path::Path;
#[tokio::main]
async fn main() {

View File

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

View File

@ -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::<Arc<Mutex<axum::Router>>>());
.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::<Arc<Mutex<axum::Router>>>());
// 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");
}