27 Commits

Author SHA1 Message Date
f8d7f82c50 chore: Refactor process_tauri_request function for improved readability and error handling 2024-07-24 23:39:27 +02:00
d33140ebaf chore: Improve desktop/src/lib readability 2024-07-24 23:39:02 +02:00
ba88b08a57 fix: typo in Tauri beforeDevCommand 2024-07-24 23:28:22 +02:00
8c38f0e4ba fix: remove 2 js extension on htmx file 2024-07-24 22:41:57 +02:00
648a7848fd feature: improve README.md 2024-07-24 22:35:39 +02:00
f6a1af5d1e fix: add org. to tauri identifier 2024-07-24 22:35:39 +02:00
a19b6dcd0d fix: Typo in index.html 2024-07-24 22:35:39 +02:00
9447ad7faf fix: wrong lib name 2024-07-24 22:35:14 +02:00
5eebd5d1cb fix: rename sesam-vitale and fix readme 2024-07-24 22:15:53 +02:00
7d41fbb519 fix: change project naming, create dummy sesame-vitale project 2024-07-24 21:59:24 +02:00
ff2c84fb33 fix: base assets path on the manifest dir when running the webserver manually 2024-07-24 20:36:16 +02:00
b807e78ac3 remove unecessary features 2024-07-24 15:17:47 +02:00
d8f3c276c0 feat: remove reference to clego inside tauri app 2024-07-24 15:00:14 +02:00
c2b4264f32 extract protocol logic to external function 2024-07-24 14:21:37 +02:00
0e8514d906 fix: bump dependency for clego 2024-07-24 14:08:58 +02:00
86a6d2b9d3 fix: revert back to crates dir layout 2024-07-24 11:58:03 +02:00
18758ff2fe fix: remove useless gitignore files 2024-07-24 11:23:41 +02:00
1f57b70cef feat: move packages to root and remove unused dependencies 2024-07-24 11:15:14 +02:00
83cee11e65 feat: restructure project, implement askama templating 2024-07-23 20:08:45 +02:00
b1cafda669 Merge pull request 'Feature: setup de Tauri v2 avec le routing fait par Axum' (#20) from feature-setup-tauri-v2-with-axum into main
Reviewed-on: P4Pillon/Krys4lide#20
2024-07-22 13:25:31 +02:00
d370a9b85d chore: Remove commented out code for GET method in build_axum_request 2024-07-22 13:24:11 +02:00
83b2f7358d chore: Implement clego:// protocol handler using axum router 2024-07-17 12:28:24 +02:00
8ef713ccf2 chore: setup tauri v2 2024-07-17 12:17:18 +02:00
4162e55b83 Merge pull request 'Setup initial project structure' (#1) from feature-setup-initial-project-structure into main
Reviewed-on: P4Pillon/Krys4lide#1
2024-07-07 14:19:45 +02:00
d9cedca335 fixup! chore: Setup clego sub project 2024-07-06 20:04:56 +02:00
820d76d0f5 chore: Setup clego sub project 2024-07-05 16:15:49 +02:00
6409e3eedf chore: Initialize cargo workspace members 2024-07-04 12:12:12 +02:00
40 changed files with 4859 additions and 5 deletions

15
.gitignore vendored
View File

@ -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?

4522
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

7
Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[workspace]
resolver = "2"
members = [
"crates/app",
"crates/sesam-vitale",
"crates/desktop"
]

View File

@ -1,3 +1,39 @@
# Krys4lide # Krys4lide
Logiciel de pharmacie Logiciel de Pharmacie libre et open-source.
## Crates
- `app`: Interface du logiciel, servie par un serveur web propulsé par Axum. Utilisable en mode endpoint ou encapsulé dans le client `desktop`
- `desktop`: Client desktop propulsé par Tauri, encapsulant le serveur web `app`
- `sesam-vitale`: Bibliothèque de gestion des services SESAM-Vitale (Lecture des cartes CPS et Vitale, téléservices ...)
## Development
### Pré-requis
La CLI Tauri est nécessaire au lancement du client `desktop`. Elle peut être installée via Cargo :
```bash
cargo install tauri-cli
```
### Exécution de l'application cliente desktop
```bash
cargo tauri dev
```
### Exécution du serveur web `app` en mode endpoint
```bash
cargo run --bin app
```
## Build
Packager le client desktop
```bash
cargo tauri build
```

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

@ -0,0 +1 @@
/target

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

@ -0,0 +1,12 @@
[package]
name = "app"
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/app/assets/js/htmx.min.js vendored Normal file

File diff suppressed because one or more lines are too long

27
crates/app/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
}

14
crates/app/src/main.rs Normal file
View File

@ -0,0 +1,14 @@
use ::app::get_router;
use std::path::Path;
use std::env;
#[tokio::main]
async fn main() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let assets_path = Path::new(&manifest_dir).join("assets");
let router = get_router(assets_path.as_path());
// 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"></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 %}Pharma 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/desktop/.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/desktop/Cargo.toml Normal file
View File

@ -0,0 +1,22 @@
[package]
name = "desktop"
version = "0.1.0"
description = "Un logiciel de pharmacie libre et open-source."
authors = ["p4pillon"]
edition = "2021"
[lib]
name = "desktop_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 = [] }
tower = "0.4.13"
tokio = "1.39.1"
app = { path = "../app" }

3
crates/desktop/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.

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

77
crates/desktop/src/lib.rs Normal file
View File

@ -0,0 +1,77 @@
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::extract::Request as AxumRequest;
use tokio::sync::{Mutex, MutexGuard};
use tower::{Service, ServiceExt};
async fn process_tauri_request(
request: TauriRequest<Vec<u8>>,
mut router: MutexGuard<'_, axum::Router>,
) -> TauriResponse<Vec<u8>> {
// Convert the Tauri request to an Axum request
let (parts, body) = request.into_parts();
let body = AxumBody::from(body);
let request = AxumRequest::from_parts(parts, body);
// Process the request with the router
let response = router
.as_service()
.ready().await
.expect("Failed to get ready service")
.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
.expect("Failed to convert body to bytes")
.to_vec();
let response = TauriResponse::from_parts(parts, body);
response
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.setup(|app| {
let assets_path = app
.path()
.resolve("assets", BaseDirectory::Resource)
.expect("Path should be resolvable");
// 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(),
));
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>>>());
// 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");
}

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() {
desktop_lib::run()
}

View File

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

View File

@ -0,0 +1,6 @@
[package]
name = "sesam-vitale"
version = "0.1.0"
edition = "2021"
[dependencies]

View File

@ -0,0 +1,14 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}

0
scripts/.gitkeep Normal file
View File