From 0932130e87cc6e55214ae46cf905829df0c88f50 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Mon, 22 Jan 2024 08:58:35 -0600 Subject: [PATCH] include more platforms in the launch builder --- Cargo.lock | 3 +++ packages/config-macro/Cargo.toml | 1 + packages/dioxus/Cargo.toml | 10 ++++++---- packages/dioxus/src/launch.rs | 20 ++++++++++++++++++-- packages/dioxus/src/lib.rs | 9 +++++++++ packages/fullstack/Cargo.toml | 4 ++++ packages/fullstack/src/config.rs | 17 ++++++++++++++--- packages/fullstack/src/launch.rs | 6 ++++++ packages/fullstack/src/lib.rs | 3 +++ packages/mobile/Cargo.toml | 2 +- 10 files changed, 65 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ccfff28bd..c8f1206e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2325,6 +2325,8 @@ dependencies = [ "dioxus-router", "dioxus-rsx", "dioxus-signals", + "dioxus-ssr", + "dioxus-tui", "dioxus-web", "env_logger", "futures-util", @@ -2564,6 +2566,7 @@ dependencies = [ "dioxus-desktop", "dioxus-hot-reload", "dioxus-lib", + "dioxus-mobile", "dioxus-ssr", "dioxus-web", "dioxus_server_macro", diff --git a/packages/config-macro/Cargo.toml b/packages/config-macro/Cargo.toml index 0a67bd7f6..f7bba9255 100644 --- a/packages/config-macro/Cargo.toml +++ b/packages/config-macro/Cargo.toml @@ -20,6 +20,7 @@ quote = "1.0" default = [] fullstack = [] desktop = [] +mobile = [] web = [] ssr = [] liveview = [] diff --git a/packages/dioxus/Cargo.toml b/packages/dioxus/Cargo.toml index 98ea47e05..dfd75f72f 100644 --- a/packages/dioxus/Cargo.toml +++ b/packages/dioxus/Cargo.toml @@ -24,7 +24,8 @@ dioxus-mobile = { workspace = true, optional = true } dioxus-desktop = { workspace = true, optional = true } dioxus-fullstack = { workspace = true, optional = true } dioxus-liveview = { workspace = true, optional = true } -# dioxus-tui = { workspace = true, optional = true } +dioxus-ssr ={ workspace = true, optional = true } +dioxus-tui = { workspace = true, optional = true } serde = { version = "1.0.136", optional = true } @@ -45,14 +46,15 @@ router = ["dioxus-router"] # Platforms fullstack = ["dioxus-fullstack", "dioxus-config-macro/fullstack", "serde", "dioxus-router?/fullstack"] desktop = ["dioxus-desktop", "dioxus-fullstack?/desktop", "dioxus-config-macro/desktop"] -mobile = ["dioxus-mobile", "dioxus-fullstack?/desktop", "dioxus-config-macro/desktop"] # todo: use the mobile versions of these +mobile = ["dioxus-mobile", "dioxus-fullstack?/mobile", "dioxus-config-macro/mobile"] web = ["dioxus-web", "dioxus-fullstack?/web", "dioxus-config-macro/web", "dioxus-router?/web"] -ssr = ["dioxus-fullstack?/ssr", "dioxus-config-macro/ssr", "dioxus-router?/ssr"] +server = ["dioxus-fullstack?/ssr", "dioxus-config-macro/ssr", "dioxus-router?/ssr"] +ssr = ["dioxus-ssr"] liveview = ["dioxus-liveview", "dioxus-config-macro/liveview", "dioxus-router?/liveview"] axum = ["dioxus-fullstack?/axum"] salvo = ["dioxus-fullstack?/salvo"] warp = ["dioxus-fullstack?/warp"] -# tui = ["dioxus-tui", "dioxus-config-macro/tui"] +tui = ["dioxus-tui", "dioxus-config-macro/tui"] [dev-dependencies] futures-util = { workspace = true } diff --git a/packages/dioxus/src/launch.rs b/packages/dioxus/src/launch.rs index 89fc8e5e4..42d6df79d 100644 --- a/packages/dioxus/src/launch.rs +++ b/packages/dioxus/src/launch.rs @@ -153,10 +153,26 @@ mod current_platform { #[cfg(all(feature = "web", not(any(feature = "desktop", feature = "fullstack"))))] pub use dioxus_web::launch::*; - #[cfg(not(any(feature = "desktop", feature = "web", feature = "fullstack")))] + #[cfg(all( + feature = "tui", + not(any(feature = "web", feature = "desktop", feature = "fullstack")) + ))] + pub use dioxus_tui::launch::*; + + #[cfg(not(any( + feature = "desktop", + feature = "web", + feature = "tui", + feature = "fullstack" + )))] pub type Config = (); - #[cfg(not(any(feature = "desktop", feature = "web", feature = "fullstack")))] + #[cfg(not(any( + feature = "desktop", + feature = "web", + feature = "tui", + feature = "fullstack" + )))] pub fn launch( root: fn() -> dioxus_core::Element, contexts: Vec>, diff --git a/packages/dioxus/src/lib.rs b/packages/dioxus/src/lib.rs index 629167e92..232305de3 100644 --- a/packages/dioxus/src/lib.rs +++ b/packages/dioxus/src/lib.rs @@ -77,9 +77,18 @@ pub use dioxus_fullstack as fullstack; #[cfg(feature = "desktop")] pub use dioxus_desktop as desktop; +#[cfg(feature = "mobile")] +pub use dioxus_desktop as mobile; + +#[cfg(feature = "liveview")] +pub use dioxus_liveview as liveview; + #[cfg(feature = "tui")] pub use dioxus_tui as tui; +#[cfg(feature = "ssr")] +pub use dioxus_ssr as ssr; + /// Try to evaluate javascript in the target window /// /// For the browser, this is the window object diff --git a/packages/fullstack/Cargo.toml b/packages/fullstack/Cargo.toml index d22b9c8fe..f42f0d619 100644 --- a/packages/fullstack/Cargo.toml +++ b/packages/fullstack/Cargo.toml @@ -39,6 +39,9 @@ dioxus-web = { workspace = true, features = ["hydrate"], optional = true } # Desktop Integration dioxus-desktop = { workspace = true, optional = true } +# Mobile Integration +dioxus-mobile = { workspace = true, optional = true } + tracing = { workspace = true } tracing-futures = { workspace = true, optional = true } once_cell = "1.17.1" @@ -70,6 +73,7 @@ default = ["hot-reload"] hot-reload = ["serde_json", "futures-util"] web = ["dioxus-web", "web-sys"] desktop = ["dioxus-desktop"] +mobile = ["dioxus-mobile"] warp = ["dep:warp", "ssr"] axum = ["dep:axum", "tower-http", "ssr"] salvo = ["dep:salvo", "ssr", "http-body-util"] diff --git a/packages/fullstack/src/config.rs b/packages/fullstack/src/config.rs index 097a06301..b0db4e718 100644 --- a/packages/fullstack/src/config.rs +++ b/packages/fullstack/src/config.rs @@ -20,6 +20,9 @@ pub struct Config { #[cfg(feature = "desktop")] pub(crate) desktop_cfg: dioxus_desktop::Config, + + #[cfg(feature = "mobile")] + pub(crate) mobile_cfg: dioxus_mobile::Config, } #[allow(clippy::derivable_impls)] @@ -36,6 +39,8 @@ impl Default for Config { web_cfg: dioxus_web::Config::default(), #[cfg(feature = "desktop")] desktop_cfg: dioxus_desktop::Config::default(), + #[cfg(feature = "mobile")] + mobile_cfg: dioxus_mobile::Config::default(), } } } @@ -92,6 +97,12 @@ impl Config { } } + /// Set the mobile config. + #[cfg(feature = "mobile")] + pub fn mobile_cfg(self, mobile_cfg: dioxus_mobile::Config) -> Self { + Self { mobile_cfg, ..self } + } + #[cfg(feature = "ssr")] /// Launch a server application pub async fn launch_server( @@ -110,7 +121,7 @@ impl Config { let ssr_state = SSRState::new(&cfg); let router = axum::Router::new().register_server_fns(server_fn_route); - #[cfg(not(feature = "desktop"))] + #[cfg(not(any(feature = "desktop", feature = "mobile")))] let router = router .serve_static_assets(cfg.assets_path) .connect_hot_reload() @@ -132,7 +143,7 @@ impl Config { use warp::Filter; // First register the server functions let router = register_server_fns(server_fn_route); - #[cfg(not(feature = "desktop"))] + #[cfg(not(any(feature = "desktop", feature = "mobile")))] let router = { // Serve the dist folder and the index.html file let serve_dir = warp::fs::dir(cfg.assets_path); @@ -159,7 +170,7 @@ impl Config { use crate::adapters::salvo_adapter::{DioxusRouterExt, SSRHandler}; use salvo::conn::Listener; let router = salvo::Router::new().register_server_fns(server_fn_route); - #[cfg(not(feature = "desktop"))] + #[cfg(not(any(feature = "desktop", feature = "mobile")))] let router = router .serve_static_assets(cfg.assets_path) .connect_hot_reload() diff --git a/packages/fullstack/src/launch.rs b/packages/fullstack/src/launch.rs index 08e77da6a..cbb150d4c 100644 --- a/packages/fullstack/src/launch.rs +++ b/packages/fullstack/src/launch.rs @@ -41,5 +41,11 @@ pub fn launch( let cfg = platform_config.desktop_cfg; dioxus_desktop::launch::launch_virtual_dom(virtual_dom_factory(), cfg) } + + #[cfg(feature = "mobile")] + { + let cfg = platform_config.mobile_cfg; + dioxus_mobile::launch::launch_virtual_dom(virtual_dom_factory(), cfg) + } } } diff --git a/packages/fullstack/src/lib.rs b/packages/fullstack/src/lib.rs index 2bd5a2fa3..138559278 100644 --- a/packages/fullstack/src/lib.rs +++ b/packages/fullstack/src/lib.rs @@ -71,3 +71,6 @@ compile_error!("The `ssr` feature (enabled by `warp`, `axum`, or `salvo`) and `w #[cfg(all(feature = "ssr", feature = "desktop", not(doc)))] compile_error!("The `ssr` feature (enabled by `warp`, `axum`, or `salvo`) and `desktop` feature are overlapping. Please choose one or the other."); + +#[cfg(all(feature = "ssr", feature = "mobile", not(doc)))] +compile_error!("The `ssr` feature (enabled by `warp`, `axum`, or `salvo`) and `mobile` feature are overlapping. Please choose one or the other."); diff --git a/packages/mobile/Cargo.toml b/packages/mobile/Cargo.toml index 924e17fc6..4d3589ca6 100644 --- a/packages/mobile/Cargo.toml +++ b/packages/mobile/Cargo.toml @@ -10,7 +10,7 @@ keywords = ["dom", "ui", "gui", "react"] license = "MIT OR Apache-2.0" [dependencies] -dioxus-desktop = { workspace = true } +dioxus-desktop = { workspace = true, default-features = false, features = ["tokio_runtime"] } [lib] doctest = false