feat: restructure project, implement askama templating #26

Merged
theo merged 21 commits from restructure-project into main 2024-07-26 14:42:03 +02:00
3 changed files with 22 additions and 30 deletions
Showing only changes of commit 65059b87d4 - Show all commits

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,16 +48,12 @@ 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| {
.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>>>());
@ -70,8 +63,7 @@ pub fn run() {
let response = process_tauri_request(request, router).await;
responder.respond(response);
});
}
)
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}