feat: restructure project, implement askama templating
This commit is contained in:
59
crates/tauri/src/lib.rs
Normal file
59
crates/tauri/src/lib.rs
Normal file
@ -0,0 +1,59 @@
|
||||
use core::panic;
|
||||
use std::sync::Arc;
|
||||
|
||||
use tauri::{path::BaseDirectory, Manager};
|
||||
use tokio::sync::Mutex;
|
||||
use tower::{Service, ServiceExt};
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.setup(|app| {
|
||||
let resource_path_buf = app
|
||||
.path()
|
||||
.resolve("assets", BaseDirectory::Resource)
|
||||
.expect("Path should be resolvable");
|
||||
|
||||
let router = Arc::new(Mutex::new(
|
||||
clego::get_router(resource_path_buf.as_path()).clone(),
|
||||
));
|
||||
|
||||
app.manage(router);
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.register_asynchronous_uri_scheme_protocol("axum", move |app, request, responder| {
|
||||
let router = Arc::clone(&app.state::<Arc<Mutex<axum::Router>>>());
|
||||
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let mut router = router.lock().await;
|
||||
|
||||
let (parts, body) = request.into_parts();
|
||||
let body = axum::body::Body::from(body);
|
||||
|
||||
let request = axum::extract::Request::from_parts(parts, body);
|
||||
|
||||
let response = match router.as_service().ready().await {
|
||||
Ok(ready_service) => ready_service.call(request).await,
|
||||
Err(_error) => panic!("Failed to get ready service"),
|
||||
};
|
||||
|
||||
let response = match response {
|
||||
Ok(response) => response,
|
||||
Err(_error) => panic!("Problem getting response from request."),
|
||||
};
|
||||
|
||||
let (parts, body) = response.into_parts();
|
||||
let body = match axum::body::to_bytes(body, usize::MAX).await {
|
||||
Ok(bytes) => bytes.to_vec(),
|
||||
Err(_error) => panic!("Problem converting response body to bytes."),
|
||||
};
|
||||
|
||||
let response = tauri::http::Response::from_parts(parts, body);
|
||||
|
||||
responder.respond(response);
|
||||
});
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
6
crates/tauri/src/main.rs
Normal file
6
crates/tauri/src/main.rs
Normal file
@ -0,0 +1,6 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
clego_lib::run()
|
||||
}
|
Reference in New Issue
Block a user