fix: revert back to crates dir layout

This commit is contained in:
theo
2024-07-24 11:58:03 +02:00
parent 18758ff2fe
commit 86a6d2b9d3
35 changed files with 31 additions and 48 deletions

1
crates/clego/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

12
crates/clego/Cargo.toml Normal file
View File

@ -0,0 +1,12 @@
[package]
name = "clego"
version = "0.1.0"
edition = "2021"
[dependencies]
askama = "0.12.1"
askama_axum = "0.4.0"
axum = "0.7.5"
tokio = { version = "1.38.1", features = ["macros", "rt-multi-thread"] }
tower-http = { version = "0.5.2", features = ["fs"] }

File diff suppressed because one or more lines are too long

27
crates/clego/src/lib.rs Normal file
View File

@ -0,0 +1,27 @@
mod templates;
use std::path::Path;
use askama_axum::IntoResponse;
use templates::{hello::HelloResponse, index::GetIndexResponse};
use tower_http::services::ServeDir;
async fn root() -> impl IntoResponse {
return GetIndexResponse {}.into_response();
}
async fn hello() -> impl IntoResponse {
return HelloResponse {
name: "Theo".to_string(),
}
.into_response();
}
pub fn get_router(assets_path: &Path) -> axum::Router {
let router = axum::Router::new()
.nest_service("/assets", ServeDir::new(assets_path))
.route("/", axum::routing::get(root))
.route("/hello", axum::routing::get(hello));
router
}

11
crates/clego/src/main.rs Normal file
View File

@ -0,0 +1,11 @@
use ::clego::get_router;
use std::path::Path;
#[tokio::main]
async fn main() {
let router = get_router(Path::new("/assets"));
// TODO: select port based on available port (or ask in CLI)
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, router).await.unwrap();
}

View File

@ -0,0 +1,7 @@
use askama::Template;
#[derive(Template)]
#[template(path = "hello.html")]
pub struct HelloResponse {
pub name: String,
}

View File

@ -0,0 +1,5 @@
use askama::Template;
#[derive(Template)]
#[template(path = "index.html")]
pub struct GetIndexResponse;

View File

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

View File

@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<title>{% block title %}{{ title }}{% endblock %}</title>
<script src="/assets/js/htmx.min.js.js"></script>
{% block head %}{% endblock %}
</head>
<body>
{% block body %}{% endblock %}
</body>
</html>

View File

@ -0,0 +1 @@
<div>Hello {{name}}!</div>

View File

@ -0,0 +1,23 @@
{% extends "base.html" %}
{% block title %}Phrama Libre{% endblock %}
{% block body %}
<div>
<header>
<h1>Pharma Libre</h1>
</header>
<main>
<div
id="hello"
hx-get="/hello"
hx-target="this"
hx-trigger="load"
hx-swap="outerHTML"
>
Loading...
</div>
</main>
</div>
{% endblock %}

7
crates/tauri/.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
# Generated by Cargo
# will have compiled files and executables
/target/
# Generated by Tauri
# will have schema files for capabilities auto-completion
/gen/schemas

22
crates/tauri/Cargo.toml Normal file
View File

@ -0,0 +1,22 @@
[package]
name = "tauri-clego"
version = "0.1.0"
description = "Un logiciel de pharmacie libre et open-source."
authors = ["p4pillon"]
edition = "2021"
[lib]
name = "clego_lib"
crate-type = ["lib", "cdylib", "staticlib"]
[build-dependencies]
tauri-build = { version = "2.0.0-beta", features = [] }
[dependencies]
axum = "0.7.5"
tauri = { version = "2.0.0-beta", features = ["devtools"] }
tower = "0.4.13"
clego = { path = "../clego" }
tokio = "1.39.1"

3
crates/tauri/build.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

BIN
crates/tauri/icons/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

BIN
crates/tauri/icons/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

62
crates/tauri/src/lib.rs Normal file
View File

@ -0,0 +1,62 @@
use core::panic;
use std::sync::Arc;
use tauri::{path::BaseDirectory, Manager};
use tokio::sync::Mutex;
use tower::{Service, ServiceExt};
async fn process_tauri_request(request: tauri::http::Request<>, router: axum:Router ){
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);
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.setup(|app| {
// Create a router and adds it the the app state
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;
responder.respond(response);
});
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

6
crates/tauri/src/main.rs Normal file
View 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()
}

View File

@ -0,0 +1,41 @@
{
"productName": "clego-clean",
"version": "0.0.1",
"identifier": "clego.pharma.libre",
"build": {
"beforeDevCommand": {
"script": "cargo run",
"cwd": "../clego"
},
"devUrl": "http://localhost:3000",
"frontendDist": "axum://place.holder/"
},
"app": {
"withGlobalTauri": true,
"windows": [
{
"title": "clego-clean",
"width": 800,
"height": 600
}
],
"security": {
"csp": null
}
},
"bundle": {
"active": true,
"resources": {
"../clego/assets/": "./assets/"
},
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
}
}