Compare commits
No commits in common. "d8f3c276c049ceb981a276a212c64f43202767e2" and "0e8514d90605d4a8c18c513503cbba57622a59ed" have entirely different histories.
d8f3c276c0
...
0e8514d906
24
Cargo.lock
generated
24
Cargo.lock
generated
@ -2161,18 +2161,6 @@ version = "2.3.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pharmacie-desktop"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"axum",
|
|
||||||
"clego",
|
|
||||||
"tauri",
|
|
||||||
"tauri-build",
|
|
||||||
"tokio",
|
|
||||||
"tower",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "phf"
|
name = "phf"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
@ -3257,6 +3245,18 @@ dependencies = [
|
|||||||
"walkdir",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tauri-clego"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"axum",
|
||||||
|
"clego",
|
||||||
|
"tauri",
|
||||||
|
"tauri-build",
|
||||||
|
"tokio",
|
||||||
|
"tower",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-codegen"
|
name = "tauri-codegen"
|
||||||
version = "2.0.0-beta.19"
|
version = "2.0.0-beta.19"
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "pharmacie-desktop"
|
name = "tauri-clego"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
description = "Un logiciel de pharmacie libre et open-source."
|
description = "Un logiciel de pharmacie libre et open-source."
|
||||||
authors = ["p4pillon"]
|
authors = ["p4pillon"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "pharmacie_desktop_lib"
|
name = "clego_lib"
|
||||||
crate-type = ["lib", "cdylib", "staticlib"]
|
crate-type = ["lib", "cdylib", "staticlib"]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
@ -2,43 +2,40 @@ use core::panic;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use tauri::{path::BaseDirectory, Manager};
|
use tauri::{path::BaseDirectory, Manager};
|
||||||
use tokio::sync::{Mutex, MutexGuard};
|
use tokio::sync::Mutex;
|
||||||
use tower::{Service, ServiceExt};
|
use tower::{Service, ServiceExt};
|
||||||
|
|
||||||
async fn process_tauri_request(
|
async fn process_tauri_request(request: tauri::http::Request<>, router: axum:Router ){
|
||||||
request: tauri::http::Request<Vec<u8>>,
|
let (parts, body) = request.into_parts();
|
||||||
mut router: MutexGuard<'_, axum::Router>,
|
let body = axum::body::Body::from(body);
|
||||||
) -> tauri::http::Response<Vec<u8>> {
|
|
||||||
let (parts, body) = request.into_parts();
|
|
||||||
let body = axum::body::Body::from(body);
|
|
||||||
|
|
||||||
let request = axum::extract::Request::from_parts(parts, body);
|
let request = axum::extract::Request::from_parts(parts, body);
|
||||||
|
|
||||||
let response = match router.as_service().ready().await {
|
let response = match router.as_service().ready().await {
|
||||||
Ok(ready_service) => ready_service.call(request).await,
|
Ok(ready_service) => ready_service.call(request).await,
|
||||||
Err(_error) => panic!("Failed to get ready service"),
|
Err(_error) => panic!("Failed to get ready service"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let response = match response {
|
let response = match response {
|
||||||
Ok(response) => response,
|
Ok(response) => response,
|
||||||
Err(_error) => panic!("Problem getting response from request."),
|
Err(_error) => panic!("Problem getting response from request."),
|
||||||
};
|
};
|
||||||
|
|
||||||
let (parts, body) = response.into_parts();
|
let (parts, body) = response.into_parts();
|
||||||
let body = match axum::body::to_bytes(body, usize::MAX).await {
|
let body = match axum::body::to_bytes(body, usize::MAX).await {
|
||||||
Ok(bytes) => bytes.to_vec(),
|
Ok(bytes) => bytes.to_vec(),
|
||||||
Err(_error) => panic!("Problem converting response body to bytes."),
|
Err(_error) => panic!("Problem converting response body to bytes."),
|
||||||
};
|
};
|
||||||
|
|
||||||
let response = tauri::http::Response::from_parts(parts, body);
|
let response = tauri::http::Response::from_parts(parts, body);
|
||||||
|
|
||||||
response
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
|
// Create a router and adds it the the app state
|
||||||
|
|
||||||
let resource_path_buf = app
|
let resource_path_buf = app
|
||||||
.path()
|
.path()
|
||||||
.resolve("assets", BaseDirectory::Resource)
|
.resolve("assets", BaseDirectory::Resource)
|
||||||
@ -48,8 +45,6 @@ pub fn run() {
|
|||||||
clego::get_router(resource_path_buf.as_path()).clone(),
|
clego::get_router(resource_path_buf.as_path()).clone(),
|
||||||
));
|
));
|
||||||
|
|
||||||
// Adds the router to the application state
|
|
||||||
// This makes it so we can retrieve it from any app instance (see bellow)
|
|
||||||
app.manage(router);
|
app.manage(router);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -58,10 +53,7 @@ pub fn run() {
|
|||||||
let router = Arc::clone(&app.state::<Arc<Mutex<axum::Router>>>());
|
let router = Arc::clone(&app.state::<Arc<Mutex<axum::Router>>>());
|
||||||
|
|
||||||
tauri::async_runtime::spawn(async move {
|
tauri::async_runtime::spawn(async move {
|
||||||
let router = router.lock().await;
|
let mut router = router.lock().await;
|
||||||
|
|
||||||
let response = process_tauri_request(request, router).await;
|
|
||||||
|
|
||||||
responder.respond(response);
|
responder.respond(response);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -2,5 +2,5 @@
|
|||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
pharmacie_desktop_lib::run()
|
clego_lib::run()
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"productName": "Logiciel Pharma",
|
"productName": "clego-clean",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"identifier": "p4pillon.pharma.desktop",
|
"identifier": "clego.pharma.libre",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": {
|
"beforeDevCommand": {
|
||||||
"script": "cargo run",
|
"script": "cargo run",
|
||||||
@ -14,7 +14,7 @@
|
|||||||
"withGlobalTauri": true,
|
"withGlobalTauri": true,
|
||||||
"windows": [
|
"windows": [
|
||||||
{
|
{
|
||||||
"title": "Logiciel Pharma",
|
"title": "clego-clean",
|
||||||
"width": 800,
|
"width": 800,
|
||||||
"height": 600
|
"height": 600
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user