Compare commits
13 Commits
wip-debug-
...
0e8514d906
Author | SHA1 | Date | |
---|---|---|---|
0e8514d906 | |||
86a6d2b9d3 | |||
18758ff2fe | |||
1f57b70cef | |||
83cee11e65 | |||
b1cafda669 | |||
d370a9b85d
|
|||
83b2f7358d
|
|||
8ef713ccf2
|
|||
4162e55b83 | |||
d9cedca335
|
|||
820d76d0f5
|
|||
6409e3eedf
|
15
.gitignore
vendored
@ -4,13 +4,20 @@
|
|||||||
debug/
|
debug/
|
||||||
target/
|
target/
|
||||||
|
|
||||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
|
||||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
|
||||||
Cargo.lock
|
|
||||||
|
|
||||||
# These are backup files generated by rustfmt
|
# These are backup files generated by rustfmt
|
||||||
**/*.rs.bk
|
**/*.rs.bk
|
||||||
|
|
||||||
# MSVC Windows builds of rustc generate these, which store debugging information
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
*.pdb
|
*.pdb
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
|
|
||||||
|
4518
Cargo.lock
generated
Normal file
6
Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[workspace]
|
||||||
|
resolver = "2"
|
||||||
|
members = [
|
||||||
|
"crates/clego",
|
||||||
|
"crates/tauri"
|
||||||
|
]
|
33
README.md
@ -1,3 +1,34 @@
|
|||||||
# Krys4lide
|
# Krys4lide
|
||||||
|
|
||||||
Logiciel de pharmacie
|
Logiciel de Pharmacie libre et open-source.
|
||||||
|
|
||||||
|
## Crates
|
||||||
|
|
||||||
|
- `clego`: Axum backend lib for tauri client. Can be used as a lib or started as a web server.
|
||||||
|
- `tauri`: Tauri app for desktop client.
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
Install
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo install tauri-cli
|
||||||
|
```
|
||||||
|
|
||||||
|
Run desktop client app
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo tauri dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Run clego endpoint
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo run --bin clego
|
||||||
|
```
|
||||||
|
|
||||||
|
Bundle desktop client app
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo tauri build
|
||||||
|
```
|
||||||
|
1
crates/clego/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/target
|
12
crates/clego/Cargo.toml
Normal 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.39.1", features = ["macros", "rt-multi-thread"] }
|
||||||
|
tower-http = { version = "0.5.2", features = ["fs"] }
|
||||||
|
|
1
crates/clego/assets/js/htmx.min.js.js
Normal file
27
crates/clego/src/lib.rs
Normal 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
@ -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();
|
||||||
|
}
|
7
crates/clego/src/templates/hello.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
use askama::Template;
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "hello.html")]
|
||||||
|
pub struct HelloResponse {
|
||||||
|
pub name: String,
|
||||||
|
}
|
5
crates/clego/src/templates/index.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
use askama::Template;
|
||||||
|
|
||||||
|
#[derive(Template)]
|
||||||
|
#[template(path = "index.html")]
|
||||||
|
pub struct GetIndexResponse;
|
2
crates/clego/src/templates/mod.rs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pub mod index;
|
||||||
|
pub mod hello;
|
13
crates/clego/templates/base.html
Normal 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>
|
1
crates/clego/templates/hello.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
<div>Hello {{name}}!</div>
|
23
crates/clego/templates/index.html
Normal 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
@ -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
@ -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
@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
tauri_build::build()
|
||||||
|
}
|
BIN
crates/tauri/icons/128x128.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
crates/tauri/icons/128x128@2x.png
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
crates/tauri/icons/32x32.png
Normal file
After Width: | Height: | Size: 974 B |
BIN
crates/tauri/icons/Square107x107Logo.png
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
crates/tauri/icons/Square142x142Logo.png
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
crates/tauri/icons/Square150x150Logo.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
BIN
crates/tauri/icons/Square284x284Logo.png
Normal file
After Width: | Height: | Size: 7.6 KiB |
BIN
crates/tauri/icons/Square30x30Logo.png
Normal file
After Width: | Height: | Size: 903 B |
BIN
crates/tauri/icons/Square310x310Logo.png
Normal file
After Width: | Height: | Size: 8.4 KiB |
BIN
crates/tauri/icons/Square44x44Logo.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
crates/tauri/icons/Square71x71Logo.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
BIN
crates/tauri/icons/Square89x89Logo.png
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
crates/tauri/icons/StoreLogo.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
crates/tauri/icons/icon.icns
Normal file
BIN
crates/tauri/icons/icon.ico
Normal file
After Width: | Height: | Size: 85 KiB |
BIN
crates/tauri/icons/icon.png
Normal file
After Width: | Height: | Size: 14 KiB |
62
crates/tauri/src/lib.rs
Normal 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
@ -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()
|
||||||
|
}
|
41
crates/tauri/tauri.conf.json
Normal 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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|