From 83cee11e65845db4a2d3fa29617455d5e51578f0 Mon Sep 17 00:00:00 2001 From: "t.lettermann" Date: Tue, 23 Jul 2024 20:08:45 +0200 Subject: [PATCH 01/21] feat: restructure project, implement askama templating --- .gitignore | 28 +- Cargo.lock | 479 ++++++++++-------- Cargo.toml | 8 +- README.md | 33 +- clego/Cargo.toml | 6 - clego/src/main.rs | 3 - crates/clego/.gitignore | 1 + crates/clego/Cargo.toml | 12 + crates/clego/assets/js/htmx.min.js.js | 1 + crates/clego/src/lib.rs | 27 + crates/clego/src/main.rs | 11 + crates/clego/src/templates/hello.rs | 7 + crates/clego/src/templates/index.rs | 5 + crates/clego/src/templates/mod.rs | 2 + crates/clego/templates/base.html | 13 + crates/clego/templates/hello.html | 1 + crates/clego/templates/index.html | 23 + {tauri/src-tauri => crates/tauri}/.gitignore | 0 crates/tauri/Cargo.toml | 23 + {tauri/src-tauri => crates/tauri}/build.rs | 0 .../tauri}/icons/128x128.png | Bin .../tauri}/icons/128x128@2x.png | Bin .../tauri}/icons/32x32.png | Bin .../tauri}/icons/Square107x107Logo.png | Bin .../tauri}/icons/Square142x142Logo.png | Bin .../tauri}/icons/Square150x150Logo.png | Bin .../tauri}/icons/Square284x284Logo.png | Bin .../tauri}/icons/Square30x30Logo.png | Bin .../tauri}/icons/Square310x310Logo.png | Bin .../tauri}/icons/Square44x44Logo.png | Bin .../tauri}/icons/Square71x71Logo.png | Bin .../tauri}/icons/Square89x89Logo.png | Bin .../tauri}/icons/StoreLogo.png | Bin .../tauri}/icons/icon.icns | Bin .../src-tauri => crates/tauri}/icons/icon.ico | Bin .../src-tauri => crates/tauri}/icons/icon.png | Bin crates/tauri/src/lib.rs | 59 +++ crates/tauri/src/main.rs | 6 + .../tauri}/tauri.conf.json | 19 +- scripts/.gitkeep | 0 tauri/.gitignore | 24 - tauri/README.md | 7 - tauri/src-tauri/Cargo.toml | 21 - tauri/src-tauri/capabilities/default.json | 17 - tauri/src-tauri/src/main.rs | 90 ---- tauri/src/assets/javascript.svg | 1 - tauri/src/assets/tauri.svg | 6 - tauri/src/index.html | 45 -- tauri/src/main.js | 18 - tauri/src/styles.css | 112 ---- 50 files changed, 536 insertions(+), 572 deletions(-) delete mode 100644 clego/Cargo.toml delete mode 100644 clego/src/main.rs create mode 100644 crates/clego/.gitignore create mode 100644 crates/clego/Cargo.toml create mode 100644 crates/clego/assets/js/htmx.min.js.js create mode 100644 crates/clego/src/lib.rs create mode 100644 crates/clego/src/main.rs create mode 100644 crates/clego/src/templates/hello.rs create mode 100644 crates/clego/src/templates/index.rs create mode 100644 crates/clego/src/templates/mod.rs create mode 100644 crates/clego/templates/base.html create mode 100644 crates/clego/templates/hello.html create mode 100644 crates/clego/templates/index.html rename {tauri/src-tauri => crates/tauri}/.gitignore (100%) create mode 100644 crates/tauri/Cargo.toml rename {tauri/src-tauri => crates/tauri}/build.rs (100%) rename {tauri/src-tauri => crates/tauri}/icons/128x128.png (100%) rename {tauri/src-tauri => crates/tauri}/icons/128x128@2x.png (100%) rename {tauri/src-tauri => crates/tauri}/icons/32x32.png (100%) rename {tauri/src-tauri => crates/tauri}/icons/Square107x107Logo.png (100%) rename {tauri/src-tauri => crates/tauri}/icons/Square142x142Logo.png (100%) rename {tauri/src-tauri => crates/tauri}/icons/Square150x150Logo.png (100%) rename {tauri/src-tauri => crates/tauri}/icons/Square284x284Logo.png (100%) rename {tauri/src-tauri => crates/tauri}/icons/Square30x30Logo.png (100%) rename {tauri/src-tauri => crates/tauri}/icons/Square310x310Logo.png (100%) rename {tauri/src-tauri => crates/tauri}/icons/Square44x44Logo.png (100%) rename {tauri/src-tauri => crates/tauri}/icons/Square71x71Logo.png (100%) rename {tauri/src-tauri => crates/tauri}/icons/Square89x89Logo.png (100%) rename {tauri/src-tauri => crates/tauri}/icons/StoreLogo.png (100%) rename {tauri/src-tauri => crates/tauri}/icons/icon.icns (100%) rename {tauri/src-tauri => crates/tauri}/icons/icon.ico (100%) rename {tauri/src-tauri => crates/tauri}/icons/icon.png (100%) create mode 100644 crates/tauri/src/lib.rs create mode 100644 crates/tauri/src/main.rs rename {tauri/src-tauri => crates/tauri}/tauri.conf.json (51%) create mode 100644 scripts/.gitkeep delete mode 100644 tauri/.gitignore delete mode 100644 tauri/README.md delete mode 100644 tauri/src-tauri/Cargo.toml delete mode 100644 tauri/src-tauri/capabilities/default.json delete mode 100644 tauri/src-tauri/src/main.rs delete mode 100644 tauri/src/assets/javascript.svg delete mode 100644 tauri/src/assets/tauri.svg delete mode 100644 tauri/src/index.html delete mode 100644 tauri/src/main.js delete mode 100644 tauri/src/styles.css diff --git a/.gitignore b/.gitignore index e22d768..da09066 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,29 @@ target/ # MSVC Windows builds of rustc generate these, which store debugging information *.pdb -# IDEs and editors -.vscode +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? + + diff --git a/Cargo.lock b/Cargo.lock index 2a2506a..fec0d24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,6 +62,61 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "askama" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b79091df18a97caea757e28cd2d5fda49c6cd4bd01ddffd7ff01ace0c0ad2c28" +dependencies = [ + "askama_derive", + "askama_escape", + "humansize", + "num-traits", + "percent-encoding", +] + +[[package]] +name = "askama_axum" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a41603f7cdbf5ac4af60760f17253eb6adf6ec5b6f14a7ed830cf687d375f163" +dependencies = [ + "askama", + "axum-core", + "http", +] + +[[package]] +name = "askama_derive" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19fe8d6cb13c4714962c072ea496f3392015f0989b1a2847bb4b2d9effd71d83" +dependencies = [ + "askama_parser", + "basic-toml", + "mime", + "mime_guess", + "proc-macro2", + "quote", + "serde", + "syn 2.0.72", +] + +[[package]] +name = "askama_escape" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" + +[[package]] +name = "askama_parser" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acb1161c6b64d1c3d83108213c2a2533a342ac225aabd0bda218278c2ddb00c0" +dependencies = [ + "nom", +] + [[package]] name = "async-trait" version = "0.1.81" @@ -70,7 +125,7 @@ checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -184,6 +239,15 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "basic-toml" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "823388e228f614e9558c6804262db37960ec8821856535f5c3f59913140558f8" +dependencies = [ + "serde", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -335,14 +399,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a969e13a7589e9e3e4207e153bae624ade2b5622fb4684a4923b23ec3d57719" dependencies = [ "serde", - "toml 0.8.2", + "toml 0.8.15", ] [[package]] name = "cc" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "324c74f2155653c90b04f25b2a47a8a631360cb908f92a772695f430c7e31052" +checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f" [[package]] name = "cesu8" @@ -399,6 +463,13 @@ dependencies = [ [[package]] name = "clego" version = "0.1.0" +dependencies = [ + "askama", + "askama_axum", + "axum", + "tokio", + "tower-http", +] [[package]] name = "cocoa" @@ -553,7 +624,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" dependencies = [ "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -563,7 +634,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edb49164822f3ee45b17acd4a208cfc1251410cf0cad9a833234c9890774dd9f" dependencies = [ "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -587,7 +658,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -598,7 +669,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -621,7 +692,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -681,7 +752,7 @@ checksum = "f2b99bf03862d7f545ebc28ddd33a665b50865f4dfd84031a393823879bd4c54" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -722,14 +793,14 @@ checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" [[package]] name = "embed-resource" -version = "2.4.2" +version = "2.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6985554d0688b687c5cb73898a34fbe3ad6c24c58c238a4d91d5e840670ee9d" +checksum = "4edcacde9351c33139a41e3c97eb2334351a81a2791bebb0b243df837128f602" dependencies = [ "cc", "memchr", "rustc_version", - "toml 0.8.2", + "toml 0.8.15", "vswhom", "winreg", ] @@ -740,15 +811,6 @@ version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ef6b89e5b37196644d8796de5268852ff179b44e96276cf4290264843743bb7" -[[package]] -name = "encoding_rs" -version = "0.8.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" -dependencies = [ - "cfg-if", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -818,7 +880,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -846,21 +908,6 @@ dependencies = [ "new_debug_unreachable", ] -[[package]] -name = "futures" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - [[package]] name = "futures-channel" version = "0.3.30" @@ -868,7 +915,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", - "futures-sink", ] [[package]] @@ -902,7 +948,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -923,7 +969,6 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ - "futures-channel", "futures-core", "futures-io", "futures-macro", @@ -1156,11 +1201,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bb0228f477c0900c880fd78c8759b95c7636dbd7842707f49e132378aa2acdc" dependencies = [ "heck 0.4.1", - "proc-macro-crate 2.0.2", + "proc-macro-crate 2.0.0", "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -1239,7 +1284,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -1326,6 +1371,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "http-range-header" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08a397c49fec283e3d6211adbe480be95aae5f304cfb923e9970e08956d5168a" + [[package]] name = "httparse" version = "1.9.4" @@ -1338,6 +1389,15 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "humansize" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7" +dependencies = [ + "libm", +] + [[package]] name = "hyper" version = "1.4.1" @@ -1427,6 +1487,25 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "include_dir" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "923d117408f1e49d914f1a379a309cffe4f18c05cf4e3d12e613a15fc81bd0dd" +dependencies = [ + "include_dir_macros", +] + +[[package]] +name = "include_dir_macros" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cab85a7ed0bd5f0e76d93846e0147172bed2e2d3f859bcc33a8d9699cad1a75" +dependencies = [ + "proc-macro2", + "quote", +] + [[package]] name = "indexmap" version = "1.9.3" @@ -1473,25 +1552,6 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" -[[package]] -name = "is-docker" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3" -dependencies = [ - "once_cell", -] - -[[package]] -name = "is-wsl" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5" -dependencies = [ - "is-docker", - "once_cell", -] - [[package]] name = "itoa" version = "0.4.8" @@ -1639,6 +1699,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + [[package]] name = "libredox" version = "0.1.3" @@ -1751,6 +1817,22 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "mime_guess" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" +dependencies = [ + "mime", + "unicase", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.4" @@ -1763,13 +1845,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.11" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +checksum = "4569e456d394deccd22ce1c1913e6ea0e54519f577285001215d33557431afe4" dependencies = [ + "hermit-abi", "libc", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1832,6 +1915,16 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -1857,16 +1950,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "num_enum" version = "0.5.11" @@ -2031,33 +2114,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "open" -version = "5.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a877bf6abd716642a53ef1b89fb498923a4afca5c754f9050b4d081c05c4b3" -dependencies = [ - "is-wsl", - "libc", - "pathdiff", -] - [[package]] name = "option-ext" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" -[[package]] -name = "os_pipe" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29d73ba8daf8fac13b0501d1abeddcfe21ba7401ada61a819144b6c2a4f32209" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "overload" version = "0.1.1" @@ -2112,12 +2174,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "pathdiff" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" - [[package]] name = "percent-encoding" version = "2.3.1" @@ -2228,7 +2284,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -2275,7 +2331,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -2352,12 +2408,11 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "2.0.2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b00f26d3400549137f92511a46ac1cd8ce37cb5598a96d382381458b992a5d24" +checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" dependencies = [ - "toml_datetime", - "toml_edit 0.20.2", + "toml_edit 0.20.7", ] [[package]] @@ -2670,7 +2725,7 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -2742,7 +2797,7 @@ checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -2753,7 +2808,7 @@ checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -2785,7 +2840,7 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -2836,7 +2891,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -2891,16 +2946,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "shared_child" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0d94659ad3c2137fef23ae75b03d5241d633f8acded53d672decfa0e6e0caef" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "simd-adler32" version = "0.3.7" @@ -3058,9 +3103,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.71" +version = "2.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", @@ -3088,7 +3133,7 @@ dependencies = [ "cfg-expr", "heck 0.5.0", "pkg-config", - "toml 0.8.2", + "toml 0.8.15", "version-compare", ] @@ -3148,20 +3193,6 @@ version = "0.12.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4873307b7c257eddcb50c9bedf158eb669578359fb28428bef438fec8e6ba7c2" -[[package]] -name = "tauri" -version = "0.0.0" -dependencies = [ - "axum", - "futures", - "serde", - "serde_json", - "tauri 2.0.0-beta.24", - "tauri-build", - "tauri-plugin-shell", - "tower", -] - [[package]] name = "tauri" version = "2.0.0-beta.24" @@ -3229,10 +3260,23 @@ dependencies = [ "serde_json", "tauri-utils", "tauri-winres", - "toml 0.8.2", + "toml 0.8.15", "walkdir", ] +[[package]] +name = "tauri-clego" +version = "0.1.0" +dependencies = [ + "axum", + "clego", + "include_dir", + "tauri", + "tauri-build", + "tokio", + "tower", +] + [[package]] name = "tauri-codegen" version = "2.0.0-beta.19" @@ -3251,7 +3295,7 @@ dependencies = [ "serde", "serde_json", "sha2", - "syn 2.0.71", + "syn 2.0.72", "tauri-utils", "thiserror", "time", @@ -3269,49 +3313,11 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", "tauri-codegen", "tauri-utils", ] -[[package]] -name = "tauri-plugin" -version = "2.0.0-beta.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1abe0b85472516d1033ba251ac81b9f18f02725aadcaad697c8b727e6505a6ad" -dependencies = [ - "anyhow", - "glob", - "plist", - "schemars", - "serde", - "serde_json", - "tauri-utils", - "toml 0.8.2", - "walkdir", -] - -[[package]] -name = "tauri-plugin-shell" -version = "2.0.0-beta.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9fa8c4e3d9ec343f6c3eb081672045566128a6c48ff6f6eeea85251ff38d3f" -dependencies = [ - "encoding_rs", - "log", - "open", - "os_pipe", - "regex", - "schemars", - "serde", - "serde_json", - "shared_child", - "tauri 2.0.0-beta.24", - "tauri-plugin", - "thiserror", - "tokio", -] - [[package]] name = "tauri-runtime" version = "2.0.0-beta.20" @@ -3384,7 +3390,7 @@ dependencies = [ "serde_with", "swift-rs", "thiserror", - "toml 0.8.2", + "toml 0.8.15", "url", "urlpattern", "walkdir", @@ -3419,22 +3425,22 @@ checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c" [[package]] name = "thiserror" -version = "1.0.62" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2675633b1499176c2dff06b0856a27976a8f9d436737b4cf4f312d4d91d8bbb" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.62" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d20468752b09f49e909e55a5d338caa8bedf615594e9d80bc4c565d30faf798c" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -3495,30 +3501,29 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.38.1" +version = "1.39.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb2caba9f80616f438e09748d5acda951967e1ea58508ef53d9c6402485a46df" +checksum = "d040ac2b29ab03b09d4129c2f5bbd012a3ac2f79d38ff506a4bf8dd34b0eac8a" dependencies = [ "backtrace", "bytes", "libc", "mio", - "num_cpus", "pin-project-lite", "socket2", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "tokio-macros" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -3548,21 +3553,21 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.2" +version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "185d8ab0dfbb35cf1399a6344d8484209c088f75f8f68230da55d48d95d43e3d" +checksum = "ac2caab0bf757388c6c0ae23b3293fdb463fee59434529014f85e3263b995c28" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.20.2", + "toml_edit 0.22.16", ] [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" dependencies = [ "serde", ] @@ -3577,20 +3582,31 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.5.40", ] [[package]] name = "toml_edit" -version = "0.20.2" +version = "0.20.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" +dependencies = [ + "indexmap 2.2.6", + "toml_datetime", + "winnow 0.5.40", +] + +[[package]] +name = "toml_edit" +version = "0.22.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "278f3d518e152219c994ce877758516bca5e118eaed6996192a774fb9fbf0788" dependencies = [ "indexmap 2.2.6", "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.6.15", ] [[package]] @@ -3609,6 +3625,31 @@ dependencies = [ "tracing", ] +[[package]] +name = "tower-http" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5" +dependencies = [ + "bitflags 2.6.0", + "bytes", + "futures-util", + "http", + "http-body", + "http-body-util", + "http-range-header", + "httpdate", + "mime", + "mime_guess", + "percent-encoding", + "pin-project-lite", + "tokio", + "tokio-util", + "tower-layer", + "tower-service", + "tracing", +] + [[package]] name = "tower-layer" version = "0.3.2" @@ -3641,7 +3682,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -3762,6 +3803,15 @@ dependencies = [ "unic-common", ] +[[package]] +name = "unicase" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d2d4dafb69621809a81864c9c1b864479e1235c0dd4e199924b9742439ed89" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.15" @@ -3919,7 +3969,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", "wasm-bindgen-shared", ] @@ -3953,7 +4003,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4053,7 +4103,7 @@ checksum = "ac1345798ecd8122468840bcdf1b95e5dc6d2206c5e4b0eafa078d061f59c9bc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -4159,7 +4209,7 @@ checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -4170,7 +4220,7 @@ checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.71", + "syn 2.0.72", ] [[package]] @@ -4405,6 +4455,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "0.6.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "557404e450152cd6795bb558bca69e43c585055f4606e3bcae5894fc6dac9ba0" +dependencies = [ + "memchr", +] + [[package]] name = "winreg" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index 3b40f42..8507ae3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] -members = [ - "clego", - "tauri/src-tauri", -] resolver = "2" +members = [ + "crates/clego", + "crates/tauri" +] diff --git a/README.md b/README.md index c25e7b4..d995282 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,34 @@ # Krys4lide -Logiciel de pharmacie \ No newline at end of file +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 +``` diff --git a/clego/Cargo.toml b/clego/Cargo.toml deleted file mode 100644 index 495a5a2..0000000 --- a/clego/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "clego" -version = "0.1.0" -edition = "2021" - -[dependencies] diff --git a/clego/src/main.rs b/clego/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/clego/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/crates/clego/.gitignore b/crates/clego/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/crates/clego/.gitignore @@ -0,0 +1 @@ +/target diff --git a/crates/clego/Cargo.toml b/crates/clego/Cargo.toml new file mode 100644 index 0000000..10760c3 --- /dev/null +++ b/crates/clego/Cargo.toml @@ -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"] } + diff --git a/crates/clego/assets/js/htmx.min.js.js b/crates/clego/assets/js/htmx.min.js.js new file mode 100644 index 0000000..6eeb64f --- /dev/null +++ b/crates/clego/assets/js/htmx.min.js.js @@ -0,0 +1 @@ +var htmx=function(){"use strict";const Q={onLoad:null,process:null,on:null,off:null,trigger:null,ajax:null,find:null,findAll:null,closest:null,values:function(e,t){const n=cn(e,t||"post");return n.values},remove:null,addClass:null,removeClass:null,toggleClass:null,takeClass:null,swap:null,defineExtension:null,removeExtension:null,logAll:null,logNone:null,logger:null,config:{historyEnabled:true,historyCacheSize:10,refreshOnHistoryMiss:false,defaultSwapStyle:"innerHTML",defaultSwapDelay:0,defaultSettleDelay:20,includeIndicatorStyles:true,indicatorClass:"htmx-indicator",requestClass:"htmx-request",addedClass:"htmx-added",settlingClass:"htmx-settling",swappingClass:"htmx-swapping",allowEval:true,allowScriptTags:true,inlineScriptNonce:"",inlineStyleNonce:"",attributesToSettle:["class","style","width","height"],withCredentials:false,timeout:0,wsReconnectDelay:"full-jitter",wsBinaryType:"blob",disableSelector:"[hx-disable], [data-hx-disable]",scrollBehavior:"instant",defaultFocusScroll:false,getCacheBusterParam:false,globalViewTransitions:false,methodsThatUseUrlParams:["get","delete"],selfRequestsOnly:true,ignoreTitle:false,scrollIntoViewOnBoost:true,triggerSpecsCache:null,disableInheritance:false,responseHandling:[{code:"204",swap:false},{code:"[23]..",swap:true},{code:"[45]..",swap:false,error:true}],allowNestedOobSwaps:true},parseInterval:null,_:null,version:"2.0.1"};Q.onLoad=$;Q.process=kt;Q.on=be;Q.off=we;Q.trigger=he;Q.ajax=Hn;Q.find=r;Q.findAll=p;Q.closest=g;Q.remove=K;Q.addClass=Y;Q.removeClass=o;Q.toggleClass=W;Q.takeClass=ge;Q.swap=ze;Q.defineExtension=Un;Q.removeExtension=Bn;Q.logAll=z;Q.logNone=J;Q.parseInterval=d;Q._=_;const n={addTriggerHandler:Et,bodyContains:le,canAccessLocalStorage:j,findThisElement:Ee,filterValues:dn,swap:ze,hasAttribute:s,getAttributeValue:te,getClosestAttributeValue:re,getClosestMatch:T,getExpressionVars:Cn,getHeaders:hn,getInputValues:cn,getInternalData:ie,getSwapSpecification:pn,getTriggerSpecs:lt,getTarget:Ce,makeFragment:k,mergeObjects:ue,makeSettleInfo:xn,oobSwap:Te,querySelectorExt:fe,settleImmediately:Gt,shouldCancel:dt,triggerEvent:he,triggerErrorEvent:ae,withExtensions:Ut};const v=["get","post","put","delete","patch"];const R=v.map(function(e){return"[hx-"+e+"], [data-hx-"+e+"]"}).join(", ");const O=e("head");function e(e,t=false){return new RegExp(`<${e}(\\s[^>]*>|>)([\\s\\S]*?)<\\/${e}>`,t?"gim":"im")}function d(e){if(e==undefined){return undefined}let t=NaN;if(e.slice(-2)=="ms"){t=parseFloat(e.slice(0,-2))}else if(e.slice(-1)=="s"){t=parseFloat(e.slice(0,-1))*1e3}else if(e.slice(-1)=="m"){t=parseFloat(e.slice(0,-1))*1e3*60}else{t=parseFloat(e)}return isNaN(t)?undefined:t}function ee(e,t){return e instanceof Element&&e.getAttribute(t)}function s(e,t){return!!e.hasAttribute&&(e.hasAttribute(t)||e.hasAttribute("data-"+t))}function te(e,t){return ee(e,t)||ee(e,"data-"+t)}function u(e){const t=e.parentElement;if(!t&&e.parentNode instanceof ShadowRoot)return e.parentNode;return t}function ne(){return document}function H(e,t){return e.getRootNode?e.getRootNode({composed:t}):ne()}function T(e,t){while(e&&!t(e)){e=u(e)}return e||null}function q(e,t,n){const r=te(t,n);const o=te(t,"hx-disinherit");var i=te(t,"hx-inherit");if(e!==t){if(Q.config.disableInheritance){if(i&&(i==="*"||i.split(" ").indexOf(n)>=0)){return r}else{return null}}if(o&&(o==="*"||o.split(" ").indexOf(n)>=0)){return"unset"}}return r}function re(t,n){let r=null;T(t,function(e){return!!(r=q(t,ce(e),n))});if(r!=="unset"){return r}}function a(e,t){const n=e instanceof Element&&(e.matches||e.matchesSelector||e.msMatchesSelector||e.mozMatchesSelector||e.webkitMatchesSelector||e.oMatchesSelector);return!!n&&n.call(e,t)}function L(e){const t=/<([a-z][^\/\0>\x20\t\r\n\f]*)/i;const n=t.exec(e);if(n){return n[1].toLowerCase()}else{return""}}function N(e){const t=new DOMParser;return t.parseFromString(e,"text/html")}function A(e,t){while(t.childNodes.length>0){e.append(t.childNodes[0])}}function I(e){const t=ne().createElement("script");se(e.attributes,function(e){t.setAttribute(e.name,e.value)});t.textContent=e.textContent;t.async=false;if(Q.config.inlineScriptNonce){t.nonce=Q.config.inlineScriptNonce}return t}function P(e){return e.matches("script")&&(e.type==="text/javascript"||e.type==="module"||e.type==="")}function D(e){Array.from(e.querySelectorAll("script")).forEach(e=>{if(P(e)){const t=I(e);const n=e.parentNode;try{n.insertBefore(t,e)}catch(e){w(e)}finally{e.remove()}}})}function k(e){const t=e.replace(O,"");const n=L(t);let r;if(n==="html"){r=new DocumentFragment;const i=N(e);A(r,i.body);r.title=i.title}else if(n==="body"){r=new DocumentFragment;const i=N(t);A(r,i.body);r.title=i.title}else{const i=N('");r=i.querySelector("template").content;r.title=i.title;var o=r.querySelector("title");if(o&&o.parentNode===r){o.remove();r.title=o.innerText}}if(r){if(Q.config.allowScriptTags){D(r)}else{r.querySelectorAll("script").forEach(e=>e.remove())}}return r}function oe(e){if(e){e()}}function t(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"}function M(e){return typeof e==="function"}function X(e){return t(e,"Object")}function ie(e){const t="htmx-internal-data";let n=e[t];if(!n){n=e[t]={}}return n}function F(t){const n=[];if(t){for(let e=0;e=0}function le(e){const t=e.getRootNode&&e.getRootNode();if(t&&t instanceof window.ShadowRoot){return ne().body.contains(t.host)}else{return ne().body.contains(e)}}function B(e){return e.trim().split(/\s+/)}function ue(e,t){for(const n in t){if(t.hasOwnProperty(n)){e[n]=t[n]}}return e}function S(e){try{return JSON.parse(e)}catch(e){w(e);return null}}function j(){const e="htmx:localStorageTest";try{localStorage.setItem(e,e);localStorage.removeItem(e);return true}catch(e){return false}}function V(t){try{const e=new URL(t);if(e){t=e.pathname+e.search}if(!/^\/$/.test(t)){t=t.replace(/\/+$/,"")}return t}catch(e){return t}}function _(e){return vn(ne().body,function(){return eval(e)})}function $(t){const e=Q.on("htmx:load",function(e){t(e.detail.elt)});return e}function z(){Q.logger=function(e,t,n){if(console){console.log(t,e,n)}}}function J(){Q.logger=null}function r(e,t){if(typeof e!=="string"){return e.querySelector(t)}else{return r(ne(),e)}}function p(e,t){if(typeof e!=="string"){return e.querySelectorAll(t)}else{return p(ne(),e)}}function E(){return window}function K(e,t){e=y(e);if(t){E().setTimeout(function(){K(e);e=null},t)}else{u(e).removeChild(e)}}function ce(e){return e instanceof Element?e:null}function G(e){return e instanceof HTMLElement?e:null}function Z(e){return typeof e==="string"?e:null}function h(e){return e instanceof Element||e instanceof Document||e instanceof DocumentFragment?e:null}function Y(e,t,n){e=ce(y(e));if(!e){return}if(n){E().setTimeout(function(){Y(e,t);e=null},n)}else{e.classList&&e.classList.add(t)}}function o(e,t,n){let r=ce(y(e));if(!r){return}if(n){E().setTimeout(function(){o(r,t);r=null},n)}else{if(r.classList){r.classList.remove(t);if(r.classList.length===0){r.removeAttribute("class")}}}}function W(e,t){e=y(e);e.classList.toggle(t)}function ge(e,t){e=y(e);se(e.parentElement.children,function(e){o(e,t)});Y(ce(e),t)}function g(e,t){e=ce(y(e));if(e&&e.closest){return e.closest(t)}else{do{if(e==null||a(e,t)){return e}}while(e=e&&ce(u(e)));return null}}function l(e,t){return e.substring(0,t.length)===t}function pe(e,t){return e.substring(e.length-t.length)===t}function i(e){const t=e.trim();if(l(t,"<")&&pe(t,"/>")){return t.substring(1,t.length-2)}else{return t}}function m(e,t,n){e=y(e);if(t.indexOf("closest ")===0){return[g(ce(e),i(t.substr(8)))]}else if(t.indexOf("find ")===0){return[r(h(e),i(t.substr(5)))]}else if(t==="next"){return[ce(e).nextElementSibling]}else if(t.indexOf("next ")===0){return[me(e,i(t.substr(5)),!!n)]}else if(t==="previous"){return[ce(e).previousElementSibling]}else if(t.indexOf("previous ")===0){return[ye(e,i(t.substr(9)),!!n)]}else if(t==="document"){return[document]}else if(t==="window"){return[window]}else if(t==="body"){return[document.body]}else if(t==="root"){return[H(e,!!n)]}else if(t.indexOf("global ")===0){return m(e,t.slice(7),true)}else{return F(h(H(e,!!n)).querySelectorAll(i(t)))}}var me=function(t,e,n){const r=h(H(t,n)).querySelectorAll(e);for(let e=0;e=0;e--){const o=r[e];if(o.compareDocumentPosition(t)===Node.DOCUMENT_POSITION_FOLLOWING){return o}}};function fe(e,t){if(typeof e!=="string"){return m(e,t)[0]}else{return m(ne().body,e)[0]}}function y(e,t){if(typeof e==="string"){return r(h(t)||document,e)}else{return e}}function xe(e,t,n){if(M(t)){return{target:ne().body,event:Z(e),listener:t}}else{return{target:y(e),event:Z(t),listener:n}}}function be(t,n,r){_n(function(){const e=xe(t,n,r);e.target.addEventListener(e.event,e.listener)});const e=M(n);return e?n:r}function we(t,n,r){_n(function(){const e=xe(t,n,r);e.target.removeEventListener(e.event,e.listener)});return M(n)?n:r}const ve=ne().createElement("output");function Se(e,t){const n=re(e,t);if(n){if(n==="this"){return[Ee(e,t)]}else{const r=m(e,n);if(r.length===0){w('The selector "'+n+'" on '+t+" returned no matches!");return[ve]}else{return r}}}}function Ee(e,t){return ce(T(e,function(e){return te(ce(e),t)!=null}))}function Ce(e){const t=re(e,"hx-target");if(t){if(t==="this"){return Ee(e,"hx-target")}else{return fe(e,t)}}else{const n=ie(e);if(n.boosted){return ne().body}else{return e}}}function Re(t){const n=Q.config.attributesToSettle;for(let e=0;e0){s=e.substr(0,e.indexOf(":"));t=e.substr(e.indexOf(":")+1,e.length)}else{s=e}const n=ne().querySelectorAll(t);if(n){se(n,function(e){let t;const n=o.cloneNode(true);t=ne().createDocumentFragment();t.appendChild(n);if(!He(s,e)){t=h(n)}const r={shouldSwap:true,target:e,fragment:t};if(!he(e,"htmx:oobBeforeSwap",r))return;e=r.target;if(r.shouldSwap){_e(s,e,e,t,i)}se(i.elts,function(e){he(e,"htmx:oobAfterSwap",r)})});o.parentNode.removeChild(o)}else{o.parentNode.removeChild(o);ae(ne().body,"htmx:oobErrorNoTarget",{content:o})}return e}function qe(e){se(p(e,"[hx-preserve], [data-hx-preserve]"),function(e){const t=te(e,"id");const n=ne().getElementById(t);if(n!=null){e.parentNode.replaceChild(n,e)}})}function Le(l,e,u){se(e.querySelectorAll("[id]"),function(t){const n=ee(t,"id");if(n&&n.length>0){const r=n.replace("'","\\'");const o=t.tagName.replace(":","\\:");const e=h(l);const i=e&&e.querySelector(o+"[id='"+r+"']");if(i&&i!==e){const s=t.cloneNode();Oe(t,i);u.tasks.push(function(){Oe(t,s)})}}})}function Ne(e){return function(){o(e,Q.config.addedClass);kt(ce(e));Ae(h(e));he(e,"htmx:load")}}function Ae(e){const t="[autofocus]";const n=G(a(e,t)?e:e.querySelector(t));if(n!=null){n.focus()}}function c(e,t,n,r){Le(e,n,r);while(n.childNodes.length>0){const o=n.firstChild;Y(ce(o),Q.config.addedClass);e.insertBefore(o,t);if(o.nodeType!==Node.TEXT_NODE&&o.nodeType!==Node.COMMENT_NODE){r.tasks.push(Ne(o))}}}function Ie(e,t){let n=0;while(n0){E().setTimeout(l,r.settleDelay)}else{l()}}function Je(e,t,n){const r=e.getResponseHeader(t);if(r.indexOf("{")===0){const o=S(r);for(const i in o){if(o.hasOwnProperty(i)){let e=o[i];if(!X(e)){e={value:e}}he(n,i,e)}}}else{const s=r.split(",");for(let e=0;e0){const s=o[0];if(s==="]"){e--;if(e===0){if(n===null){t=t+"true"}o.shift();t+=")})";try{const l=vn(r,function(){return Function(t)()},function(){return true});l.source=t;return l}catch(e){ae(ne().body,"htmx:syntax:error",{error:e,source:t});return null}}}else if(s==="["){e++}if(nt(s,n,i)){t+="(("+i+"."+s+") ? ("+i+"."+s+") : (window."+s+"))"}else{t=t+s}n=o.shift()}}}function b(e,t){let n="";while(e.length>0&&!t.test(e[0])){n+=e.shift()}return n}function ot(e){let t;if(e.length>0&&Qe.test(e[0])){e.shift();t=b(e,et).trim();e.shift()}else{t=b(e,x)}return t}const it="input, textarea, select";function st(e,t,n){const r=[];const o=tt(t);do{b(o,We);const l=o.length;const u=b(o,/[,\[\s]/);if(u!==""){if(u==="every"){const c={trigger:"every"};b(o,We);c.pollInterval=d(b(o,/[,\[\s]/));b(o,We);var i=rt(e,o,"event");if(i){c.eventFilter=i}r.push(c)}else{const f={trigger:u};var i=rt(e,o,"event");if(i){f.eventFilter=i}while(o.length>0&&o[0]!==","){b(o,We);const a=o.shift();if(a==="changed"){f.changed=true}else if(a==="once"){f.once=true}else if(a==="consume"){f.consume=true}else if(a==="delay"&&o[0]===":"){o.shift();f.delay=d(b(o,x))}else if(a==="from"&&o[0]===":"){o.shift();if(Qe.test(o[0])){var s=ot(o)}else{var s=b(o,x);if(s==="closest"||s==="find"||s==="next"||s==="previous"){o.shift();const h=ot(o);if(h.length>0){s+=" "+h}}}f.from=s}else if(a==="target"&&o[0]===":"){o.shift();f.target=ot(o)}else if(a==="throttle"&&o[0]===":"){o.shift();f.throttle=d(b(o,x))}else if(a==="queue"&&o[0]===":"){o.shift();f.queue=b(o,x)}else if(a==="root"&&o[0]===":"){o.shift();f[a]=ot(o)}else if(a==="threshold"&&o[0]===":"){o.shift();f[a]=b(o,x)}else{ae(e,"htmx:syntax:error",{token:o.shift()})}}r.push(f)}}if(o.length===l){ae(e,"htmx:syntax:error",{token:o.shift()})}b(o,We)}while(o[0]===","&&o.shift());if(n){n[t]=r}return r}function lt(e){const t=te(e,"hx-trigger");let n=[];if(t){const r=Q.config.triggerSpecsCache;n=r&&r[t]||st(e,t,r)}if(n.length>0){return n}else if(a(e,"form")){return[{trigger:"submit"}]}else if(a(e,'input[type="button"], input[type="submit"]')){return[{trigger:"click"}]}else if(a(e,it)){return[{trigger:"change"}]}else{return[{trigger:"click"}]}}function ut(e){ie(e).cancelled=true}function ct(e,t,n){const r=ie(e);r.timeout=E().setTimeout(function(){if(le(e)&&r.cancelled!==true){if(!pt(n,e,Xt("hx:poll:trigger",{triggerSpec:n,target:e}))){t(e)}ct(e,t,n)}},n.pollInterval)}function ft(e){return location.hostname===e.hostname&&ee(e,"href")&&ee(e,"href").indexOf("#")!==0}function at(e){return g(e,Q.config.disableSelector)}function ht(t,n,e){if(t instanceof HTMLAnchorElement&&ft(t)&&(t.target===""||t.target==="_self")||t.tagName==="FORM"){n.boosted=true;let r,o;if(t.tagName==="A"){r="get";o=ee(t,"href")}else{const i=ee(t,"method");r=i?i.toLowerCase():"get";if(r==="get"){}o=ee(t,"action")}e.forEach(function(e){mt(t,function(e,t){const n=ce(e);if(at(n)){f(n);return}de(r,o,n,t)},n,e,true)})}}function dt(e,t){const n=ce(t);if(!n){return false}if(e.type==="submit"||e.type==="click"){if(n.tagName==="FORM"){return true}if(a(n,'input[type="submit"], button')&&g(n,"form")!==null){return true}if(n instanceof HTMLAnchorElement&&n.href&&(n.getAttribute("href")==="#"||n.getAttribute("href").indexOf("#")!==0)){return true}}return false}function gt(e,t){return ie(e).boosted&&e instanceof HTMLAnchorElement&&t.type==="click"&&(t.ctrlKey||t.metaKey)}function pt(e,t,n){const r=e.eventFilter;if(r){try{return r.call(t,n)!==true}catch(e){const o=r.source;ae(ne().body,"htmx:eventFilter:error",{error:e,source:o});return true}}return false}function mt(s,l,e,u,c){const f=ie(s);let t;if(u.from){t=m(s,u.from)}else{t=[s]}if(u.changed){t.forEach(function(e){const t=ie(e);t.lastValue=e.value})}se(t,function(o){const i=function(e){if(!le(s)){o.removeEventListener(u.trigger,i);return}if(gt(s,e)){return}if(c||dt(e,s)){e.preventDefault()}if(pt(u,s,e)){return}const t=ie(e);t.triggerSpec=u;if(t.handledFor==null){t.handledFor=[]}if(t.handledFor.indexOf(s)<0){t.handledFor.push(s);if(u.consume){e.stopPropagation()}if(u.target&&e.target){if(!a(ce(e.target),u.target)){return}}if(u.once){if(f.triggeredOnce){return}else{f.triggeredOnce=true}}if(u.changed){const n=ie(o);const r=o.value;if(n.lastValue===r){return}n.lastValue=r}if(f.delayed){clearTimeout(f.delayed)}if(f.throttle){return}if(u.throttle>0){if(!f.throttle){l(s,e);f.throttle=E().setTimeout(function(){f.throttle=null},u.throttle)}}else if(u.delay>0){f.delayed=E().setTimeout(function(){l(s,e)},u.delay)}else{he(s,"htmx:trigger");l(s,e)}}};if(e.listenerInfos==null){e.listenerInfos=[]}e.listenerInfos.push({trigger:u.trigger,listener:i,on:o});o.addEventListener(u.trigger,i)})}let yt=false;let xt=null;function bt(){if(!xt){xt=function(){yt=true};window.addEventListener("scroll",xt);setInterval(function(){if(yt){yt=false;se(ne().querySelectorAll("[hx-trigger*='revealed'],[data-hx-trigger*='revealed']"),function(e){wt(e)})}},200)}}function wt(e){if(!s(e,"data-hx-revealed")&&U(e)){e.setAttribute("data-hx-revealed","true");const t=ie(e);if(t.initHash){he(e,"revealed")}else{e.addEventListener("htmx:afterProcessNode",function(){he(e,"revealed")},{once:true})}}}function vt(e,t,n,r){const o=function(){if(!n.loaded){n.loaded=true;t(e)}};if(r>0){E().setTimeout(o,r)}else{o()}}function St(t,n,e){let i=false;se(v,function(r){if(s(t,"hx-"+r)){const o=te(t,"hx-"+r);i=true;n.path=o;n.verb=r;e.forEach(function(e){Et(t,e,n,function(e,t){const n=ce(e);if(g(n,Q.config.disableSelector)){f(n);return}de(r,o,n,t)})})}});return i}function Et(r,e,t,n){if(e.trigger==="revealed"){bt();mt(r,n,t,e);wt(ce(r))}else if(e.trigger==="intersect"){const o={};if(e.root){o.root=fe(r,e.root)}if(e.threshold){o.threshold=parseFloat(e.threshold)}const i=new IntersectionObserver(function(t){for(let e=0;e0){t.polling=true;ct(ce(r),n,e)}else{mt(r,n,t,e)}}function Ct(e){const t=ce(e);if(!t){return false}const n=t.attributes;for(let e=0;e", "+e).join(""));return o}else{return[]}}function qt(e){const t=g(ce(e.target),"button, input[type='submit']");const n=Nt(e);if(n){n.lastButtonClicked=t}}function Lt(e){const t=Nt(e);if(t){t.lastButtonClicked=null}}function Nt(e){const t=g(ce(e.target),"button, input[type='submit']");if(!t){return}const n=y("#"+ee(t,"form"),t.getRootNode())||g(t,"form");if(!n){return}return ie(n)}function At(e){e.addEventListener("click",qt);e.addEventListener("focusin",qt);e.addEventListener("focusout",Lt)}function It(t,e,n){const r=ie(t);if(!Array.isArray(r.onHandlers)){r.onHandlers=[]}let o;const i=function(e){vn(t,function(){if(at(t)){return}if(!o){o=new Function("event",n)}o.call(t,e)})};t.addEventListener(e,i);r.onHandlers.push({event:e,listener:i})}function Pt(t){De(t);for(let e=0;eQ.config.historyCacheSize){i.shift()}while(i.length>0){try{localStorage.setItem("htmx-history-cache",JSON.stringify(i));break}catch(e){ae(ne().body,"htmx:historyCacheError",{cause:e,cache:i});i.shift()}}}function _t(t){if(!j()){return null}t=V(t);const n=S(localStorage.getItem("htmx-history-cache"))||[];for(let e=0;e=200&&this.status<400){he(ne().body,"htmx:historyCacheMissLoad",i);const e=k(this.response);const t=e.querySelector("[hx-history-elt],[data-hx-history-elt]")||e;const n=jt();const r=xn(n);kn(e.title);Ve(n,t,r);Gt(r.tasks);Bt=o;he(ne().body,"htmx:historyRestore",{path:o,cacheMiss:true,serverResponse:this.response})}else{ae(ne().body,"htmx:historyCacheMissLoadError",i)}};e.send()}function Yt(e){zt();e=e||location.pathname+location.search;const t=_t(e);if(t){const n=k(t.content);const r=jt();const o=xn(r);kn(n.title);Ve(r,n,o);Gt(o.tasks);E().setTimeout(function(){window.scrollTo(0,t.scroll)},0);Bt=e;he(ne().body,"htmx:historyRestore",{path:e,item:t})}else{if(Q.config.refreshOnHistoryMiss){window.location.reload(true)}else{Zt(e)}}}function Wt(e){let t=Se(e,"hx-indicator");if(t==null){t=[e]}se(t,function(e){const t=ie(e);t.requestCount=(t.requestCount||0)+1;e.classList.add.call(e.classList,Q.config.requestClass)});return t}function Qt(e){let t=Se(e,"hx-disabled-elt");if(t==null){t=[]}se(t,function(e){const t=ie(e);t.requestCount=(t.requestCount||0)+1;e.setAttribute("disabled","")});return t}function en(e,t){se(e,function(e){const t=ie(e);t.requestCount=(t.requestCount||0)-1;if(t.requestCount===0){e.classList.remove.call(e.classList,Q.config.requestClass)}});se(t,function(e){const t=ie(e);t.requestCount=(t.requestCount||0)-1;if(t.requestCount===0){e.removeAttribute("disabled")}})}function tn(t,n){for(let e=0;en.indexOf(e)<0)}else{e=e.filter(e=>e!==n)}r.delete(t);se(e,e=>r.append(t,e))}}function sn(t,n,r,o,i){if(o==null||tn(t,o)){return}else{t.push(o)}if(nn(o)){const s=ee(o,"name");let e=o.value;if(o instanceof HTMLSelectElement&&o.multiple){e=F(o.querySelectorAll("option:checked")).map(function(e){return e.value})}if(o instanceof HTMLInputElement&&o.files){e=F(o.files)}rn(s,e,n);if(i){ln(o,r)}}if(o instanceof HTMLFormElement){se(o.elements,function(e){if(t.indexOf(e)>=0){on(e.name,e.value,n)}else{t.push(e)}if(i){ln(e,r)}});new FormData(o).forEach(function(e,t){if(e instanceof File&&e.name===""){return}rn(t,e,n)})}}function ln(e,t){const n=e;if(n.willValidate){he(n,"htmx:validation:validate");if(!n.checkValidity()){t.push({elt:n,message:n.validationMessage,validity:n.validity});he(n,"htmx:validation:failed",{message:n.validationMessage,validity:n.validity})}}}function un(t,e){for(const n of e.keys()){t.delete(n);e.getAll(n).forEach(function(e){t.append(n,e)})}return t}function cn(e,t){const n=[];const r=new FormData;const o=new FormData;const i=[];const s=ie(e);if(s.lastButtonClicked&&!le(s.lastButtonClicked)){s.lastButtonClicked=null}let l=e instanceof HTMLFormElement&&e.noValidate!==true||te(e,"hx-validate")==="true";if(s.lastButtonClicked){l=l&&s.lastButtonClicked.formNoValidate!==true}if(t!=="get"){sn(n,o,i,g(e,"form"),l)}sn(n,r,i,e,l);if(s.lastButtonClicked||e.tagName==="BUTTON"||e.tagName==="INPUT"&&ee(e,"type")==="submit"){const c=s.lastButtonClicked||e;const f=ee(c,"name");rn(f,c.value,o)}const u=Se(e,"hx-include");se(u,function(e){sn(n,r,i,ce(e),l);if(!a(e,"form")){se(h(e).querySelectorAll(it),function(e){sn(n,r,i,e,l)})}});un(r,o);return{errors:i,formData:r,values:An(r)}}function fn(e,t,n){if(e!==""){e+="&"}if(String(n)==="[object Object]"){n=JSON.stringify(n)}const r=encodeURIComponent(n);e+=encodeURIComponent(t)+"="+r;return e}function an(e){e=Ln(e);let n="";e.forEach(function(e,t){n=fn(n,t,e)});return n}function hn(e,t,n){const r={"HX-Request":"true","HX-Trigger":ee(e,"id"),"HX-Trigger-Name":ee(e,"name"),"HX-Target":te(t,"id"),"HX-Current-URL":ne().location.href};wn(e,"hx-headers",false,r);if(n!==undefined){r["HX-Prompt"]=n}if(ie(e).boosted){r["HX-Boosted"]="true"}return r}function dn(n,e){const t=re(e,"hx-params");if(t){if(t==="none"){return new FormData}else if(t==="*"){return n}else if(t.indexOf("not ")===0){se(t.substr(4).split(","),function(e){e=e.trim();n.delete(e)});return n}else{const r=new FormData;se(t.split(","),function(t){t=t.trim();if(n.has(t)){n.getAll(t).forEach(function(e){r.append(t,e)})}});return r}}else{return n}}function gn(e){return!!ee(e,"href")&&ee(e,"href").indexOf("#")>=0}function pn(e,t){const n=t||re(e,"hx-swap");const r={swapStyle:ie(e).boosted?"innerHTML":Q.config.defaultSwapStyle,swapDelay:Q.config.defaultSwapDelay,settleDelay:Q.config.defaultSettleDelay};if(Q.config.scrollIntoViewOnBoost&&ie(e).boosted&&!gn(e)){r.show="top"}if(n){const s=B(n);if(s.length>0){for(let e=0;e0?o.join(":"):null;r.scroll=c;r.scrollTarget=i}else if(l.indexOf("show:")===0){const f=l.substr(5);var o=f.split(":");const a=o.pop();var i=o.length>0?o.join(":"):null;r.show=a;r.showTarget=i}else if(l.indexOf("focus-scroll:")===0){const h=l.substr("focus-scroll:".length);r.focusScroll=h=="true"}else if(e==0){r.swapStyle=l}else{w("Unknown modifier in hx-swap: "+l)}}}}return r}function mn(e){return re(e,"hx-encoding")==="multipart/form-data"||a(e,"form")&&ee(e,"enctype")==="multipart/form-data"}function yn(t,n,r){let o=null;Ut(n,function(e){if(o==null){o=e.encodeParameters(t,r,n)}});if(o!=null){return o}else{if(mn(n)){return un(new FormData,Ln(r))}else{return an(r)}}}function xn(e){return{tasks:[],elts:[e]}}function bn(e,t){const n=e[0];const r=e[e.length-1];if(t.scroll){var o=null;if(t.scrollTarget){o=ce(fe(n,t.scrollTarget))}if(t.scroll==="top"&&(n||o)){o=o||n;o.scrollTop=0}if(t.scroll==="bottom"&&(r||o)){o=o||r;o.scrollTop=o.scrollHeight}}if(t.show){var o=null;if(t.showTarget){let e=t.showTarget;if(t.showTarget==="window"){e="body"}o=ce(fe(n,e))}if(t.show==="top"&&(n||o)){o=o||n;o.scrollIntoView({block:"start",behavior:Q.config.scrollBehavior})}if(t.show==="bottom"&&(r||o)){o=o||r;o.scrollIntoView({block:"end",behavior:Q.config.scrollBehavior})}}}function wn(r,e,o,i){if(i==null){i={}}if(r==null){return i}const s=te(r,e);if(s){let e=s.trim();let t=o;if(e==="unset"){return null}if(e.indexOf("javascript:")===0){e=e.substr(11);t=true}else if(e.indexOf("js:")===0){e=e.substr(3);t=true}if(e.indexOf("{")!==0){e="{"+e+"}"}let n;if(t){n=vn(r,function(){return Function("return ("+e+")")()},{})}else{n=S(e)}for(const l in n){if(n.hasOwnProperty(l)){if(i[l]==null){i[l]=n[l]}}}}return wn(ce(u(r)),e,o,i)}function vn(e,t,n){if(Q.config.allowEval){return t()}else{ae(e,"htmx:evalDisallowedError");return n}}function Sn(e,t){return wn(e,"hx-vars",true,t)}function En(e,t){return wn(e,"hx-vals",false,t)}function Cn(e){return ue(Sn(e),En(e))}function Rn(t,n,r){if(r!==null){try{t.setRequestHeader(n,r)}catch(e){t.setRequestHeader(n,encodeURIComponent(r));t.setRequestHeader(n+"-URI-AutoEncoded","true")}}}function On(t){if(t.responseURL&&typeof URL!=="undefined"){try{const e=new URL(t.responseURL);return e.pathname+e.search}catch(e){ae(ne().body,"htmx:badResponseUrl",{url:t.responseURL})}}}function C(e,t){return t.test(e.getAllResponseHeaders())}function Hn(e,t,n){e=e.toLowerCase();if(n){if(n instanceof Element||typeof n==="string"){return de(e,t,null,null,{targetOverride:y(n),returnPromise:true})}else{return de(e,t,y(n.source),n.event,{handler:n.handler,headers:n.headers,values:n.values,targetOverride:y(n.target),swapOverride:n.swap,select:n.select,returnPromise:true})}}else{return de(e,t,null,null,{returnPromise:true})}}function Tn(e){const t=[];while(e){t.push(e);e=e.parentElement}return t}function qn(e,t,n){let r;let o;if(typeof URL==="function"){o=new URL(t,document.location.href);const i=document.location.origin;r=i===o.origin}else{o=t;r=l(t,document.location.origin)}if(Q.config.selfRequestsOnly){if(!r){return false}}return he(e,"htmx:validateUrl",ue({url:o,sameHost:r},n))}function Ln(e){if(e instanceof FormData)return e;const t=new FormData;for(const n in e){if(e.hasOwnProperty(n)){if(typeof e[n].forEach==="function"){e[n].forEach(function(e){t.append(n,e)})}else if(typeof e[n]==="object"){t.append(n,JSON.stringify(e[n]))}else{t.append(n,e[n])}}}return t}function Nn(r,o,e){return new Proxy(e,{get:function(t,e){if(typeof e==="number")return t[e];if(e==="length")return t.length;if(e==="push"){return function(e){t.push(e);r.append(o,e)}}if(typeof t[e]==="function"){return function(){t[e].apply(t,arguments);r.delete(o);t.forEach(function(e){r.append(o,e)})}}if(t[e]&&t[e].length===1){return t[e][0]}else{return t[e]}},set:function(e,t,n){e[t]=n;r.delete(o);e.forEach(function(e){r.append(o,e)});return true}})}function An(r){return new Proxy(r,{get:function(e,t){if(typeof t==="symbol"){return Reflect.get(e,t)}if(t==="toJSON"){return()=>Object.fromEntries(r)}if(t in e){if(typeof e[t]==="function"){return function(){return r[t].apply(r,arguments)}}else{return e[t]}}const n=r.getAll(t);if(n.length===0){return undefined}else if(n.length===1){return n[0]}else{return Nn(e,t,n)}},set:function(t,n,e){if(typeof n!=="string"){return false}t.delete(n);if(typeof e.forEach==="function"){e.forEach(function(e){t.append(n,e)})}else{t.append(n,e)}return true},deleteProperty:function(e,t){if(typeof t==="string"){e.delete(t)}return true},ownKeys:function(e){return Reflect.ownKeys(Object.fromEntries(e))},getOwnPropertyDescriptor:function(e,t){return Reflect.getOwnPropertyDescriptor(Object.fromEntries(e),t)}})}function de(t,n,r,o,i,k){let s=null;let l=null;i=i!=null?i:{};if(i.returnPromise&&typeof Promise!=="undefined"){var e=new Promise(function(e,t){s=e;l=t})}if(r==null){r=ne().body}const M=i.handler||Mn;const X=i.select||null;if(!le(r)){oe(s);return e}const u=i.targetOverride||ce(Ce(r));if(u==null||u==ve){ae(r,"htmx:targetError",{target:te(r,"hx-target")});oe(l);return e}let c=ie(r);const f=c.lastButtonClicked;if(f){const L=ee(f,"formaction");if(L!=null){n=L}const N=ee(f,"formmethod");if(N!=null){if(N.toLowerCase()!=="dialog"){t=N}}}const a=re(r,"hx-confirm");if(k===undefined){const K=function(e){return de(t,n,r,o,i,!!e)};const G={target:u,elt:r,path:n,verb:t,triggeringEvent:o,etc:i,issueRequest:K,question:a};if(he(r,"htmx:confirm",G)===false){oe(s);return e}}let h=r;let d=re(r,"hx-sync");let g=null;let F=false;if(d){const A=d.split(":");const I=A[0].trim();if(I==="this"){h=Ee(r,"hx-sync")}else{h=ce(fe(r,I))}d=(A[1]||"drop").trim();c=ie(h);if(d==="drop"&&c.xhr&&c.abortable!==true){oe(s);return e}else if(d==="abort"){if(c.xhr){oe(s);return e}else{F=true}}else if(d==="replace"){he(h,"htmx:abort")}else if(d.indexOf("queue")===0){const Z=d.split(" ");g=(Z[1]||"last").trim()}}if(c.xhr){if(c.abortable){he(h,"htmx:abort")}else{if(g==null){if(o){const P=ie(o);if(P&&P.triggerSpec&&P.triggerSpec.queue){g=P.triggerSpec.queue}}if(g==null){g="last"}}if(c.queuedRequests==null){c.queuedRequests=[]}if(g==="first"&&c.queuedRequests.length===0){c.queuedRequests.push(function(){de(t,n,r,o,i)})}else if(g==="all"){c.queuedRequests.push(function(){de(t,n,r,o,i)})}else if(g==="last"){c.queuedRequests=[];c.queuedRequests.push(function(){de(t,n,r,o,i)})}oe(s);return e}}const p=new XMLHttpRequest;c.xhr=p;c.abortable=F;const m=function(){c.xhr=null;c.abortable=false;if(c.queuedRequests!=null&&c.queuedRequests.length>0){const e=c.queuedRequests.shift();e()}};const U=re(r,"hx-prompt");if(U){var y=prompt(U);if(y===null||!he(r,"htmx:prompt",{prompt:y,target:u})){oe(s);m();return e}}if(a&&!k){if(!confirm(a)){oe(s);m();return e}}let x=hn(r,u,y);if(t!=="get"&&!mn(r)){x["Content-Type"]="application/x-www-form-urlencoded"}if(i.headers){x=ue(x,i.headers)}const B=cn(r,t);let b=B.errors;const j=B.formData;if(i.values){un(j,Ln(i.values))}const V=Ln(Cn(r));const w=un(j,V);let v=dn(w,r);if(Q.config.getCacheBusterParam&&t==="get"){v.set("org.htmx.cache-buster",ee(u,"id")||"true")}if(n==null||n===""){n=ne().location.href}const S=wn(r,"hx-request");const _=ie(r).boosted;let E=Q.config.methodsThatUseUrlParams.indexOf(t)>=0;const C={boosted:_,useUrlParams:E,formData:v,parameters:An(v),unfilteredFormData:w,unfilteredParameters:An(w),headers:x,target:u,verb:t,errors:b,withCredentials:i.credentials||S.credentials||Q.config.withCredentials,timeout:i.timeout||S.timeout||Q.config.timeout,path:n,triggeringEvent:o};if(!he(r,"htmx:configRequest",C)){oe(s);m();return e}n=C.path;t=C.verb;x=C.headers;v=Ln(C.parameters);b=C.errors;E=C.useUrlParams;if(b&&b.length>0){he(r,"htmx:validation:halted",C);oe(s);m();return e}const $=n.split("#");const z=$[0];const R=$[1];let O=n;if(E){O=z;const Y=!v.keys().next().done;if(Y){if(O.indexOf("?")<0){O+="?"}else{O+="&"}O+=an(v);if(R){O+="#"+R}}}if(!qn(r,O,C)){ae(r,"htmx:invalidPath",C);oe(l);return e}p.open(t.toUpperCase(),O,true);p.overrideMimeType("text/html");p.withCredentials=C.withCredentials;p.timeout=C.timeout;if(S.noHeaders){}else{for(const D in x){if(x.hasOwnProperty(D)){const W=x[D];Rn(p,D,W)}}}const H={xhr:p,target:u,requestConfig:C,etc:i,boosted:_,select:X,pathInfo:{requestPath:n,finalRequestPath:O,responsePath:null,anchor:R}};p.onload=function(){try{const t=Tn(r);H.pathInfo.responsePath=On(p);M(r,H);en(T,q);he(r,"htmx:afterRequest",H);he(r,"htmx:afterOnLoad",H);if(!le(r)){let e=null;while(t.length>0&&e==null){const n=t.shift();if(le(n)){e=n}}if(e){he(e,"htmx:afterRequest",H);he(e,"htmx:afterOnLoad",H)}}oe(s);m()}catch(e){ae(r,"htmx:onLoadError",ue({error:e},H));throw e}};p.onerror=function(){en(T,q);ae(r,"htmx:afterRequest",H);ae(r,"htmx:sendError",H);oe(l);m()};p.onabort=function(){en(T,q);ae(r,"htmx:afterRequest",H);ae(r,"htmx:sendAbort",H);oe(l);m()};p.ontimeout=function(){en(T,q);ae(r,"htmx:afterRequest",H);ae(r,"htmx:timeout",H);oe(l);m()};if(!he(r,"htmx:beforeRequest",H)){oe(s);m();return e}var T=Wt(r);var q=Qt(r);se(["loadstart","loadend","progress","abort"],function(t){se([p,p.upload],function(e){e.addEventListener(t,function(e){he(r,"htmx:xhr:"+t,{lengthComputable:e.lengthComputable,loaded:e.loaded,total:e.total})})})});he(r,"htmx:beforeSend",H);const J=E?null:yn(p,r,v);p.send(J);return e}function In(e,t){const n=t.xhr;let r=null;let o=null;if(C(n,/HX-Push:/i)){r=n.getResponseHeader("HX-Push");o="push"}else if(C(n,/HX-Push-Url:/i)){r=n.getResponseHeader("HX-Push-Url");o="push"}else if(C(n,/HX-Replace-Url:/i)){r=n.getResponseHeader("HX-Replace-Url");o="replace"}if(r){if(r==="false"){return{}}else{return{type:o,path:r}}}const i=t.pathInfo.finalRequestPath;const s=t.pathInfo.responsePath;const l=re(e,"hx-push-url");const u=re(e,"hx-replace-url");const c=ie(e).boosted;let f=null;let a=null;if(l){f="push";a=l}else if(u){f="replace";a=u}else if(c){f="push";a=s||i}if(a){if(a==="false"){return{}}if(a==="true"){a=s||i}if(t.pathInfo.anchor&&a.indexOf("#")===-1){a=a+"#"+t.pathInfo.anchor}return{type:f,path:a}}else{return{}}}function Pn(e,t){var n=new RegExp(e.code);return n.test(t.toString(10))}function Dn(e){for(var t=0;t0){E().setTimeout(e,y.swapDelay)}else{e()}}if(a){ae(o,"htmx:responseError",ue({error:"Response Status Error Code "+s.status+" from "+i.pathInfo.requestPath},i))}}const Xn={};function Fn(){return{init:function(e){return null},getSelectors:function(){return null},onEvent:function(e,t){return true},transformResponse:function(e,t,n){return e},isInlineSwap:function(e){return false},handleSwap:function(e,t,n,r){return false},encodeParameters:function(e,t,n){return null}}}function Un(e,t){if(t.init){t.init(n)}Xn[e]=ue(Fn(),t)}function Bn(e){delete Xn[e]}function jn(e,n,r){if(n==undefined){n=[]}if(e==undefined){return n}if(r==undefined){r=[]}const t=te(e,"hx-ext");if(t){se(t.split(","),function(e){e=e.replace(/ /g,"");if(e.slice(0,7)=="ignore:"){r.push(e.slice(7));return}if(r.indexOf(e)<0){const t=Xn[e];if(t&&n.indexOf(t)<0){n.push(t)}}})}return jn(ce(u(e)),n,r)}var Vn=false;ne().addEventListener("DOMContentLoaded",function(){Vn=true});function _n(e){if(Vn||ne().readyState==="complete"){e()}else{ne().addEventListener("DOMContentLoaded",e)}}function $n(){if(Q.config.includeIndicatorStyles!==false){const e=Q.config.inlineStyleNonce?` nonce="${Q.config.inlineStyleNonce}"`:"";ne().head.insertAdjacentHTML("beforeend"," ."+Q.config.indicatorClass+"{opacity:0} ."+Q.config.requestClass+" ."+Q.config.indicatorClass+"{opacity:1; transition: opacity 200ms ease-in;} ."+Q.config.requestClass+"."+Q.config.indicatorClass+"{opacity:1; transition: opacity 200ms ease-in;} ")}}function zn(){const e=ne().querySelector('meta[name="htmx-config"]');if(e){return S(e.content)}else{return null}}function Jn(){const e=zn();if(e){Q.config=ue(Q.config,e)}}_n(function(){Jn();$n();let e=ne().body;kt(e);const t=ne().querySelectorAll("[hx-trigger='restored'],[data-hx-trigger='restored']");e.addEventListener("htmx:abort",function(e){const t=e.target;const n=ie(t);if(n&&n.xhr){n.xhr.abort()}});const n=window.onpopstate?window.onpopstate.bind(window):null;window.onpopstate=function(e){if(e.state&&e.state.htmx){Yt();se(t,function(e){he(e,"htmx:restored",{document:ne(),triggerEvent:he})})}else{if(n){n(e)}}};E().setTimeout(function(){he(e,"htmx:load",{});e=null},0)});return Q}(); \ No newline at end of file diff --git a/crates/clego/src/lib.rs b/crates/clego/src/lib.rs new file mode 100644 index 0000000..cb78fca --- /dev/null +++ b/crates/clego/src/lib.rs @@ -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 +} diff --git a/crates/clego/src/main.rs b/crates/clego/src/main.rs new file mode 100644 index 0000000..bfbfd83 --- /dev/null +++ b/crates/clego/src/main.rs @@ -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(); +} diff --git a/crates/clego/src/templates/hello.rs b/crates/clego/src/templates/hello.rs new file mode 100644 index 0000000..9ec4fb3 --- /dev/null +++ b/crates/clego/src/templates/hello.rs @@ -0,0 +1,7 @@ +use askama::Template; + +#[derive(Template)] +#[template(path = "hello.html")] +pub struct HelloResponse { + pub name: String, +} diff --git a/crates/clego/src/templates/index.rs b/crates/clego/src/templates/index.rs new file mode 100644 index 0000000..49e09e7 --- /dev/null +++ b/crates/clego/src/templates/index.rs @@ -0,0 +1,5 @@ +use askama::Template; + +#[derive(Template)] +#[template(path = "index.html")] +pub struct GetIndexResponse; diff --git a/crates/clego/src/templates/mod.rs b/crates/clego/src/templates/mod.rs new file mode 100644 index 0000000..3f635aa --- /dev/null +++ b/crates/clego/src/templates/mod.rs @@ -0,0 +1,2 @@ +pub mod index; +pub mod hello; diff --git a/crates/clego/templates/base.html b/crates/clego/templates/base.html new file mode 100644 index 0000000..9d57d0b --- /dev/null +++ b/crates/clego/templates/base.html @@ -0,0 +1,13 @@ + + + + {% block title %}{{ title }}{% endblock %} + + + + {% block head %}{% endblock %} + + + {% block body %}{% endblock %} + + diff --git a/crates/clego/templates/hello.html b/crates/clego/templates/hello.html new file mode 100644 index 0000000..c45d96e --- /dev/null +++ b/crates/clego/templates/hello.html @@ -0,0 +1 @@ +
Hello {{name}}!
diff --git a/crates/clego/templates/index.html b/crates/clego/templates/index.html new file mode 100644 index 0000000..f43a467 --- /dev/null +++ b/crates/clego/templates/index.html @@ -0,0 +1,23 @@ +{% extends "base.html" %} + +{% block title %}Phrama Libre{% endblock %} + +{% block body %} + +
+
+

Pharma Libre

+
+
+
+ Loading... +
+
+
+{% endblock %} diff --git a/tauri/src-tauri/.gitignore b/crates/tauri/.gitignore similarity index 100% rename from tauri/src-tauri/.gitignore rename to crates/tauri/.gitignore diff --git a/crates/tauri/Cargo.toml b/crates/tauri/Cargo.toml new file mode 100644 index 0000000..640a82a --- /dev/null +++ b/crates/tauri/Cargo.toml @@ -0,0 +1,23 @@ +[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" } +include_dir = "0.7.4" +tokio = "1.39.1" + diff --git a/tauri/src-tauri/build.rs b/crates/tauri/build.rs similarity index 100% rename from tauri/src-tauri/build.rs rename to crates/tauri/build.rs diff --git a/tauri/src-tauri/icons/128x128.png b/crates/tauri/icons/128x128.png similarity index 100% rename from tauri/src-tauri/icons/128x128.png rename to crates/tauri/icons/128x128.png diff --git a/tauri/src-tauri/icons/128x128@2x.png b/crates/tauri/icons/128x128@2x.png similarity index 100% rename from tauri/src-tauri/icons/128x128@2x.png rename to crates/tauri/icons/128x128@2x.png diff --git a/tauri/src-tauri/icons/32x32.png b/crates/tauri/icons/32x32.png similarity index 100% rename from tauri/src-tauri/icons/32x32.png rename to crates/tauri/icons/32x32.png diff --git a/tauri/src-tauri/icons/Square107x107Logo.png b/crates/tauri/icons/Square107x107Logo.png similarity index 100% rename from tauri/src-tauri/icons/Square107x107Logo.png rename to crates/tauri/icons/Square107x107Logo.png diff --git a/tauri/src-tauri/icons/Square142x142Logo.png b/crates/tauri/icons/Square142x142Logo.png similarity index 100% rename from tauri/src-tauri/icons/Square142x142Logo.png rename to crates/tauri/icons/Square142x142Logo.png diff --git a/tauri/src-tauri/icons/Square150x150Logo.png b/crates/tauri/icons/Square150x150Logo.png similarity index 100% rename from tauri/src-tauri/icons/Square150x150Logo.png rename to crates/tauri/icons/Square150x150Logo.png diff --git a/tauri/src-tauri/icons/Square284x284Logo.png b/crates/tauri/icons/Square284x284Logo.png similarity index 100% rename from tauri/src-tauri/icons/Square284x284Logo.png rename to crates/tauri/icons/Square284x284Logo.png diff --git a/tauri/src-tauri/icons/Square30x30Logo.png b/crates/tauri/icons/Square30x30Logo.png similarity index 100% rename from tauri/src-tauri/icons/Square30x30Logo.png rename to crates/tauri/icons/Square30x30Logo.png diff --git a/tauri/src-tauri/icons/Square310x310Logo.png b/crates/tauri/icons/Square310x310Logo.png similarity index 100% rename from tauri/src-tauri/icons/Square310x310Logo.png rename to crates/tauri/icons/Square310x310Logo.png diff --git a/tauri/src-tauri/icons/Square44x44Logo.png b/crates/tauri/icons/Square44x44Logo.png similarity index 100% rename from tauri/src-tauri/icons/Square44x44Logo.png rename to crates/tauri/icons/Square44x44Logo.png diff --git a/tauri/src-tauri/icons/Square71x71Logo.png b/crates/tauri/icons/Square71x71Logo.png similarity index 100% rename from tauri/src-tauri/icons/Square71x71Logo.png rename to crates/tauri/icons/Square71x71Logo.png diff --git a/tauri/src-tauri/icons/Square89x89Logo.png b/crates/tauri/icons/Square89x89Logo.png similarity index 100% rename from tauri/src-tauri/icons/Square89x89Logo.png rename to crates/tauri/icons/Square89x89Logo.png diff --git a/tauri/src-tauri/icons/StoreLogo.png b/crates/tauri/icons/StoreLogo.png similarity index 100% rename from tauri/src-tauri/icons/StoreLogo.png rename to crates/tauri/icons/StoreLogo.png diff --git a/tauri/src-tauri/icons/icon.icns b/crates/tauri/icons/icon.icns similarity index 100% rename from tauri/src-tauri/icons/icon.icns rename to crates/tauri/icons/icon.icns diff --git a/tauri/src-tauri/icons/icon.ico b/crates/tauri/icons/icon.ico similarity index 100% rename from tauri/src-tauri/icons/icon.ico rename to crates/tauri/icons/icon.ico diff --git a/tauri/src-tauri/icons/icon.png b/crates/tauri/icons/icon.png similarity index 100% rename from tauri/src-tauri/icons/icon.png rename to crates/tauri/icons/icon.png diff --git a/crates/tauri/src/lib.rs b/crates/tauri/src/lib.rs new file mode 100644 index 0000000..a621317 --- /dev/null +++ b/crates/tauri/src/lib.rs @@ -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::>>()); + + 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"); +} diff --git a/crates/tauri/src/main.rs b/crates/tauri/src/main.rs new file mode 100644 index 0000000..48351fd --- /dev/null +++ b/crates/tauri/src/main.rs @@ -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() +} diff --git a/tauri/src-tauri/tauri.conf.json b/crates/tauri/tauri.conf.json similarity index 51% rename from tauri/src-tauri/tauri.conf.json rename to crates/tauri/tauri.conf.json index f3630be..8e441cc 100644 --- a/tauri/src-tauri/tauri.conf.json +++ b/crates/tauri/tauri.conf.json @@ -1,15 +1,20 @@ { - "productName": "tauri", - "version": "0.0.0", - "identifier": "org.p4pillon.krys4lide", + "productName": "clego-clean", + "version": "0.0.1", + "identifier": "clego.pharma.libre", "build": { - "frontendDist": "../src" + "beforeDevCommand": { + "script": "cargo run", + "cwd": "../clego" + }, + "devUrl": "http://localhost:3000", + "frontendDist": "axum://place.holder/" }, "app": { "withGlobalTauri": true, "windows": [ { - "title": "tauri", + "title": "clego-clean", "width": 800, "height": 600 } @@ -20,6 +25,9 @@ }, "bundle": { "active": true, + "resources": { + "../clego/assets/": "./assets/" + }, "targets": "all", "icon": [ "icons/32x32.png", @@ -29,4 +37,5 @@ "icons/icon.ico" ] } + } diff --git a/scripts/.gitkeep b/scripts/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tauri/.gitignore b/tauri/.gitignore deleted file mode 100644 index a547bf3..0000000 --- a/tauri/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -pnpm-debug.log* -lerna-debug.log* - -node_modules -dist -dist-ssr -*.local - -# Editor directories and files -.vscode/* -!.vscode/extensions.json -.idea -.DS_Store -*.suo -*.ntvs* -*.njsproj -*.sln -*.sw? diff --git a/tauri/README.md b/tauri/README.md deleted file mode 100644 index 441faf7..0000000 --- a/tauri/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Tauri + Vanilla - -This template should help get you started developing with Tauri in vanilla HTML, CSS and Javascript. - -## Recommended IDE Setup - -- [VS Code](https://code.visualstudio.com/) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer) diff --git a/tauri/src-tauri/Cargo.toml b/tauri/src-tauri/Cargo.toml deleted file mode 100644 index 2f37dbf..0000000 --- a/tauri/src-tauri/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "tauri" -version = "0.0.0" -description = "A Tauri App" -authors = ["you"] -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[build-dependencies] -tauri-build = { version = "2.0.0-beta", features = [] } - -[dependencies] -tauri = { version = "2.0.0-beta", features = [] } -tauri-plugin-shell = "2.0.0-beta" -serde = { version = "1", features = ["derive"] } -serde_json = "1" -futures = "0.3.30" -axum = "0.7.5" -tower = "0.4.13" - diff --git a/tauri/src-tauri/capabilities/default.json b/tauri/src-tauri/capabilities/default.json deleted file mode 100644 index e14ca1d..0000000 --- a/tauri/src-tauri/capabilities/default.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "$schema": "../gen/schemas/desktop-schema.json", - "identifier": "default", - "description": "Capability for the main window", - "windows": ["main"], - "permissions": [ - "path:default", - "event:default", - "window:default", - "app:default", - "image:default", - "resources:default", - "menu:default", - "tray:default", - "shell:allow-open" - ] -} diff --git a/tauri/src-tauri/src/main.rs b/tauri/src-tauri/src/main.rs deleted file mode 100644 index fc4ca4c..0000000 --- a/tauri/src-tauri/src/main.rs +++ /dev/null @@ -1,90 +0,0 @@ -// Prevents additional console window on Windows in release, DO NOT REMOVE!! -#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] - -use futures::executor::block_on; - -use tauri::http::{Response, Uri}; - -// Enable the services methods on Axum Router -use tower::{Service, ServiceExt}; - - -/*** ROUTEUR ***/ - -async fn route_test() -> &'static str { - "Hello, `/test/` !" -} - -async fn route_root() -> &'static str { - "Hello, `/` !" -} - -async fn route_fallback(uri: axum::http::Uri) -> (axum::http::StatusCode, String) { - (axum::http::StatusCode::NOT_FOUND, format!("No route for {uri}")) -} - -/*** TAURI ***/ - -fn build_axum_request(uri: Uri) -> axum::http::Request { - axum::http::Request::builder() - .uri(uri.to_string()) - .body(axum::body::Body::empty()) - .unwrap() -} - -async fn call_axum(uri: Uri) -> axum::http::Response { - let mut routeur: axum::Router = axum::Router::new() - .route("/test", axum::routing::get(route_test)) - .route("/", axum::routing::get(route_root)) - .fallback(route_fallback); - - let request = build_axum_request(uri); - - routeur - .as_service() - .ready() - .await - .unwrap() - .call(request) - .await - .unwrap() -} - -async fn build_tauri_response(axum_response: axum::http::Response) -> Response> { - let (parts, body) = axum_response.into_parts(); - - let body_bytes = axum::body::to_bytes(body, usize::MAX).await.unwrap().to_vec(); - - Response::builder() - .status(parts.status.as_u16()) - .header("Content-Type", "text/html") - .body(body_bytes) - .unwrap() -} - -// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command -#[tauri::command] -fn greet(name: &str) -> String { - format!("Hello, {}! You've been greeted from Rust!", name) -} - -fn main() { - tauri::Builder::default() - // Tauri example using the tauri-plugin-shell - .plugin(tauri_plugin_shell::init()) - .invoke_handler(tauri::generate_handler![greet]) - // Handling of the clego:// protocol through Axum - .register_asynchronous_uri_scheme_protocol("clego", |_app, request, responder| { - let uri = request.uri().clone(); - - std::thread::spawn(move || { - // Open this thread to execute asynchronous code avoid blocking the main thread while waiting for the response - let axum_response = block_on(call_axum(uri)); - let response = block_on(build_tauri_response(axum_response)); - responder.respond(response); - }); - }) - // Tauri execution - .run(tauri::generate_context!()) - .expect("error while running tauri application"); -} diff --git a/tauri/src/assets/javascript.svg b/tauri/src/assets/javascript.svg deleted file mode 100644 index f9abb2b..0000000 --- a/tauri/src/assets/javascript.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/tauri/src/assets/tauri.svg b/tauri/src/assets/tauri.svg deleted file mode 100644 index 31b62c9..0000000 --- a/tauri/src/assets/tauri.svg +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/tauri/src/index.html b/tauri/src/index.html deleted file mode 100644 index ed1fc94..0000000 --- a/tauri/src/index.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - Tauri App - - - - -
-

Welcome to Tauri!

- - - -

Click on the Tauri logo to learn more about the framework

- -
- - -
- -

- - Open `clego://test` - Open `clego://0.0.0.0/test` - Open `clego://0.0.0.0/foo` -
- - diff --git a/tauri/src/main.js b/tauri/src/main.js deleted file mode 100644 index 9a7530b..0000000 --- a/tauri/src/main.js +++ /dev/null @@ -1,18 +0,0 @@ -const { invoke } = window.__TAURI__.core; - -let greetInputEl; -let greetMsgEl; - -async function greet() { - // Learn more about Tauri commands at https://tauri.app/v1/guides/features/command - greetMsgEl.textContent = await invoke("greet", { name: greetInputEl.value }); -} - -window.addEventListener("DOMContentLoaded", () => { - greetInputEl = document.querySelector("#greet-input"); - greetMsgEl = document.querySelector("#greet-msg"); - document.querySelector("#greet-form").addEventListener("submit", (e) => { - e.preventDefault(); - greet(); - }); -}); diff --git a/tauri/src/styles.css b/tauri/src/styles.css deleted file mode 100644 index e57b8ac..0000000 --- a/tauri/src/styles.css +++ /dev/null @@ -1,112 +0,0 @@ -.logo.vanilla:hover { - filter: drop-shadow(0 0 2em #ffe21c); -} -:root { - font-family: Inter, Avenir, Helvetica, Arial, sans-serif; - font-size: 16px; - line-height: 24px; - font-weight: 400; - - color: #0f0f0f; - background-color: #f6f6f6; - - font-synthesis: none; - text-rendering: optimizeLegibility; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; - -webkit-text-size-adjust: 100%; -} - -.container { - margin: 0; - padding-top: 10vh; - display: flex; - flex-direction: column; - justify-content: center; - text-align: center; -} - -.logo { - height: 6em; - padding: 1.5em; - will-change: filter; - transition: 0.75s; -} - -.logo.tauri:hover { - filter: drop-shadow(0 0 2em #24c8db); -} - -.row { - display: flex; - justify-content: center; -} - -a { - font-weight: 500; - color: #646cff; - text-decoration: inherit; -} - -a:hover { - color: #535bf2; -} - -h1 { - text-align: center; -} - -input, -button { - border-radius: 8px; - border: 1px solid transparent; - padding: 0.6em 1.2em; - font-size: 1em; - font-weight: 500; - font-family: inherit; - color: #0f0f0f; - background-color: #ffffff; - transition: border-color 0.25s; - box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2); -} - -button { - cursor: pointer; -} - -button:hover { - border-color: #396cd8; -} -button:active { - border-color: #396cd8; - background-color: #e8e8e8; -} - -input, -button { - outline: none; -} - -#greet-input { - margin-right: 5px; -} - -@media (prefers-color-scheme: dark) { - :root { - color: #f6f6f6; - background-color: #2f2f2f; - } - - a:hover { - color: #24c8db; - } - - input, - button { - color: #ffffff; - background-color: #0f0f0f98; - } - button:active { - background-color: #0f0f0f69; - } -} From 1f57b70cef8427daa352f523832a9c8f82f7b1fe Mon Sep 17 00:00:00 2001 From: "t.lettermann" Date: Wed, 24 Jul 2024 11:15:14 +0200 Subject: [PATCH 02/21] feat: move packages to root and remove unused dependencies --- Cargo.toml | 4 ++-- {crates/clego => clego}/.gitignore | 0 {crates/clego => clego}/Cargo.toml | 0 {crates/clego => clego}/assets/js/htmx.min.js.js | 0 {crates/clego => clego}/src/lib.rs | 0 {crates/clego => clego}/src/main.rs | 0 {crates/clego => clego}/src/templates/hello.rs | 0 {crates/clego => clego}/src/templates/index.rs | 0 {crates/clego => clego}/src/templates/mod.rs | 0 {crates/clego => clego}/templates/base.html | 0 {crates/clego => clego}/templates/hello.html | 0 {crates/clego => clego}/templates/index.html | 0 {crates/tauri => tauri}/.gitignore | 0 {crates/tauri => tauri}/Cargo.toml | 1 - {crates/tauri => tauri}/build.rs | 0 {crates/tauri => tauri}/icons/128x128.png | Bin {crates/tauri => tauri}/icons/128x128@2x.png | Bin {crates/tauri => tauri}/icons/32x32.png | Bin {crates/tauri => tauri}/icons/Square107x107Logo.png | Bin {crates/tauri => tauri}/icons/Square142x142Logo.png | Bin {crates/tauri => tauri}/icons/Square150x150Logo.png | Bin {crates/tauri => tauri}/icons/Square284x284Logo.png | Bin {crates/tauri => tauri}/icons/Square30x30Logo.png | Bin {crates/tauri => tauri}/icons/Square310x310Logo.png | Bin {crates/tauri => tauri}/icons/Square44x44Logo.png | Bin {crates/tauri => tauri}/icons/Square71x71Logo.png | Bin {crates/tauri => tauri}/icons/Square89x89Logo.png | Bin {crates/tauri => tauri}/icons/StoreLogo.png | Bin {crates/tauri => tauri}/icons/icon.icns | Bin {crates/tauri => tauri}/icons/icon.ico | Bin {crates/tauri => tauri}/icons/icon.png | Bin {crates/tauri => tauri}/src/lib.rs | 0 {crates/tauri => tauri}/src/main.rs | 0 {crates/tauri => tauri}/tauri.conf.json | 0 34 files changed, 2 insertions(+), 3 deletions(-) rename {crates/clego => clego}/.gitignore (100%) rename {crates/clego => clego}/Cargo.toml (100%) rename {crates/clego => clego}/assets/js/htmx.min.js.js (100%) rename {crates/clego => clego}/src/lib.rs (100%) rename {crates/clego => clego}/src/main.rs (100%) rename {crates/clego => clego}/src/templates/hello.rs (100%) rename {crates/clego => clego}/src/templates/index.rs (100%) rename {crates/clego => clego}/src/templates/mod.rs (100%) rename {crates/clego => clego}/templates/base.html (100%) rename {crates/clego => clego}/templates/hello.html (100%) rename {crates/clego => clego}/templates/index.html (100%) rename {crates/tauri => tauri}/.gitignore (100%) rename {crates/tauri => tauri}/Cargo.toml (95%) rename {crates/tauri => tauri}/build.rs (100%) rename {crates/tauri => tauri}/icons/128x128.png (100%) rename {crates/tauri => tauri}/icons/128x128@2x.png (100%) rename {crates/tauri => tauri}/icons/32x32.png (100%) rename {crates/tauri => tauri}/icons/Square107x107Logo.png (100%) rename {crates/tauri => tauri}/icons/Square142x142Logo.png (100%) rename {crates/tauri => tauri}/icons/Square150x150Logo.png (100%) rename {crates/tauri => tauri}/icons/Square284x284Logo.png (100%) rename {crates/tauri => tauri}/icons/Square30x30Logo.png (100%) rename {crates/tauri => tauri}/icons/Square310x310Logo.png (100%) rename {crates/tauri => tauri}/icons/Square44x44Logo.png (100%) rename {crates/tauri => tauri}/icons/Square71x71Logo.png (100%) rename {crates/tauri => tauri}/icons/Square89x89Logo.png (100%) rename {crates/tauri => tauri}/icons/StoreLogo.png (100%) rename {crates/tauri => tauri}/icons/icon.icns (100%) rename {crates/tauri => tauri}/icons/icon.ico (100%) rename {crates/tauri => tauri}/icons/icon.png (100%) rename {crates/tauri => tauri}/src/lib.rs (100%) rename {crates/tauri => tauri}/src/main.rs (100%) rename {crates/tauri => tauri}/tauri.conf.json (100%) diff --git a/Cargo.toml b/Cargo.toml index 8507ae3..a55175c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" members = [ - "crates/clego", - "crates/tauri" + "clego", + "tauri" ] diff --git a/crates/clego/.gitignore b/clego/.gitignore similarity index 100% rename from crates/clego/.gitignore rename to clego/.gitignore diff --git a/crates/clego/Cargo.toml b/clego/Cargo.toml similarity index 100% rename from crates/clego/Cargo.toml rename to clego/Cargo.toml diff --git a/crates/clego/assets/js/htmx.min.js.js b/clego/assets/js/htmx.min.js.js similarity index 100% rename from crates/clego/assets/js/htmx.min.js.js rename to clego/assets/js/htmx.min.js.js diff --git a/crates/clego/src/lib.rs b/clego/src/lib.rs similarity index 100% rename from crates/clego/src/lib.rs rename to clego/src/lib.rs diff --git a/crates/clego/src/main.rs b/clego/src/main.rs similarity index 100% rename from crates/clego/src/main.rs rename to clego/src/main.rs diff --git a/crates/clego/src/templates/hello.rs b/clego/src/templates/hello.rs similarity index 100% rename from crates/clego/src/templates/hello.rs rename to clego/src/templates/hello.rs diff --git a/crates/clego/src/templates/index.rs b/clego/src/templates/index.rs similarity index 100% rename from crates/clego/src/templates/index.rs rename to clego/src/templates/index.rs diff --git a/crates/clego/src/templates/mod.rs b/clego/src/templates/mod.rs similarity index 100% rename from crates/clego/src/templates/mod.rs rename to clego/src/templates/mod.rs diff --git a/crates/clego/templates/base.html b/clego/templates/base.html similarity index 100% rename from crates/clego/templates/base.html rename to clego/templates/base.html diff --git a/crates/clego/templates/hello.html b/clego/templates/hello.html similarity index 100% rename from crates/clego/templates/hello.html rename to clego/templates/hello.html diff --git a/crates/clego/templates/index.html b/clego/templates/index.html similarity index 100% rename from crates/clego/templates/index.html rename to clego/templates/index.html diff --git a/crates/tauri/.gitignore b/tauri/.gitignore similarity index 100% rename from crates/tauri/.gitignore rename to tauri/.gitignore diff --git a/crates/tauri/Cargo.toml b/tauri/Cargo.toml similarity index 95% rename from crates/tauri/Cargo.toml rename to tauri/Cargo.toml index 640a82a..6e32742 100644 --- a/crates/tauri/Cargo.toml +++ b/tauri/Cargo.toml @@ -18,6 +18,5 @@ tauri = { version = "2.0.0-beta", features = ["devtools"] } tower = "0.4.13" clego = { path = "../clego" } -include_dir = "0.7.4" tokio = "1.39.1" diff --git a/crates/tauri/build.rs b/tauri/build.rs similarity index 100% rename from crates/tauri/build.rs rename to tauri/build.rs diff --git a/crates/tauri/icons/128x128.png b/tauri/icons/128x128.png similarity index 100% rename from crates/tauri/icons/128x128.png rename to tauri/icons/128x128.png diff --git a/crates/tauri/icons/128x128@2x.png b/tauri/icons/128x128@2x.png similarity index 100% rename from crates/tauri/icons/128x128@2x.png rename to tauri/icons/128x128@2x.png diff --git a/crates/tauri/icons/32x32.png b/tauri/icons/32x32.png similarity index 100% rename from crates/tauri/icons/32x32.png rename to tauri/icons/32x32.png diff --git a/crates/tauri/icons/Square107x107Logo.png b/tauri/icons/Square107x107Logo.png similarity index 100% rename from crates/tauri/icons/Square107x107Logo.png rename to tauri/icons/Square107x107Logo.png diff --git a/crates/tauri/icons/Square142x142Logo.png b/tauri/icons/Square142x142Logo.png similarity index 100% rename from crates/tauri/icons/Square142x142Logo.png rename to tauri/icons/Square142x142Logo.png diff --git a/crates/tauri/icons/Square150x150Logo.png b/tauri/icons/Square150x150Logo.png similarity index 100% rename from crates/tauri/icons/Square150x150Logo.png rename to tauri/icons/Square150x150Logo.png diff --git a/crates/tauri/icons/Square284x284Logo.png b/tauri/icons/Square284x284Logo.png similarity index 100% rename from crates/tauri/icons/Square284x284Logo.png rename to tauri/icons/Square284x284Logo.png diff --git a/crates/tauri/icons/Square30x30Logo.png b/tauri/icons/Square30x30Logo.png similarity index 100% rename from crates/tauri/icons/Square30x30Logo.png rename to tauri/icons/Square30x30Logo.png diff --git a/crates/tauri/icons/Square310x310Logo.png b/tauri/icons/Square310x310Logo.png similarity index 100% rename from crates/tauri/icons/Square310x310Logo.png rename to tauri/icons/Square310x310Logo.png diff --git a/crates/tauri/icons/Square44x44Logo.png b/tauri/icons/Square44x44Logo.png similarity index 100% rename from crates/tauri/icons/Square44x44Logo.png rename to tauri/icons/Square44x44Logo.png diff --git a/crates/tauri/icons/Square71x71Logo.png b/tauri/icons/Square71x71Logo.png similarity index 100% rename from crates/tauri/icons/Square71x71Logo.png rename to tauri/icons/Square71x71Logo.png diff --git a/crates/tauri/icons/Square89x89Logo.png b/tauri/icons/Square89x89Logo.png similarity index 100% rename from crates/tauri/icons/Square89x89Logo.png rename to tauri/icons/Square89x89Logo.png diff --git a/crates/tauri/icons/StoreLogo.png b/tauri/icons/StoreLogo.png similarity index 100% rename from crates/tauri/icons/StoreLogo.png rename to tauri/icons/StoreLogo.png diff --git a/crates/tauri/icons/icon.icns b/tauri/icons/icon.icns similarity index 100% rename from crates/tauri/icons/icon.icns rename to tauri/icons/icon.icns diff --git a/crates/tauri/icons/icon.ico b/tauri/icons/icon.ico similarity index 100% rename from crates/tauri/icons/icon.ico rename to tauri/icons/icon.ico diff --git a/crates/tauri/icons/icon.png b/tauri/icons/icon.png similarity index 100% rename from crates/tauri/icons/icon.png rename to tauri/icons/icon.png diff --git a/crates/tauri/src/lib.rs b/tauri/src/lib.rs similarity index 100% rename from crates/tauri/src/lib.rs rename to tauri/src/lib.rs diff --git a/crates/tauri/src/main.rs b/tauri/src/main.rs similarity index 100% rename from crates/tauri/src/main.rs rename to tauri/src/main.rs diff --git a/crates/tauri/tauri.conf.json b/tauri/tauri.conf.json similarity index 100% rename from crates/tauri/tauri.conf.json rename to tauri/tauri.conf.json From 18758ff2fe28d082048d9342d1d4c51d031cd136 Mon Sep 17 00:00:00 2001 From: theo Date: Wed, 24 Jul 2024 11:23:41 +0200 Subject: [PATCH 03/21] fix: remove useless gitignore files --- .gitignore | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/.gitignore b/.gitignore index da09066..7e3d3ac 100644 --- a/.gitignore +++ b/.gitignore @@ -10,20 +10,6 @@ target/ # MSVC Windows builds of rustc generate these, which store debugging information *.pdb -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -pnpm-debug.log* -lerna-debug.log* - -node_modules -dist -dist-ssr -*.local - # Editor directories and files .vscode/* !.vscode/extensions.json @@ -35,4 +21,3 @@ dist-ssr *.sln *.sw? - From 86a6d2b9d39ba1f0fa17648463713ba3c6b55359 Mon Sep 17 00:00:00 2001 From: theo Date: Wed, 24 Jul 2024 11:58:03 +0200 Subject: [PATCH 04/21] fix: revert back to crates dir layout --- Cargo.lock | 24 +-------- Cargo.toml | 4 +- {clego => crates/clego}/.gitignore | 0 {clego => crates/clego}/Cargo.toml | 0 .../clego}/assets/js/htmx.min.js.js | 0 {clego => crates/clego}/src/lib.rs | 0 {clego => crates/clego}/src/main.rs | 0 .../clego}/src/templates/hello.rs | 0 .../clego}/src/templates/index.rs | 0 {clego => crates/clego}/src/templates/mod.rs | 0 {clego => crates/clego}/templates/base.html | 0 {clego => crates/clego}/templates/hello.html | 0 {clego => crates/clego}/templates/index.html | 0 {tauri => crates/tauri}/.gitignore | 0 {tauri => crates/tauri}/Cargo.toml | 0 {tauri => crates/tauri}/build.rs | 0 {tauri => crates/tauri}/icons/128x128.png | Bin {tauri => crates/tauri}/icons/128x128@2x.png | Bin {tauri => crates/tauri}/icons/32x32.png | Bin .../tauri}/icons/Square107x107Logo.png | Bin .../tauri}/icons/Square142x142Logo.png | Bin .../tauri}/icons/Square150x150Logo.png | Bin .../tauri}/icons/Square284x284Logo.png | Bin .../tauri}/icons/Square30x30Logo.png | Bin .../tauri}/icons/Square310x310Logo.png | Bin .../tauri}/icons/Square44x44Logo.png | Bin .../tauri}/icons/Square71x71Logo.png | Bin .../tauri}/icons/Square89x89Logo.png | Bin {tauri => crates/tauri}/icons/StoreLogo.png | Bin {tauri => crates/tauri}/icons/icon.icns | Bin {tauri => crates/tauri}/icons/icon.ico | Bin {tauri => crates/tauri}/icons/icon.png | Bin {tauri => crates/tauri}/src/lib.rs | 51 +++++++++--------- {tauri => crates/tauri}/src/main.rs | 0 {tauri => crates/tauri}/tauri.conf.json | 0 35 files changed, 31 insertions(+), 48 deletions(-) rename {clego => crates/clego}/.gitignore (100%) rename {clego => crates/clego}/Cargo.toml (100%) rename {clego => crates/clego}/assets/js/htmx.min.js.js (100%) rename {clego => crates/clego}/src/lib.rs (100%) rename {clego => crates/clego}/src/main.rs (100%) rename {clego => crates/clego}/src/templates/hello.rs (100%) rename {clego => crates/clego}/src/templates/index.rs (100%) rename {clego => crates/clego}/src/templates/mod.rs (100%) rename {clego => crates/clego}/templates/base.html (100%) rename {clego => crates/clego}/templates/hello.html (100%) rename {clego => crates/clego}/templates/index.html (100%) rename {tauri => crates/tauri}/.gitignore (100%) rename {tauri => crates/tauri}/Cargo.toml (100%) rename {tauri => crates/tauri}/build.rs (100%) rename {tauri => crates/tauri}/icons/128x128.png (100%) rename {tauri => crates/tauri}/icons/128x128@2x.png (100%) rename {tauri => crates/tauri}/icons/32x32.png (100%) rename {tauri => crates/tauri}/icons/Square107x107Logo.png (100%) rename {tauri => crates/tauri}/icons/Square142x142Logo.png (100%) rename {tauri => crates/tauri}/icons/Square150x150Logo.png (100%) rename {tauri => crates/tauri}/icons/Square284x284Logo.png (100%) rename {tauri => crates/tauri}/icons/Square30x30Logo.png (100%) rename {tauri => crates/tauri}/icons/Square310x310Logo.png (100%) rename {tauri => crates/tauri}/icons/Square44x44Logo.png (100%) rename {tauri => crates/tauri}/icons/Square71x71Logo.png (100%) rename {tauri => crates/tauri}/icons/Square89x89Logo.png (100%) rename {tauri => crates/tauri}/icons/StoreLogo.png (100%) rename {tauri => crates/tauri}/icons/icon.icns (100%) rename {tauri => crates/tauri}/icons/icon.ico (100%) rename {tauri => crates/tauri}/icons/icon.png (100%) rename {tauri => crates/tauri}/src/lib.rs (51%) rename {tauri => crates/tauri}/src/main.rs (100%) rename {tauri => crates/tauri}/tauri.conf.json (100%) diff --git a/Cargo.lock b/Cargo.lock index fec0d24..ad838f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1487,25 +1487,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "include_dir" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "923d117408f1e49d914f1a379a309cffe4f18c05cf4e3d12e613a15fc81bd0dd" -dependencies = [ - "include_dir_macros", -] - -[[package]] -name = "include_dir_macros" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cab85a7ed0bd5f0e76d93846e0147172bed2e2d3f859bcc33a8d9699cad1a75" -dependencies = [ - "proc-macro2", - "quote", -] - [[package]] name = "indexmap" version = "1.9.3" @@ -2101,9 +2082,9 @@ dependencies = [ [[package]] name = "object" -version = "0.36.1" +version = "0.36.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce" +checksum = "3f203fa8daa7bb185f760ae12bd8e097f63d17041dcdcaf675ac54cdf863170e" dependencies = [ "memchr", ] @@ -3270,7 +3251,6 @@ version = "0.1.0" dependencies = [ "axum", "clego", - "include_dir", "tauri", "tauri-build", "tokio", diff --git a/Cargo.toml b/Cargo.toml index a55175c..8507ae3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" members = [ - "clego", - "tauri" + "crates/clego", + "crates/tauri" ] diff --git a/clego/.gitignore b/crates/clego/.gitignore similarity index 100% rename from clego/.gitignore rename to crates/clego/.gitignore diff --git a/clego/Cargo.toml b/crates/clego/Cargo.toml similarity index 100% rename from clego/Cargo.toml rename to crates/clego/Cargo.toml diff --git a/clego/assets/js/htmx.min.js.js b/crates/clego/assets/js/htmx.min.js.js similarity index 100% rename from clego/assets/js/htmx.min.js.js rename to crates/clego/assets/js/htmx.min.js.js diff --git a/clego/src/lib.rs b/crates/clego/src/lib.rs similarity index 100% rename from clego/src/lib.rs rename to crates/clego/src/lib.rs diff --git a/clego/src/main.rs b/crates/clego/src/main.rs similarity index 100% rename from clego/src/main.rs rename to crates/clego/src/main.rs diff --git a/clego/src/templates/hello.rs b/crates/clego/src/templates/hello.rs similarity index 100% rename from clego/src/templates/hello.rs rename to crates/clego/src/templates/hello.rs diff --git a/clego/src/templates/index.rs b/crates/clego/src/templates/index.rs similarity index 100% rename from clego/src/templates/index.rs rename to crates/clego/src/templates/index.rs diff --git a/clego/src/templates/mod.rs b/crates/clego/src/templates/mod.rs similarity index 100% rename from clego/src/templates/mod.rs rename to crates/clego/src/templates/mod.rs diff --git a/clego/templates/base.html b/crates/clego/templates/base.html similarity index 100% rename from clego/templates/base.html rename to crates/clego/templates/base.html diff --git a/clego/templates/hello.html b/crates/clego/templates/hello.html similarity index 100% rename from clego/templates/hello.html rename to crates/clego/templates/hello.html diff --git a/clego/templates/index.html b/crates/clego/templates/index.html similarity index 100% rename from clego/templates/index.html rename to crates/clego/templates/index.html diff --git a/tauri/.gitignore b/crates/tauri/.gitignore similarity index 100% rename from tauri/.gitignore rename to crates/tauri/.gitignore diff --git a/tauri/Cargo.toml b/crates/tauri/Cargo.toml similarity index 100% rename from tauri/Cargo.toml rename to crates/tauri/Cargo.toml diff --git a/tauri/build.rs b/crates/tauri/build.rs similarity index 100% rename from tauri/build.rs rename to crates/tauri/build.rs diff --git a/tauri/icons/128x128.png b/crates/tauri/icons/128x128.png similarity index 100% rename from tauri/icons/128x128.png rename to crates/tauri/icons/128x128.png diff --git a/tauri/icons/128x128@2x.png b/crates/tauri/icons/128x128@2x.png similarity index 100% rename from tauri/icons/128x128@2x.png rename to crates/tauri/icons/128x128@2x.png diff --git a/tauri/icons/32x32.png b/crates/tauri/icons/32x32.png similarity index 100% rename from tauri/icons/32x32.png rename to crates/tauri/icons/32x32.png diff --git a/tauri/icons/Square107x107Logo.png b/crates/tauri/icons/Square107x107Logo.png similarity index 100% rename from tauri/icons/Square107x107Logo.png rename to crates/tauri/icons/Square107x107Logo.png diff --git a/tauri/icons/Square142x142Logo.png b/crates/tauri/icons/Square142x142Logo.png similarity index 100% rename from tauri/icons/Square142x142Logo.png rename to crates/tauri/icons/Square142x142Logo.png diff --git a/tauri/icons/Square150x150Logo.png b/crates/tauri/icons/Square150x150Logo.png similarity index 100% rename from tauri/icons/Square150x150Logo.png rename to crates/tauri/icons/Square150x150Logo.png diff --git a/tauri/icons/Square284x284Logo.png b/crates/tauri/icons/Square284x284Logo.png similarity index 100% rename from tauri/icons/Square284x284Logo.png rename to crates/tauri/icons/Square284x284Logo.png diff --git a/tauri/icons/Square30x30Logo.png b/crates/tauri/icons/Square30x30Logo.png similarity index 100% rename from tauri/icons/Square30x30Logo.png rename to crates/tauri/icons/Square30x30Logo.png diff --git a/tauri/icons/Square310x310Logo.png b/crates/tauri/icons/Square310x310Logo.png similarity index 100% rename from tauri/icons/Square310x310Logo.png rename to crates/tauri/icons/Square310x310Logo.png diff --git a/tauri/icons/Square44x44Logo.png b/crates/tauri/icons/Square44x44Logo.png similarity index 100% rename from tauri/icons/Square44x44Logo.png rename to crates/tauri/icons/Square44x44Logo.png diff --git a/tauri/icons/Square71x71Logo.png b/crates/tauri/icons/Square71x71Logo.png similarity index 100% rename from tauri/icons/Square71x71Logo.png rename to crates/tauri/icons/Square71x71Logo.png diff --git a/tauri/icons/Square89x89Logo.png b/crates/tauri/icons/Square89x89Logo.png similarity index 100% rename from tauri/icons/Square89x89Logo.png rename to crates/tauri/icons/Square89x89Logo.png diff --git a/tauri/icons/StoreLogo.png b/crates/tauri/icons/StoreLogo.png similarity index 100% rename from tauri/icons/StoreLogo.png rename to crates/tauri/icons/StoreLogo.png diff --git a/tauri/icons/icon.icns b/crates/tauri/icons/icon.icns similarity index 100% rename from tauri/icons/icon.icns rename to crates/tauri/icons/icon.icns diff --git a/tauri/icons/icon.ico b/crates/tauri/icons/icon.ico similarity index 100% rename from tauri/icons/icon.ico rename to crates/tauri/icons/icon.ico diff --git a/tauri/icons/icon.png b/crates/tauri/icons/icon.png similarity index 100% rename from tauri/icons/icon.png rename to crates/tauri/icons/icon.png diff --git a/tauri/src/lib.rs b/crates/tauri/src/lib.rs similarity index 51% rename from tauri/src/lib.rs rename to crates/tauri/src/lib.rs index a621317..446fd28 100644 --- a/tauri/src/lib.rs +++ b/crates/tauri/src/lib.rs @@ -5,10 +5,37 @@ 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) @@ -27,30 +54,6 @@ pub fn run() { 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); }); }) diff --git a/tauri/src/main.rs b/crates/tauri/src/main.rs similarity index 100% rename from tauri/src/main.rs rename to crates/tauri/src/main.rs diff --git a/tauri/tauri.conf.json b/crates/tauri/tauri.conf.json similarity index 100% rename from tauri/tauri.conf.json rename to crates/tauri/tauri.conf.json From 0e8514d90605d4a8c18c513503cbba57622a59ed Mon Sep 17 00:00:00 2001 From: theo Date: Wed, 24 Jul 2024 14:08:58 +0200 Subject: [PATCH 05/21] fix: bump dependency for clego --- crates/clego/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/clego/Cargo.toml b/crates/clego/Cargo.toml index 10760c3..f06528b 100644 --- a/crates/clego/Cargo.toml +++ b/crates/clego/Cargo.toml @@ -7,6 +7,6 @@ edition = "2021" askama = "0.12.1" askama_axum = "0.4.0" axum = "0.7.5" -tokio = { version = "1.38.1", features = ["macros", "rt-multi-thread"] } +tokio = { version = "1.39.1", features = ["macros", "rt-multi-thread"] } tower-http = { version = "0.5.2", features = ["fs"] } From c2b4264f32e5e7ccda4d67dd530fd90d01a9b169 Mon Sep 17 00:00:00 2001 From: theo Date: Wed, 24 Jul 2024 14:21:37 +0200 Subject: [PATCH 06/21] extract protocol logic to external function --- crates/tauri/src/lib.rs | 52 ++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/crates/tauri/src/lib.rs b/crates/tauri/src/lib.rs index 446fd28..19ca565 100644 --- a/crates/tauri/src/lib.rs +++ b/crates/tauri/src/lib.rs @@ -2,40 +2,43 @@ use core::panic; use std::sync::Arc; use tauri::{path::BaseDirectory, Manager}; -use tokio::sync::Mutex; +use tokio::sync::{Mutex, MutexGuard}; 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); +async fn process_tauri_request( + request: tauri::http::Request>, + mut router: MutexGuard<'_, axum::Router>, +) -> tauri::http::Response> { + 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 { - Ok(ready_service) => ready_service.call(request).await, - Err(_error) => panic!("Failed to get ready service"), -}; + 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 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 (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); + let response = tauri::http::Response::from_parts(parts, body); + + response } #[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) @@ -45,6 +48,8 @@ pub fn run() { 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); Ok(()) @@ -53,7 +58,10 @@ pub fn run() { let router = Arc::clone(&app.state::>>()); tauri::async_runtime::spawn(async move { - let mut router = router.lock().await; + let router = router.lock().await; + + let response = process_tauri_request(request, router).await; + responder.respond(response); }); }) From d8f3c276c049ceb981a276a212c64f43202767e2 Mon Sep 17 00:00:00 2001 From: theo Date: Wed, 24 Jul 2024 15:00:14 +0200 Subject: [PATCH 07/21] feat: remove reference to clego inside tauri app --- Cargo.lock | 24 ++++++++++++------------ crates/tauri/Cargo.toml | 4 ++-- crates/tauri/src/main.rs | 2 +- crates/tauri/tauri.conf.json | 6 +++--- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ad838f5..d706ed2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2161,6 +2161,18 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "pharmacie-desktop" +version = "0.1.0" +dependencies = [ + "axum", + "clego", + "tauri", + "tauri-build", + "tokio", + "tower", +] + [[package]] name = "phf" version = "0.8.0" @@ -3245,18 +3257,6 @@ dependencies = [ "walkdir", ] -[[package]] -name = "tauri-clego" -version = "0.1.0" -dependencies = [ - "axum", - "clego", - "tauri", - "tauri-build", - "tokio", - "tower", -] - [[package]] name = "tauri-codegen" version = "2.0.0-beta.19" diff --git a/crates/tauri/Cargo.toml b/crates/tauri/Cargo.toml index 6e32742..1bca76e 100644 --- a/crates/tauri/Cargo.toml +++ b/crates/tauri/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "tauri-clego" +name = "pharmacie-desktop" version = "0.1.0" description = "Un logiciel de pharmacie libre et open-source." authors = ["p4pillon"] edition = "2021" [lib] -name = "clego_lib" +name = "pharmacie_desktop_lib" crate-type = ["lib", "cdylib", "staticlib"] [build-dependencies] diff --git a/crates/tauri/src/main.rs b/crates/tauri/src/main.rs index 48351fd..991f759 100644 --- a/crates/tauri/src/main.rs +++ b/crates/tauri/src/main.rs @@ -2,5 +2,5 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] fn main() { - clego_lib::run() + pharmacie_desktop_lib::run() } diff --git a/crates/tauri/tauri.conf.json b/crates/tauri/tauri.conf.json index 8e441cc..9282f10 100644 --- a/crates/tauri/tauri.conf.json +++ b/crates/tauri/tauri.conf.json @@ -1,7 +1,7 @@ { - "productName": "clego-clean", + "productName": "Logiciel Pharma", "version": "0.0.1", - "identifier": "clego.pharma.libre", + "identifier": "p4pillon.pharma.desktop", "build": { "beforeDevCommand": { "script": "cargo run", @@ -14,7 +14,7 @@ "withGlobalTauri": true, "windows": [ { - "title": "clego-clean", + "title": "Logiciel Pharma", "width": 800, "height": 600 } From b807e78ac39a30bc52994380615069cd6d095f6f Mon Sep 17 00:00:00 2001 From: theo Date: Wed, 24 Jul 2024 15:17:47 +0200 Subject: [PATCH 08/21] remove unecessary features --- crates/tauri/Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/tauri/Cargo.toml b/crates/tauri/Cargo.toml index 1bca76e..a9d2832 100644 --- a/crates/tauri/Cargo.toml +++ b/crates/tauri/Cargo.toml @@ -14,9 +14,9 @@ tauri-build = { version = "2.0.0-beta", features = [] } [dependencies] axum = "0.7.5" -tauri = { version = "2.0.0-beta", features = ["devtools"] } +tauri = { version = "2.0.0-beta", features = [] } tower = "0.4.13" - -clego = { path = "../clego" } tokio = "1.39.1" +clego = { path = "../clego" } + From ff2c84fb33a79863f0c783d30e1322481328f997 Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Wed, 24 Jul 2024 20:36:16 +0200 Subject: [PATCH 09/21] fix: base assets path on the manifest dir when running the webserver manually --- crates/clego/src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/clego/src/main.rs b/crates/clego/src/main.rs index bfbfd83..00b4fdf 100644 --- a/crates/clego/src/main.rs +++ b/crates/clego/src/main.rs @@ -1,9 +1,12 @@ use ::clego::get_router; use std::path::Path; +use std::env; #[tokio::main] async fn main() { - let router = get_router(Path::new("/assets")); + 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(); From 7d41fbb5198a39e13e35e04c29ed0be5465b9b98 Mon Sep 17 00:00:00 2001 From: theo Date: Wed, 24 Jul 2024 21:59:24 +0200 Subject: [PATCH 10/21] fix: change project naming, create dummy sesame-vitale project --- Cargo.lock | 50 ++++++++++-------- Cargo.toml | 5 +- crates/{clego => app}/.gitignore | 0 crates/{clego => app}/Cargo.toml | 2 +- .../{clego => app}/assets/js/htmx.min.js.js | 0 crates/{clego => app}/src/lib.rs | 0 crates/{clego => app}/src/main.rs | 2 +- crates/{clego => app}/src/templates/hello.rs | 0 crates/{clego => app}/src/templates/index.rs | 0 crates/{clego => app}/src/templates/mod.rs | 0 crates/{clego => app}/templates/base.html | 0 crates/{clego => app}/templates/hello.html | 0 crates/{clego => app}/templates/index.html | 0 crates/{tauri => desktop}/.gitignore | 0 crates/{tauri => desktop}/Cargo.toml | 4 +- crates/{tauri => desktop}/build.rs | 0 crates/{tauri => desktop}/icons/128x128.png | Bin .../{tauri => desktop}/icons/128x128@2x.png | Bin crates/{tauri => desktop}/icons/32x32.png | Bin .../icons/Square107x107Logo.png | Bin .../icons/Square142x142Logo.png | Bin .../icons/Square150x150Logo.png | Bin .../icons/Square284x284Logo.png | Bin .../icons/Square30x30Logo.png | Bin .../icons/Square310x310Logo.png | Bin .../icons/Square44x44Logo.png | Bin .../icons/Square71x71Logo.png | Bin .../icons/Square89x89Logo.png | Bin crates/{tauri => desktop}/icons/StoreLogo.png | Bin crates/{tauri => desktop}/icons/icon.icns | Bin crates/{tauri => desktop}/icons/icon.ico | Bin crates/{tauri => desktop}/icons/icon.png | Bin crates/{tauri => desktop}/src/lib.rs | 2 +- crates/{tauri => desktop}/src/main.rs | 0 crates/{tauri => desktop}/tauri.conf.json | 2 +- crates/sesame-vitale/Cargo.toml | 6 +++ crates/sesame-vitale/src/lib.rs | 14 +++++ 37 files changed, 56 insertions(+), 31 deletions(-) rename crates/{clego => app}/.gitignore (100%) rename crates/{clego => app}/Cargo.toml (94%) rename crates/{clego => app}/assets/js/htmx.min.js.js (100%) rename crates/{clego => app}/src/lib.rs (100%) rename crates/{clego => app}/src/main.rs (94%) rename crates/{clego => app}/src/templates/hello.rs (100%) rename crates/{clego => app}/src/templates/index.rs (100%) rename crates/{clego => app}/src/templates/mod.rs (100%) rename crates/{clego => app}/templates/base.html (100%) rename crates/{clego => app}/templates/hello.html (100%) rename crates/{clego => app}/templates/index.html (100%) rename crates/{tauri => desktop}/.gitignore (100%) rename crates/{tauri => desktop}/Cargo.toml (87%) rename crates/{tauri => desktop}/build.rs (100%) rename crates/{tauri => desktop}/icons/128x128.png (100%) rename crates/{tauri => desktop}/icons/128x128@2x.png (100%) rename crates/{tauri => desktop}/icons/32x32.png (100%) rename crates/{tauri => desktop}/icons/Square107x107Logo.png (100%) rename crates/{tauri => desktop}/icons/Square142x142Logo.png (100%) rename crates/{tauri => desktop}/icons/Square150x150Logo.png (100%) rename crates/{tauri => desktop}/icons/Square284x284Logo.png (100%) rename crates/{tauri => desktop}/icons/Square30x30Logo.png (100%) rename crates/{tauri => desktop}/icons/Square310x310Logo.png (100%) rename crates/{tauri => desktop}/icons/Square44x44Logo.png (100%) rename crates/{tauri => desktop}/icons/Square71x71Logo.png (100%) rename crates/{tauri => desktop}/icons/Square89x89Logo.png (100%) rename crates/{tauri => desktop}/icons/StoreLogo.png (100%) rename crates/{tauri => desktop}/icons/icon.icns (100%) rename crates/{tauri => desktop}/icons/icon.ico (100%) rename crates/{tauri => desktop}/icons/icon.png (100%) rename crates/{tauri => desktop}/src/lib.rs (96%) rename crates/{tauri => desktop}/src/main.rs (100%) rename crates/{tauri => desktop}/tauri.conf.json (94%) create mode 100644 crates/sesame-vitale/Cargo.toml create mode 100644 crates/sesame-vitale/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index d706ed2..4d5cf74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,6 +62,17 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "app" +version = "0.1.0" +dependencies = [ + "askama", + "askama_axum", + "axum", + "tokio", + "tower-http", +] + [[package]] name = "askama" version = "0.12.1" @@ -460,17 +471,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "clego" -version = "0.1.0" -dependencies = [ - "askama", - "askama_axum", - "axum", - "tokio", - "tower-http", -] - [[package]] name = "cocoa" version = "0.25.0" @@ -695,6 +695,18 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "desktop" +version = "0.1.0" +dependencies = [ + "app", + "axum", + "tauri", + "tauri-build", + "tokio", + "tower", +] + [[package]] name = "digest" version = "0.10.7" @@ -2161,18 +2173,6 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" -[[package]] -name = "pharmacie-desktop" -version = "0.1.0" -dependencies = [ - "axum", - "clego", - "tauri", - "tauri-build", - "tokio", - "tower", -] - [[package]] name = "phf" version = "0.8.0" @@ -2919,6 +2919,10 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "sesame-vitale" +version = "0.1.0" + [[package]] name = "sha2" version = "0.10.8" diff --git a/Cargo.toml b/Cargo.toml index 8507ae3..f3d66ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [workspace] resolver = "2" members = [ - "crates/clego", - "crates/tauri" + "crates/app", + "crates/sesame-vitale", + "crates/desktop" ] diff --git a/crates/clego/.gitignore b/crates/app/.gitignore similarity index 100% rename from crates/clego/.gitignore rename to crates/app/.gitignore diff --git a/crates/clego/Cargo.toml b/crates/app/Cargo.toml similarity index 94% rename from crates/clego/Cargo.toml rename to crates/app/Cargo.toml index f06528b..786b7b6 100644 --- a/crates/clego/Cargo.toml +++ b/crates/app/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "clego" +name = "app" version = "0.1.0" edition = "2021" diff --git a/crates/clego/assets/js/htmx.min.js.js b/crates/app/assets/js/htmx.min.js.js similarity index 100% rename from crates/clego/assets/js/htmx.min.js.js rename to crates/app/assets/js/htmx.min.js.js diff --git a/crates/clego/src/lib.rs b/crates/app/src/lib.rs similarity index 100% rename from crates/clego/src/lib.rs rename to crates/app/src/lib.rs diff --git a/crates/clego/src/main.rs b/crates/app/src/main.rs similarity index 94% rename from crates/clego/src/main.rs rename to crates/app/src/main.rs index 00b4fdf..6d2d784 100644 --- a/crates/clego/src/main.rs +++ b/crates/app/src/main.rs @@ -1,4 +1,4 @@ -use ::clego::get_router; +use ::app::get_router; use std::path::Path; use std::env; diff --git a/crates/clego/src/templates/hello.rs b/crates/app/src/templates/hello.rs similarity index 100% rename from crates/clego/src/templates/hello.rs rename to crates/app/src/templates/hello.rs diff --git a/crates/clego/src/templates/index.rs b/crates/app/src/templates/index.rs similarity index 100% rename from crates/clego/src/templates/index.rs rename to crates/app/src/templates/index.rs diff --git a/crates/clego/src/templates/mod.rs b/crates/app/src/templates/mod.rs similarity index 100% rename from crates/clego/src/templates/mod.rs rename to crates/app/src/templates/mod.rs diff --git a/crates/clego/templates/base.html b/crates/app/templates/base.html similarity index 100% rename from crates/clego/templates/base.html rename to crates/app/templates/base.html diff --git a/crates/clego/templates/hello.html b/crates/app/templates/hello.html similarity index 100% rename from crates/clego/templates/hello.html rename to crates/app/templates/hello.html diff --git a/crates/clego/templates/index.html b/crates/app/templates/index.html similarity index 100% rename from crates/clego/templates/index.html rename to crates/app/templates/index.html diff --git a/crates/tauri/.gitignore b/crates/desktop/.gitignore similarity index 100% rename from crates/tauri/.gitignore rename to crates/desktop/.gitignore diff --git a/crates/tauri/Cargo.toml b/crates/desktop/Cargo.toml similarity index 87% rename from crates/tauri/Cargo.toml rename to crates/desktop/Cargo.toml index a9d2832..351ff36 100644 --- a/crates/tauri/Cargo.toml +++ b/crates/desktop/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "pharmacie-desktop" +name = "desktop" version = "0.1.0" description = "Un logiciel de pharmacie libre et open-source." authors = ["p4pillon"] @@ -18,5 +18,5 @@ tauri = { version = "2.0.0-beta", features = [] } tower = "0.4.13" tokio = "1.39.1" -clego = { path = "../clego" } +app = { path = "../app" } diff --git a/crates/tauri/build.rs b/crates/desktop/build.rs similarity index 100% rename from crates/tauri/build.rs rename to crates/desktop/build.rs diff --git a/crates/tauri/icons/128x128.png b/crates/desktop/icons/128x128.png similarity index 100% rename from crates/tauri/icons/128x128.png rename to crates/desktop/icons/128x128.png diff --git a/crates/tauri/icons/128x128@2x.png b/crates/desktop/icons/128x128@2x.png similarity index 100% rename from crates/tauri/icons/128x128@2x.png rename to crates/desktop/icons/128x128@2x.png diff --git a/crates/tauri/icons/32x32.png b/crates/desktop/icons/32x32.png similarity index 100% rename from crates/tauri/icons/32x32.png rename to crates/desktop/icons/32x32.png diff --git a/crates/tauri/icons/Square107x107Logo.png b/crates/desktop/icons/Square107x107Logo.png similarity index 100% rename from crates/tauri/icons/Square107x107Logo.png rename to crates/desktop/icons/Square107x107Logo.png diff --git a/crates/tauri/icons/Square142x142Logo.png b/crates/desktop/icons/Square142x142Logo.png similarity index 100% rename from crates/tauri/icons/Square142x142Logo.png rename to crates/desktop/icons/Square142x142Logo.png diff --git a/crates/tauri/icons/Square150x150Logo.png b/crates/desktop/icons/Square150x150Logo.png similarity index 100% rename from crates/tauri/icons/Square150x150Logo.png rename to crates/desktop/icons/Square150x150Logo.png diff --git a/crates/tauri/icons/Square284x284Logo.png b/crates/desktop/icons/Square284x284Logo.png similarity index 100% rename from crates/tauri/icons/Square284x284Logo.png rename to crates/desktop/icons/Square284x284Logo.png diff --git a/crates/tauri/icons/Square30x30Logo.png b/crates/desktop/icons/Square30x30Logo.png similarity index 100% rename from crates/tauri/icons/Square30x30Logo.png rename to crates/desktop/icons/Square30x30Logo.png diff --git a/crates/tauri/icons/Square310x310Logo.png b/crates/desktop/icons/Square310x310Logo.png similarity index 100% rename from crates/tauri/icons/Square310x310Logo.png rename to crates/desktop/icons/Square310x310Logo.png diff --git a/crates/tauri/icons/Square44x44Logo.png b/crates/desktop/icons/Square44x44Logo.png similarity index 100% rename from crates/tauri/icons/Square44x44Logo.png rename to crates/desktop/icons/Square44x44Logo.png diff --git a/crates/tauri/icons/Square71x71Logo.png b/crates/desktop/icons/Square71x71Logo.png similarity index 100% rename from crates/tauri/icons/Square71x71Logo.png rename to crates/desktop/icons/Square71x71Logo.png diff --git a/crates/tauri/icons/Square89x89Logo.png b/crates/desktop/icons/Square89x89Logo.png similarity index 100% rename from crates/tauri/icons/Square89x89Logo.png rename to crates/desktop/icons/Square89x89Logo.png diff --git a/crates/tauri/icons/StoreLogo.png b/crates/desktop/icons/StoreLogo.png similarity index 100% rename from crates/tauri/icons/StoreLogo.png rename to crates/desktop/icons/StoreLogo.png diff --git a/crates/tauri/icons/icon.icns b/crates/desktop/icons/icon.icns similarity index 100% rename from crates/tauri/icons/icon.icns rename to crates/desktop/icons/icon.icns diff --git a/crates/tauri/icons/icon.ico b/crates/desktop/icons/icon.ico similarity index 100% rename from crates/tauri/icons/icon.ico rename to crates/desktop/icons/icon.ico diff --git a/crates/tauri/icons/icon.png b/crates/desktop/icons/icon.png similarity index 100% rename from crates/tauri/icons/icon.png rename to crates/desktop/icons/icon.png diff --git a/crates/tauri/src/lib.rs b/crates/desktop/src/lib.rs similarity index 96% rename from crates/tauri/src/lib.rs rename to crates/desktop/src/lib.rs index 19ca565..e7da8af 100644 --- a/crates/tauri/src/lib.rs +++ b/crates/desktop/src/lib.rs @@ -45,7 +45,7 @@ pub fn run() { .expect("Path should be resolvable"); let router = Arc::new(Mutex::new( - clego::get_router(resource_path_buf.as_path()).clone(), + app::get_router(resource_path_buf.as_path()).clone(), )); // Adds the router to the application state diff --git a/crates/tauri/src/main.rs b/crates/desktop/src/main.rs similarity index 100% rename from crates/tauri/src/main.rs rename to crates/desktop/src/main.rs diff --git a/crates/tauri/tauri.conf.json b/crates/desktop/tauri.conf.json similarity index 94% rename from crates/tauri/tauri.conf.json rename to crates/desktop/tauri.conf.json index 9282f10..d971535 100644 --- a/crates/tauri/tauri.conf.json +++ b/crates/desktop/tauri.conf.json @@ -26,7 +26,7 @@ "bundle": { "active": true, "resources": { - "../clego/assets/": "./assets/" + "../app/assets/": "./assets/" }, "targets": "all", "icon": [ diff --git a/crates/sesame-vitale/Cargo.toml b/crates/sesame-vitale/Cargo.toml new file mode 100644 index 0000000..3dc98de --- /dev/null +++ b/crates/sesame-vitale/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "sesame-vitale" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/crates/sesame-vitale/src/lib.rs b/crates/sesame-vitale/src/lib.rs new file mode 100644 index 0000000..7d12d9a --- /dev/null +++ b/crates/sesame-vitale/src/lib.rs @@ -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); + } +} From 5eebd5d1cbc7dc169daf9b23a673b01b9c95f1b0 Mon Sep 17 00:00:00 2001 From: theo Date: Wed, 24 Jul 2024 22:15:53 +0200 Subject: [PATCH 11/21] fix: rename sesam-vitale and fix readme --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 15 ++++++++------- crates/desktop/Cargo.toml | 2 +- crates/{sesame-vitale => sesam-vitale}/Cargo.toml | 2 +- crates/{sesame-vitale => sesam-vitale}/src/lib.rs | 0 6 files changed, 12 insertions(+), 11 deletions(-) rename crates/{sesame-vitale => sesam-vitale}/Cargo.toml (72%) rename crates/{sesame-vitale => sesam-vitale}/src/lib.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 4d5cf74..9dc7859 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2920,7 +2920,7 @@ dependencies = [ ] [[package]] -name = "sesame-vitale" +name = "sesam-vitale" version = "0.1.0" [[package]] diff --git a/Cargo.toml b/Cargo.toml index f3d66ea..ebb5ebe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,6 @@ resolver = "2" members = [ "crates/app", - "crates/sesame-vitale", + "crates/sesam-vitale", "crates/desktop" ] diff --git a/README.md b/README.md index d995282..469c47c 100644 --- a/README.md +++ b/README.md @@ -4,30 +4,31 @@ 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. +- `app`: Endpoint Axum qui peut aussi être utilisé en tant que librairie. Renvoie l'interface du logiciel de pharmacie en HTML. +- `desktop`: Application Tauri qui intègre l'application Axum. +- `sesam-vitale`: Moteur de facturation SESAM-VITALE. ## Development -Install +### Installation ```bash cargo install tauri-cli ``` -Run desktop client app +### Exécution de l'application cliente desktop ```bash cargo tauri dev ``` -Run clego endpoint +### Exécution de l'endpoint `app` ```bash -cargo run --bin clego +cargo run --bin app ``` -Bundle desktop client app +### Création du bundle de l'application cliente desktop ```bash cargo tauri build diff --git a/crates/desktop/Cargo.toml b/crates/desktop/Cargo.toml index 351ff36..aa35d05 100644 --- a/crates/desktop/Cargo.toml +++ b/crates/desktop/Cargo.toml @@ -6,7 +6,7 @@ authors = ["p4pillon"] edition = "2021" [lib] -name = "pharmacie_desktop_lib" +name = "desktop_lib" crate-type = ["lib", "cdylib", "staticlib"] [build-dependencies] diff --git a/crates/sesame-vitale/Cargo.toml b/crates/sesam-vitale/Cargo.toml similarity index 72% rename from crates/sesame-vitale/Cargo.toml rename to crates/sesam-vitale/Cargo.toml index 3dc98de..7132546 100644 --- a/crates/sesame-vitale/Cargo.toml +++ b/crates/sesam-vitale/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "sesame-vitale" +name = "sesam-vitale" version = "0.1.0" edition = "2021" diff --git a/crates/sesame-vitale/src/lib.rs b/crates/sesam-vitale/src/lib.rs similarity index 100% rename from crates/sesame-vitale/src/lib.rs rename to crates/sesam-vitale/src/lib.rs From 9447ad7fafea2e7855373756f8c40808f803442a Mon Sep 17 00:00:00 2001 From: theo Date: Wed, 24 Jul 2024 22:35:14 +0200 Subject: [PATCH 12/21] fix: wrong lib name --- crates/desktop/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/desktop/src/main.rs b/crates/desktop/src/main.rs index 991f759..bea3c23 100644 --- a/crates/desktop/src/main.rs +++ b/crates/desktop/src/main.rs @@ -2,5 +2,5 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] fn main() { - pharmacie_desktop_lib::run() + desktop_lib::run() } From a19b6dcd0dac1fbf393c8003195b8432d791d5e5 Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Wed, 24 Jul 2024 22:33:25 +0200 Subject: [PATCH 13/21] fix: Typo in index.html --- crates/app/templates/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/app/templates/index.html b/crates/app/templates/index.html index f43a467..718e694 100644 --- a/crates/app/templates/index.html +++ b/crates/app/templates/index.html @@ -1,6 +1,6 @@ {% extends "base.html" %} -{% block title %}Phrama Libre{% endblock %} +{% block title %}Pharma Libre{% endblock %} {% block body %} From f6a1af5d1eb2f168a8eea6f322a23cd9a8f28290 Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Wed, 24 Jul 2024 22:34:01 +0200 Subject: [PATCH 14/21] fix: add `org.` to tauri identifier --- crates/desktop/tauri.conf.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/desktop/tauri.conf.json b/crates/desktop/tauri.conf.json index d971535..8890044 100644 --- a/crates/desktop/tauri.conf.json +++ b/crates/desktop/tauri.conf.json @@ -1,7 +1,7 @@ { "productName": "Logiciel Pharma", "version": "0.0.1", - "identifier": "p4pillon.pharma.desktop", + "identifier": "org.p4pillon.pharma.desktop", "build": { "beforeDevCommand": { "script": "cargo run", From 648a7848fdb44eb35f279848b306699684111b2a Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Wed, 24 Jul 2024 22:35:27 +0200 Subject: [PATCH 15/21] feature: improve README.md --- README.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 469c47c..4d5e939 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,15 @@ Logiciel de Pharmacie libre et open-source. ## Crates -- `app`: Endpoint Axum qui peut aussi être utilisé en tant que librairie. Renvoie l'interface du logiciel de pharmacie en HTML. -- `desktop`: Application Tauri qui intègre l'application Axum. -- `sesam-vitale`: Moteur de facturation SESAM-VITALE. +- `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 -### Installation +### 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 @@ -22,13 +24,15 @@ cargo install tauri-cli cargo tauri dev ``` -### Exécution de l'endpoint `app` +### Exécution du serveur web `app` en mode endpoint ```bash cargo run --bin app ``` -### Création du bundle de l'application cliente desktop +## Build + +Packager le client desktop ```bash cargo tauri build From 8c38f0e4ba52e8943e8b3f292f60f02421b929ca Mon Sep 17 00:00:00 2001 From: theo Date: Wed, 24 Jul 2024 22:41:57 +0200 Subject: [PATCH 16/21] fix: remove 2 js extension on htmx file --- crates/app/assets/js/{htmx.min.js.js => htmx.min.js} | 0 crates/app/templates/base.html | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename crates/app/assets/js/{htmx.min.js.js => htmx.min.js} (100%) diff --git a/crates/app/assets/js/htmx.min.js.js b/crates/app/assets/js/htmx.min.js similarity index 100% rename from crates/app/assets/js/htmx.min.js.js rename to crates/app/assets/js/htmx.min.js diff --git a/crates/app/templates/base.html b/crates/app/templates/base.html index 9d57d0b..8c1715d 100644 --- a/crates/app/templates/base.html +++ b/crates/app/templates/base.html @@ -3,7 +3,7 @@ {% block title %}{{ title }}{% endblock %} - + {% block head %}{% endblock %} From ba88b08a57cb4a14b097dba6abb3d42ddf66ce76 Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Wed, 24 Jul 2024 23:28:22 +0200 Subject: [PATCH 17/21] fix: typo in Tauri beforeDevCommand --- crates/desktop/tauri.conf.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/desktop/tauri.conf.json b/crates/desktop/tauri.conf.json index 8890044..f7d9482 100644 --- a/crates/desktop/tauri.conf.json +++ b/crates/desktop/tauri.conf.json @@ -4,8 +4,8 @@ "identifier": "org.p4pillon.pharma.desktop", "build": { "beforeDevCommand": { - "script": "cargo run", - "cwd": "../clego" + "cwd": "../app", + "script": "cargo run" }, "devUrl": "http://localhost:3000", "frontendDist": "axum://place.holder/" From d33140ebafba1bbdcb1797fd9ad689ea6a8ba493 Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Wed, 24 Jul 2024 23:39:02 +0200 Subject: [PATCH 18/21] chore: Improve desktop/src/lib readability --- crates/desktop/src/lib.rs | 57 ++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/crates/desktop/src/lib.rs b/crates/desktop/src/lib.rs index e7da8af..3cadb71 100644 --- a/crates/desktop/src/lib.rs +++ b/crates/desktop/src/lib.rs @@ -2,18 +2,28 @@ use core::panic; 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: tauri::http::Request>, + request: TauriRequest>, mut router: MutexGuard<'_, axum::Router>, -) -> tauri::http::Response> { +) -> TauriResponse> { + // Convert the Tauri request to an Axum request let (parts, body) = request.into_parts(); - let body = axum::body::Body::from(body); - - let request = axum::extract::Request::from_parts(parts, body); + let body = AxumBody::from(body); + let request = AxumRequest::from_parts(parts, body); + // Process the request with the router let response = match router.as_service().ready().await { Ok(ready_service) => ready_service.call(request).await, Err(_error) => panic!("Failed to get ready service"), @@ -24,13 +34,14 @@ async fn process_tauri_request( Err(_error) => panic!("Problem getting response from request."), }; + // Convert the Axum response to a Tauri response let (parts, body) = response.into_parts(); - let body = match axum::body::to_bytes(body, usize::MAX).await { + let 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); + let response = TauriResponse::from_parts(parts, body); response } @@ -39,32 +50,34 @@ async fn process_tauri_request( pub fn run() { tauri::Builder::default() .setup(|app| { - let resource_path_buf = app + let assets_path = app .path() .resolve("assets", BaseDirectory::Resource) .expect("Path should be resolvable"); - let router = Arc::new(Mutex::new( - app::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) + 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| { - let router = Arc::clone(&app.state::>>()); + .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::>>()); - tauri::async_runtime::spawn(async move { - let router = router.lock().await; - - let response = process_tauri_request(request, router).await; - - responder.respond(response); - }); - }) + // 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"); } From f8d7f82c50c46fd0d723ad94c39e0ddc96a43201 Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Wed, 24 Jul 2024 23:39:27 +0200 Subject: [PATCH 19/21] chore: Refactor process_tauri_request function for improved readability and error handling --- crates/desktop/src/lib.rs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/crates/desktop/src/lib.rs b/crates/desktop/src/lib.rs index 3cadb71..daa8cd9 100644 --- a/crates/desktop/src/lib.rs +++ b/crates/desktop/src/lib.rs @@ -1,4 +1,3 @@ -use core::panic; use std::sync::Arc; use tauri::{path::BaseDirectory, Manager}; @@ -24,23 +23,18 @@ async fn process_tauri_request( let request = AxumRequest::from_parts(parts, body); // Process the request with the router - 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 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 { - Ok(bytes) => bytes.to_vec(), - Err(_error) => panic!("Problem converting response body to bytes."), - }; - + 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 From 65059b87d4f61f4450ad96110d4c9af9f854c664 Mon Sep 17 00:00:00 2001 From: theo Date: Thu, 25 Jul 2024 09:21:17 +0200 Subject: [PATCH 20/21] chore: run cargo fmt --- crates/app/src/main.rs | 2 +- crates/app/src/templates/mod.rs | 2 +- crates/desktop/src/lib.rs | 48 ++++++++++++++------------------- 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 6d2d784..0f11472 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -1,6 +1,6 @@ use ::app::get_router; +use std::env; use std::path::Path; -use std::env; #[tokio::main] async fn main() { diff --git a/crates/app/src/templates/mod.rs b/crates/app/src/templates/mod.rs index 3f635aa..bb7cbb8 100644 --- a/crates/app/src/templates/mod.rs +++ b/crates/app/src/templates/mod.rs @@ -1,2 +1,2 @@ -pub mod index; pub mod hello; +pub mod index; diff --git a/crates/desktop/src/lib.rs b/crates/desktop/src/lib.rs index daa8cd9..09e2db9 100644 --- a/crates/desktop/src/lib.rs +++ b/crates/desktop/src/lib.rs @@ -1,15 +1,9 @@ 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::body::{to_bytes, Body as AxumBody}; use axum::extract::Request as AxumRequest; +use tauri::http::{Request as TauriRequest, Response as TauriResponse}; +use tauri::{path::BaseDirectory, Manager}; use tokio::sync::{Mutex, MutexGuard}; use tower::{Service, ServiceExt}; @@ -25,14 +19,17 @@ async fn process_tauri_request( // Process the request with the router let response = router .as_service() - .ready().await + .ready() + .await .expect("Failed to get ready service") - .call(request).await + .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 + let body = to_bytes(body, usize::MAX) + .await .expect("Failed to convert body to bytes") .to_vec(); let response = TauriResponse::from_parts(parts, body); @@ -51,27 +48,22 @@ pub fn run() { // 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(), - )); + 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::>>()); + .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::>>()); - // 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); - }); - } - ) + // 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"); } From d6d487a7272072bb5c5478b8eb3dc8775ab8d28e Mon Sep 17 00:00:00 2001 From: theo Date: Fri, 26 Jul 2024 14:06:53 +0200 Subject: [PATCH 21/21] chore: reduce verbosity and propose alternative to named types --- Cargo.lock | 2 ++ crates/desktop/Cargo.toml | 2 ++ crates/desktop/src/lib.rs | 54 +++++++++++++++++++-------------------- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9dc7859..648d490 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -701,6 +701,8 @@ version = "0.1.0" dependencies = [ "app", "axum", + "bytes", + "http", "tauri", "tauri-build", "tokio", diff --git a/crates/desktop/Cargo.toml b/crates/desktop/Cargo.toml index aa35d05..0ddbb50 100644 --- a/crates/desktop/Cargo.toml +++ b/crates/desktop/Cargo.toml @@ -19,4 +19,6 @@ tower = "0.4.13" tokio = "1.39.1" app = { path = "../app" } +http = "1.1.0" +bytes = "1.6.1" diff --git a/crates/desktop/src/lib.rs b/crates/desktop/src/lib.rs index 09e2db9..3e7ca06 100644 --- a/crates/desktop/src/lib.rs +++ b/crates/desktop/src/lib.rs @@ -1,54 +1,54 @@ +use bytes::Bytes; +use http::{request, response, Request, Response}; +use std::path::PathBuf; use std::sync::Arc; -use axum::body::{to_bytes, Body as AxumBody}; -use axum::extract::Request as AxumRequest; -use tauri::http::{Request as TauriRequest, Response as TauriResponse}; -use tauri::{path::BaseDirectory, Manager}; +use axum::body::{to_bytes, Body}; + +use axum::Router; + +use tauri::path::BaseDirectory; +use tauri::Manager; use tokio::sync::{Mutex, MutexGuard}; use tower::{Service, ServiceExt}; async fn process_tauri_request( - request: TauriRequest>, - mut router: MutexGuard<'_, axum::Router>, -) -> TauriResponse> { - // 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); + tauri_request: Request>, + mut router: MutexGuard<'_, Router>, +) -> Response> { + let (parts, body): (request::Parts, Vec) = tauri_request.into_parts(); + let axum_request: Request = Request::from_parts(parts, body.into()); - // Process the request with the router - let response = router + let axum_response: Response = router .as_service() .ready() .await - .expect("Failed to get ready service") - .call(request) + .expect("Failed to get ready service from router") + .call(axum_request) .await - .expect("Failed to get response from router"); + .expect("Could not 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); + let (parts, body): (response::Parts, Body) = axum_response.into_parts(); + let body: Bytes = to_bytes(body, usize::MAX).await.unwrap_or_default(); - response + let tauri_response: Response> = Response::from_parts(parts, body.into()); + + tauri_response } #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { tauri::Builder::default() .setup(|app| { - let assets_path = app + let assets_path: PathBuf = app .path() .resolve("assets", BaseDirectory::Resource) .expect("Path should be resolvable"); - // Adds the router to the application state + // Adds Axum router to 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())); + let router = Arc::new(Mutex::new(app::get_router(&assets_path))); + app.manage(router); Ok(())