From 0d900024cbafc07ffa371b6f8c6e83efe57915d0 Mon Sep 17 00:00:00 2001 From: traxys Date: Mon, 7 Aug 2023 17:27:11 +0200 Subject: [PATCH] Make the GUI a library to support multiple platforms --- Cargo.lock | 57 ++++++++++++--------- Cargo.toml | 2 +- flake.nix | 2 +- {app => gui}/Cargo.toml | 3 +- {app => gui}/dl_deps.sh | 0 {app => gui}/src/bootstrap/mod.rs | 0 {app => gui}/src/full_context.rs | 0 {app => gui}/src/ingredients.rs | 0 app/src/main.rs => gui/src/lib.rs | 17 +++--- {app => gui}/src/recipe/creator.rs | 0 {app => gui}/src/recipe/list.rs | 0 {app => gui}/src/recipe/mod.rs | 0 {app => gui}/src/recipe/view.rs | 0 {app => gui}/src/sidebar.rs | 0 web/Cargo.toml | 13 +++++ {app => web}/Dioxus.toml | 0 {app => web}/public/.gitignore | 0 {app => web}/public/awesomplete.css | 0 {app => web}/public/awesomplete.min.js | 0 {app => web}/public/awesomplete.min.js.map | 0 {app => web}/public/household_selection.css | 0 {app => web}/public/login.css | 0 {app => web}/public/style.css | 0 web/src/main.rs | 21 ++++++++ 24 files changed, 76 insertions(+), 39 deletions(-) rename {app => gui}/Cargo.toml (88%) rename {app => gui}/dl_deps.sh (100%) rename {app => gui}/src/bootstrap/mod.rs (100%) rename {app => gui}/src/full_context.rs (100%) rename {app => gui}/src/ingredients.rs (100%) rename app/src/main.rs => gui/src/lib.rs (98%) rename {app => gui}/src/recipe/creator.rs (100%) rename {app => gui}/src/recipe/list.rs (100%) rename {app => gui}/src/recipe/mod.rs (100%) rename {app => gui}/src/recipe/view.rs (100%) rename {app => gui}/src/sidebar.rs (100%) create mode 100644 web/Cargo.toml rename {app => web}/Dioxus.toml (100%) rename {app => web}/public/.gitignore (100%) rename {app => web}/public/awesomplete.css (100%) rename {app => web}/public/awesomplete.min.js (100%) rename {app => web}/public/awesomplete.min.js.map (100%) rename {app => web}/public/household_selection.css (100%) rename {app => web}/public/login.css (100%) rename {app => web}/public/style.css (100%) create mode 100644 web/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 9215e0a..d9f223f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -590,7 +590,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be8aed40e4edbf4d3b4431ab260b63fdc40f5780a4766824329ea0f1eefe3c0f" dependencies = [ "log", - "wasm-bindgen", "web-sys", ] @@ -910,29 +909,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "dioxus_app" -version = "0.1.0" -dependencies = [ - "ammonia", - "anyhow", - "api", - "console_log", - "dioxus", - "dioxus-router", - "dioxus-web", - "gloo-net", - "gloo-storage", - "gloo-utils", - "itertools 0.11.0", - "log", - "pulldown-cmark", - "serde", - "urlencoding", - "uuid", - "wasm-bindgen", -] - [[package]] name = "dirs" version = "4.0.0" @@ -2724,6 +2700,39 @@ dependencies = [ "uuid", ] +[[package]] +name = "regalade_gui" +version = "0.1.0" +dependencies = [ + "ammonia", + "anyhow", + "api", + "dioxus", + "dioxus-router", + "dioxus-web", + "gloo-net", + "gloo-storage", + "gloo-utils", + "itertools 0.11.0", + "log", + "pulldown-cmark", + "serde", + "urlencoding", + "uuid", + "wasm-bindgen", +] + +[[package]] +name = "regalade_web" +version = "0.1.0" +dependencies = [ + "console_log", + "dioxus-web", + "gloo-utils", + "log", + "regalade_gui", +] + [[package]] name = "regex" version = "1.8.1" diff --git a/Cargo.toml b/Cargo.toml index 43c694a..3c300c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ authors = ["traxys "] edition = "2021" [workspace] -members = [".", "api", "app", "migration"] +members = [".", "api", "gui", "migration", "web"] [dependencies] anyhow = "1.0.71" diff --git a/flake.nix b/flake.nix index 29f6e21..ceb27b9 100644 --- a/flake.nix +++ b/flake.nix @@ -118,7 +118,7 @@ export XDG_DATA_HOME=/build/data mkdir -p $XDG_DATA_HOME - cd app + cd web dx build --release runHook postBuild diff --git a/app/Cargo.toml b/gui/Cargo.toml similarity index 88% rename from app/Cargo.toml rename to gui/Cargo.toml index 6d4683b..cb18673 100644 --- a/app/Cargo.toml +++ b/gui/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "dioxus_app" +name = "regalade_gui" version = "0.1.0" edition = "2021" @@ -9,7 +9,6 @@ edition = "2021" ammonia = "3.3.0" anyhow = "1.0.71" api = { version = "0.1.0", path = "../api" } -console_log = { version = "1.0.0", features = ["color"] } dioxus = "0.4.0" dioxus-router = { version = "0.4.1", features = ["web"] } dioxus-web = "0.4.0" diff --git a/app/dl_deps.sh b/gui/dl_deps.sh similarity index 100% rename from app/dl_deps.sh rename to gui/dl_deps.sh diff --git a/app/src/bootstrap/mod.rs b/gui/src/bootstrap/mod.rs similarity index 100% rename from app/src/bootstrap/mod.rs rename to gui/src/bootstrap/mod.rs diff --git a/app/src/full_context.rs b/gui/src/full_context.rs similarity index 100% rename from app/src/full_context.rs rename to gui/src/full_context.rs diff --git a/app/src/ingredients.rs b/gui/src/ingredients.rs similarity index 100% rename from app/src/ingredients.rs rename to gui/src/ingredients.rs diff --git a/app/src/main.rs b/gui/src/lib.rs similarity index 98% rename from app/src/main.rs rename to gui/src/lib.rs index 881d194..d4a4c12 100644 --- a/app/src/main.rs +++ b/gui/src/lib.rs @@ -586,18 +586,13 @@ enum Route { RecipeView {id: i64} } -fn App(cx: Scope) -> Element { +pub trait AppContext {} + +pub struct AppProps<'a, C> { + pub context: &'a C, +} +pub fn App<'a, C: AppContext>(cx: Scope<'a, AppProps<'a, C>>) -> Element { cx.render(rsx! { Router:: {} }) } - -fn main() { - console_log::init_with_level(log::Level::Info).unwrap(); - - let html = gloo_utils::document_element(); - html.set_attribute("data-bs-theme", "dark") - .expect("could not set dark theme"); - - dioxus_web::launch(App) -} diff --git a/app/src/recipe/creator.rs b/gui/src/recipe/creator.rs similarity index 100% rename from app/src/recipe/creator.rs rename to gui/src/recipe/creator.rs diff --git a/app/src/recipe/list.rs b/gui/src/recipe/list.rs similarity index 100% rename from app/src/recipe/list.rs rename to gui/src/recipe/list.rs diff --git a/app/src/recipe/mod.rs b/gui/src/recipe/mod.rs similarity index 100% rename from app/src/recipe/mod.rs rename to gui/src/recipe/mod.rs diff --git a/app/src/recipe/view.rs b/gui/src/recipe/view.rs similarity index 100% rename from app/src/recipe/view.rs rename to gui/src/recipe/view.rs diff --git a/app/src/sidebar.rs b/gui/src/sidebar.rs similarity index 100% rename from app/src/sidebar.rs rename to gui/src/sidebar.rs diff --git a/web/Cargo.toml b/web/Cargo.toml new file mode 100644 index 0000000..983e0f8 --- /dev/null +++ b/web/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "regalade_web" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +console_log = "1.0.0" +dioxus-web = "0.4.0" +gloo-utils = "0.1.7" +log = "0.4.19" +regalade_gui = { path = "../gui" } diff --git a/app/Dioxus.toml b/web/Dioxus.toml similarity index 100% rename from app/Dioxus.toml rename to web/Dioxus.toml diff --git a/app/public/.gitignore b/web/public/.gitignore similarity index 100% rename from app/public/.gitignore rename to web/public/.gitignore diff --git a/app/public/awesomplete.css b/web/public/awesomplete.css similarity index 100% rename from app/public/awesomplete.css rename to web/public/awesomplete.css diff --git a/app/public/awesomplete.min.js b/web/public/awesomplete.min.js similarity index 100% rename from app/public/awesomplete.min.js rename to web/public/awesomplete.min.js diff --git a/app/public/awesomplete.min.js.map b/web/public/awesomplete.min.js.map similarity index 100% rename from app/public/awesomplete.min.js.map rename to web/public/awesomplete.min.js.map diff --git a/app/public/household_selection.css b/web/public/household_selection.css similarity index 100% rename from app/public/household_selection.css rename to web/public/household_selection.css diff --git a/app/public/login.css b/web/public/login.css similarity index 100% rename from app/public/login.css rename to web/public/login.css diff --git a/app/public/style.css b/web/public/style.css similarity index 100% rename from app/public/style.css rename to web/public/style.css diff --git a/web/src/main.rs b/web/src/main.rs new file mode 100644 index 0000000..f1d47ab --- /dev/null +++ b/web/src/main.rs @@ -0,0 +1,21 @@ +use regalade_gui::{App, AppContext, AppProps}; + +struct WebApp {} + +impl AppContext for WebApp {} + +fn main() { + console_log::init_with_level(log::Level::Info).unwrap(); + + let html = gloo_utils::document_element(); + html.set_attribute("data-bs-theme", "dark") + .expect("could not set dark theme"); + + dioxus_web::launch_with_props( + App, + AppProps { + context: &WebApp {}, + }, + dioxus_web::Config::new(), + ) +}