Fix compile checks on numerous packages using --all --all-features

This commit is contained in:
Jonathan Kelley 2024-01-18 16:27:43 -08:00
parent 3506b3ea72
commit d8af9b7ed1
No known key found for this signature in database
GPG key ID: 1FBB50F7EB0A08BE
38 changed files with 147 additions and 186 deletions

4
Cargo.lock generated
View file

@ -2368,7 +2368,6 @@ dependencies = [
"tempfile", "tempfile",
"thiserror", "thiserror",
"tokio", "tokio",
"toml 0.5.11",
"toml_edit 0.19.15", "toml_edit 0.19.15",
"tower", "tower",
"tower-http 0.2.5", "tower-http 0.2.5",
@ -2449,14 +2448,13 @@ dependencies = [
"async-trait", "async-trait",
"core-foundation", "core-foundation",
"crossbeam-channel", "crossbeam-channel",
"dioxus",
"dioxus-cli-config", "dioxus-cli-config",
"dioxus-core", "dioxus-core",
"dioxus-core-macro",
"dioxus-hooks", "dioxus-hooks",
"dioxus-hot-reload", "dioxus-hot-reload",
"dioxus-html", "dioxus-html",
"dioxus-interpreter-js", "dioxus-interpreter-js",
"dioxus-signals",
"dunce", "dunce",
"exitcode", "exitcode",
"futures-channel", "futures-channel",

View file

@ -1,7 +1,7 @@
use dioxus::{events::*, html::MouseEvent, prelude::*}; use dioxus::{events::*, html::MouseEvent, prelude::*};
fn main() { fn main() {
launch_desktop(app); launch(app);
} }
#[derive(Debug)] #[derive(Debug)]

View file

@ -15,7 +15,7 @@ fn main() {
.with_inner_size(LogicalSize::new(300.0, 525.0)), .with_inner_size(LogicalSize::new(300.0, 525.0)),
); );
LaunchBuilder::desktop().cfg(config).launch(app); LaunchBuilder::desktop().with_cfg(config).launch(app);
} }
fn app() -> Element { fn app() -> Element {

View file

@ -4,7 +4,7 @@
use dioxus::prelude::*; use dioxus::prelude::*;
fn main() { fn main() {
launch_desktop(app); launch(app);
} }
fn app() -> Element { fn app() -> Element {

View file

@ -6,13 +6,13 @@ use dioxus_desktop::Config;
fn main() { fn main() {
LaunchBuilder::new() LaunchBuilder::new()
.cfg( .with_cfg(
Config::new().with_custom_head("<style>body { background-color: red; }</style>".into()), Config::new().with_custom_head("<style>body { background-color: red; }</style>".into()),
) )
.launch(app); .launch(app);
LaunchBuilder::new() LaunchBuilder::new()
.cfg( .with_cfg(
Config::new().with_custom_index( Config::new().with_custom_index(
r#" r#"
<!DOCTYPE html> <!DOCTYPE html>

View file

@ -13,7 +13,7 @@ use dioxus_desktop::{Config, WindowBuilder};
fn main() { fn main() {
LaunchBuilder::new() LaunchBuilder::new()
.cfg(Config::new().with_window(WindowBuilder::new().with_resizable(true))) .with_cfg(Config::new().with_window(WindowBuilder::new().with_resizable(true)))
.launch(app) .launch(app)
} }

View file

@ -3,7 +3,7 @@ use dioxus_desktop::Config;
fn main() { fn main() {
LaunchBuilder::desktop() LaunchBuilder::desktop()
.cfg(Config::new().with_file_drop_handler(|_w, e| { .with_cfg(Config::new().with_file_drop_handler(|_w, e| {
println!("{e:?}"); println!("{e:?}");
true true
})) }))

View file

@ -4,18 +4,14 @@ use dioxus_router::prelude::*;
fn main() { fn main() {
LaunchBuilder::desktop() LaunchBuilder::desktop()
.cfg( .with_cfg(
Config::new().with_window( Config::new().with_window(
WindowBuilder::new() WindowBuilder::new()
.with_inner_size(LogicalSize::new(600, 1000)) .with_inner_size(LogicalSize::new(600, 1000))
.with_resizable(false), .with_resizable(false),
), ),
) )
.launch(|| { .launch(|| rsx! { Router::<Route> {} })
rsx! {
Router::<Route> {}
}
})
} }
#[derive(Routable, Clone)] #[derive(Routable, Clone)]

View file

@ -14,7 +14,7 @@ use dioxus_desktop::Config;
fn main() { fn main() {
LaunchBuilder::desktop() LaunchBuilder::desktop()
.cfg(Config::new().with_prerendered({ .with_cfg(Config::new().with_prerendered({
// We build the dom a first time, then pre-render it to HTML // We build the dom a first time, then pre-render it to HTML
let pre_rendered_dom = VirtualDom::prebuilt(app); let pre_rendered_dom = VirtualDom::prebuilt(app);

View file

@ -2,7 +2,7 @@ use dioxus::prelude::*;
use dioxus_desktop::{tao::dpi::PhysicalPosition, LogicalSize, WindowBuilder}; use dioxus_desktop::{tao::dpi::PhysicalPosition, LogicalSize, WindowBuilder};
fn main() { fn main() {
LaunchBuilder::new().cfg(make_config()); LaunchBuilder::new().with_cfg(make_config());
} }
fn app() -> Element { fn app() -> Element {

View file

@ -32,7 +32,7 @@ fn main() {
.with_inner_size(LogicalSize::new(320.0, 530.0)), .with_inner_size(LogicalSize::new(320.0, 530.0)),
); );
LaunchBuilder::new().cfg(cfg).launch(app); LaunchBuilder::new().with_cfg(cfg).launch(app);
} }
const STYLE: &str = include_str!("./assets/calculator.css"); const STYLE: &str = include_str!("./assets/calculator.css");

View file

@ -4,7 +4,7 @@ use std::rc::Rc;
use dioxus::{html::geometry::euclid::Rect, prelude::*}; use dioxus::{html::geometry::euclid::Rect, prelude::*};
fn main() { fn main() {
LaunchBuilder::new().cfg( LaunchBuilder::new().with_cfg(
dioxus_desktop::Config::default().with_custom_head( dioxus_desktop::Config::default().with_custom_head(
r#" r#"
<style type="text/css"> <style type="text/css">

View file

@ -18,7 +18,7 @@ use dioxus_desktop::{Config, LogicalSize, WindowBuilder};
fn main() { fn main() {
LaunchBuilder::desktop() LaunchBuilder::desktop()
.cfg( .with_cfg(
Config::new().with_window( Config::new().with_window(
WindowBuilder::new() WindowBuilder::new()
.with_title("Doggo Fetcher") .with_title("Doggo Fetcher")

View file

@ -3,7 +3,7 @@ use dioxus_desktop::{window, Config, WindowBuilder};
fn main() { fn main() {
LaunchBuilder::desktop() LaunchBuilder::desktop()
.cfg( .with_cfg(
Config::new().with_window( Config::new().with_window(
WindowBuilder::new() WindowBuilder::new()
.with_title("Borderless Window") .with_title("Borderless Window")

View file

@ -6,7 +6,7 @@ use dioxus_desktop::{Config, WindowCloseBehaviour};
fn main() { fn main() {
LaunchBuilder::new() LaunchBuilder::new()
.cfg(Config::new().with_close_behaviour(WindowCloseBehaviour::CloseWindow)) .with_cfg(Config::new().with_close_behaviour(WindowCloseBehaviour::CloseWindow))
.launch(app) .launch(app)
} }

View file

@ -15,7 +15,7 @@ serde_json = "1.0.79"
toml = { version = "0.5.8", optional = true } toml = { version = "0.5.8", optional = true }
cargo_toml = { version = "0.16.0", optional = true } cargo_toml = { version = "0.16.0", optional = true }
once_cell = "1.18.0" once_cell = "1.18.0"
tracing.workspace = true tracing = { workspace = true }
# bundling # bundling
tauri-bundler = { version = "=1.4.0", features = ["native-tls-vendored"], optional = true } tauri-bundler = { version = "=1.4.0", features = ["native-tls-vendored"], optional = true }

View file

@ -21,7 +21,6 @@ log = "0.4.14"
fern = { version = "0.6.0", features = ["colored"] } fern = { version = "0.6.0", features = ["colored"] }
serde = { version = "1.0.136", features = ["derive"] } serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.79" serde_json = "1.0.79"
toml = "0.5.8"
fs_extra = "1.2.0" fs_extra = "1.2.0"
cargo_toml = "0.16.0" cargo_toml = "0.16.0"
futures = "0.3.21" futures = "0.3.21"
@ -89,7 +88,7 @@ interprocess-docfix = { version = "1.2.2" }
gitignore = "1.0.8" gitignore = "1.0.8"
[features] [features]
default = [] default = ["plugin"]
plugin = ["mlua"] plugin = ["mlua"]
[[bin]] [[bin]]

View file

@ -4,14 +4,11 @@ use std::{
sync::Mutex, sync::Mutex,
}; };
use crate::tools::{app_path, clone_repo};
use dioxus_cli_config::CrateConfig;
use mlua::{Lua, Table}; use mlua::{Lua, Table};
use serde_json::json; use serde_json::json;
use crate::{
tools::{app_path, clone_repo},
CrateConfig,
};
use self::{ use self::{
interface::{ interface::{
command::PluginCommander, dirs::PluginDirs, fs::PluginFileSystem, log::PluginLogger, command::PluginCommander, dirs::PluginDirs, fs::PluginFileSystem, log::PluginLogger,

View file

@ -21,7 +21,7 @@ use std::{
use tokio::sync::broadcast::{self}; use tokio::sync::broadcast::{self};
#[cfg(feature = "plugin")] #[cfg(feature = "plugin")]
use plugin::PluginManager; use crate::plugin::PluginManager;
use super::HotReloadState; use super::HotReloadState;

View file

@ -110,7 +110,7 @@ async fn setup_file_watcher<F: Fn() -> Result<BuildResult> + Send + 'static>(
); );
#[cfg(feature = "plugin")] #[cfg(feature = "plugin")]
let _ = PluginManager::on_serve_rebuild( let _ = crate::plugin::PluginManager::on_serve_rebuild(
chrono::Local::now().timestamp(), chrono::Local::now().timestamp(),
e.paths, e.paths,
); );

View file

@ -39,7 +39,7 @@ use tower_http::{
}; };
#[cfg(feature = "plugin")] #[cfg(feature = "plugin")]
use plugin::PluginManager; use crate::plugin::PluginManager;
mod proxy; mod proxy;
@ -159,10 +159,10 @@ pub async fn serve(
); );
// Router // Router
let router = setup_router(config, ws_reload_state, hot_reload_state).await?; let router = setup_router(config.clone(), ws_reload_state, hot_reload_state).await?;
// Start server // Start server
start_server(port, router, start_browser, rustls_config).await?; start_server(port, router, start_browser, rustls_config, &config).await?;
Ok(()) Ok(())
} }
@ -366,10 +366,11 @@ async fn start_server(
router: Router, router: Router,
start_browser: bool, start_browser: bool,
rustls: Option<RustlsConfig>, rustls: Option<RustlsConfig>,
config: &CrateConfig,
) -> Result<()> { ) -> Result<()> {
// If plugins, call on_serve_start event // If plugins, call on_serve_start event
#[cfg(feature = "plugin")] #[cfg(feature = "plugin")]
PluginManager::on_serve_start(&config)?; PluginManager::on_serve_start(config)?;
// Parse address // Parse address
let addr = format!("0.0.0.0:{}", port).parse().unwrap(); let addr = format!("0.0.0.0:{}", port).parse().unwrap();

View file

@ -118,18 +118,3 @@ impl<F: Fn() -> Element + Clone + 'static> ComponentFunction<(), EmptyMarker> fo
self() self()
} }
} }
#[test]
fn it_works_maybe() {
fn test(_: ()) -> Element {
todo!()
}
fn test2() -> Element {
todo!()
}
let callable: Rc<dyn ComponentFunction<(), ()>> =
Rc::new(test) as Rc<dyn ComponentFunction<_, _>>;
let callable2: Rc<dyn ComponentFunction<(), EmptyMarker>> =
Rc::new(test2) as Rc<dyn ComponentFunction<_, _>>;
}

View file

@ -30,7 +30,7 @@ wry = { version = "0.35.0", default-features = false, features = [
"protocol", "protocol",
"file-drop", "file-drop",
] } ] }
futures-channel.workspace = true futures-channel = { workspace = true }
tokio = { workspace = true, features = [ tokio = { workspace = true, features = [
"sync", "sync",
"rt-multi-thread", "rt-multi-thread",
@ -79,9 +79,7 @@ default-features = false
features = ["tokio_runtime", "hot-reload"] features = ["tokio_runtime", "hot-reload"]
[dev-dependencies] [dev-dependencies]
dioxus-core-macro = { workspace = true } dioxus = { workspace = true, features = ["launch", "desktop"]}
dioxus-hooks = { workspace = true }
dioxus-signals = { workspace = true }
exitcode = "1.1.2" exitcode = "1.1.2"
[build-dependencies] [build-dependencies]

View file

@ -1,15 +1,13 @@
use dioxus::prelude::*; use dioxus::prelude::*;
fn app() -> Element { fn app() -> Element {
let state = use_signal(|| 0); let mut state = use_signal(|| 0);
use_future(|| {
to_owned![state]; use_future(|| async move {
async move {
loop { loop {
state += 1; state += 1;
tokio::time::sleep(std::time::Duration::from_millis(1)).await; tokio::time::sleep(std::time::Duration::from_millis(1)).await;
} }
}
}); });
rsx! { rsx! {
@ -28,5 +26,5 @@ fn app() -> Element {
} }
fn main() { fn main() {
dioxus_desktop::launch(app); launch(app);
} }

View file

@ -1,8 +1,9 @@
use dioxus::html::geometry::euclid::Vector3D; use dioxus::html::geometry::euclid::Vector3D;
use dioxus::prelude::*; use dioxus::prelude::*;
use dioxus_core::prelude::consume_context;
use dioxus_desktop::DesktopContext; use dioxus_desktop::DesktopContext;
pub(crate) fn check_app_exits(app: Component) { pub(crate) fn check_app_exits(app: fn() -> Element) {
use dioxus_desktop::tao::window::WindowBuilder; use dioxus_desktop::tao::window::WindowBuilder;
use dioxus_desktop::Config; use dioxus_desktop::Config;
// This is a deadman's switch to ensure that the app exits // This is a deadman's switch to ensure that the app exits
@ -15,10 +16,9 @@ pub(crate) fn check_app_exits(app: Component) {
} }
}); });
dioxus_desktop::launch_cfg( LaunchBuilder::desktop()
app, .with_cfg(Config::new().with_window(WindowBuilder::new().with_visible(true)))
Config::new().with_window(WindowBuilder::new().with_visible(true)), .launch(app);
);
// Stop deadman's switch // Stop deadman's switch
should_panic.store(false, std::sync::atomic::Ordering::SeqCst); should_panic.store(false, std::sync::atomic::Ordering::SeqCst);
@ -29,10 +29,10 @@ pub fn main() {
} }
fn mock_event(id: &'static str, value: &'static str) { fn mock_event(id: &'static str, value: &'static str) {
let eval_provider = use_eval(cx).clone(); use_effect(move || {
spawn(async move {
use_effect(move |_| async move {
tokio::time::sleep(std::time::Duration::from_millis(100)).await; tokio::time::sleep(std::time::Duration::from_millis(100)).await;
let js = format!( let js = format!(
r#" r#"
//console.log("ran"); //console.log("ran");
@ -45,14 +45,15 @@ fn mock_event(id: &'static str, value: &'static str) {
value, id value, id
); );
eval_provider(&js).unwrap(); dioxus::eval(js);
});
}) })
} }
#[allow(deprecated)] #[allow(deprecated)]
fn app() -> Element { fn app() -> Element {
let desktop_context: DesktopContext = cx.consume_context().unwrap(); let desktop_context: DesktopContext = consume_context();
let received_events = use_signal(|| 0); let mut received_events = use_signal(|| 0);
// button // button
mock_event( mock_event(
@ -204,7 +205,7 @@ fn app() -> Element {
r#"new FocusEvent("focusout",{bubbles: true})"#, r#"new FocusEvent("focusout",{bubbles: true})"#,
); );
if **received_events == 13 { if received_events() == 13 {
println!("all events recieved"); println!("all events recieved");
desktop_context.close(); desktop_context.close();
} }
@ -214,15 +215,13 @@ fn app() -> Element {
div { div {
width: "100px", width: "100px",
height: "100px", height: "100px",
onmounted: move |evt| { onmounted: move |evt| async move {
to_owned![received_events]; todo!();
async move { // let rect = evt.get_client_rect().await.unwrap();
let rect = evt.get_client_rect().await.unwrap(); // println!("rect: {:?}", rect);
println!("rect: {:?}", rect); // assert_eq!(rect.width(), 100.0);
assert_eq!(rect.width(), 100.0); // assert_eq!(rect.height(), 100.0);
assert_eq!(rect.height(), 100.0); // received_events.with_mut(|x| *x + 1)
received_events.modify(|x| *x + 1)
}
} }
} }
button { button {
@ -235,7 +234,7 @@ fn app() -> Element {
event.data.trigger_button(), event.data.trigger_button(),
Some(dioxus_html::input_data::MouseButton::Primary), Some(dioxus_html::input_data::MouseButton::Primary),
); );
received_events.modify(|x| *x + 1) received_events.with_mut(|x| *x + 1);
} }
} }
div { div {
@ -249,7 +248,7 @@ fn app() -> Element {
.held_buttons() .held_buttons()
.contains(dioxus_html::input_data::MouseButton::Secondary), .contains(dioxus_html::input_data::MouseButton::Secondary),
); );
received_events.modify(|x| *x + 1) received_events.with_mut(|x| *x + 1);
} }
} }
div { div {
@ -267,7 +266,7 @@ fn app() -> Element {
event.data.trigger_button(), event.data.trigger_button(),
Some(dioxus_html::input_data::MouseButton::Secondary), Some(dioxus_html::input_data::MouseButton::Secondary),
); );
received_events.modify(|x| *x + 1) received_events.with_mut(|x| *x + 1);
} }
} }
div { div {
@ -288,7 +287,7 @@ fn app() -> Element {
event.data.trigger_button(), event.data.trigger_button(),
Some(dioxus_html::input_data::MouseButton::Secondary), Some(dioxus_html::input_data::MouseButton::Secondary),
); );
received_events.modify(|x| *x + 1) received_events.with_mut(|x| *x + 1);
} }
} }
div { div {
@ -306,7 +305,7 @@ fn app() -> Element {
event.data.trigger_button(), event.data.trigger_button(),
Some(dioxus_html::input_data::MouseButton::Secondary), Some(dioxus_html::input_data::MouseButton::Secondary),
); );
received_events.modify(|x| *x + 1) received_events.with_mut(|x| *x + 1);
} }
} }
div { div {
@ -319,7 +318,7 @@ fn app() -> Element {
event.data.trigger_button(), event.data.trigger_button(),
Some(dioxus_html::input_data::MouseButton::Primary), Some(dioxus_html::input_data::MouseButton::Primary),
); );
received_events.modify(|x| *x + 1) received_events.with_mut(|x| *x + 1);
} }
} }
div { div {
@ -332,7 +331,7 @@ fn app() -> Element {
let dioxus_html::geometry::WheelDelta::Pixels(delta) = event.data.delta() else { let dioxus_html::geometry::WheelDelta::Pixels(delta) = event.data.delta() else {
panic!("Expected delta to be in pixels") }; panic!("Expected delta to be in pixels") };
assert_eq!(delta, Vector3D::new(1.0, 2.0, 3.0)); assert_eq!(delta, Vector3D::new(1.0, 2.0, 3.0));
received_events.modify(|x| *x + 1) received_events.with_mut(|x| *x + 1);
} }
} }
input { input {
@ -344,7 +343,7 @@ fn app() -> Element {
assert_eq!(event.data.code().to_string(), "KeyA"); assert_eq!(event.data.code().to_string(), "KeyA");
assert_eq!(event.data.location(), Location::Standard); assert_eq!(event.data.location(), Location::Standard);
assert!(event.data.is_auto_repeating()); assert!(event.data.is_auto_repeating());
received_events.modify(|x| *x + 1) received_events.with_mut(|x| *x + 1);
} }
} }
input { input {
@ -356,7 +355,7 @@ fn app() -> Element {
assert_eq!(event.data.code().to_string(), "KeyA"); assert_eq!(event.data.code().to_string(), "KeyA");
assert_eq!(event.data.location(), Location::Standard); assert_eq!(event.data.location(), Location::Standard);
assert!(!event.data.is_auto_repeating()); assert!(!event.data.is_auto_repeating());
received_events.modify(|x| *x + 1) received_events.with_mut(|x| *x + 1);
} }
} }
input { input {
@ -368,21 +367,21 @@ fn app() -> Element {
assert_eq!(event.data.code().to_string(), "KeyA"); assert_eq!(event.data.code().to_string(), "KeyA");
assert_eq!(event.data.location(), Location::Standard); assert_eq!(event.data.location(), Location::Standard);
assert!(!event.data.is_auto_repeating()); assert!(!event.data.is_auto_repeating());
received_events.modify(|x| *x + 1) received_events.with_mut(|x| *x + 1);
} }
} }
input { input {
id: "focus_in_div", id: "focus_in_div",
onfocusin: move |event| { onfocusin: move |event| {
println!("{:?}", event.data); println!("{:?}", event.data);
received_events.modify(|x| *x + 1) received_events.with_mut(|x| *x + 1);
} }
} }
input { input {
id: "focus_out_div", id: "focus_out_div",
onfocusout: move |event| { onfocusout: move |event| {
println!("{:?}", event.data); println!("{:?}", event.data);
received_events.modify(|x| *x + 1) received_events.with_mut(|x| *x + 1);
} }
} }
} }

View file

@ -1,12 +1,12 @@
use dioxus::prelude::*; use dioxus::prelude::*;
use dioxus_core::Element; use dioxus_core::Element;
use dioxus_desktop::DesktopContext; use dioxus_desktop::{window, DesktopContext};
fn main() { fn main() {
check_app_exits(check_html_renders); check_app_exits(check_html_renders);
} }
pub(crate) fn check_app_exits(app: Component) { pub(crate) fn check_app_exits(app: fn() -> Element) {
use dioxus_desktop::Config; use dioxus_desktop::Config;
use tao::window::WindowBuilder; use tao::window::WindowBuilder;
// This is a deadman's switch to ensure that the app exits // This is a deadman's switch to ensure that the app exits
@ -19,30 +19,35 @@ pub(crate) fn check_app_exits(app: Component) {
} }
}); });
dioxus_desktop::launch_cfg( LaunchBuilder::desktop()
app, .with_cfg(Config::new().with_window(WindowBuilder::new().with_visible(true)))
Config::new().with_window(WindowBuilder::new().with_visible(true)), .launch(app);
);
should_panic.store(false, std::sync::atomic::Ordering::SeqCst); should_panic.store(false, std::sync::atomic::Ordering::SeqCst);
} }
fn use_inner_html(d: &'static str) -> Option<String> { fn use_inner_html(id: &'static str) -> Option<String> {
let value: Signal<Option<String>> = use_signal(|| None); let mut value = use_signal(|| None as Option<String>);
use_effect(|| async move {
use_effect(move || {
spawn(async move {
tokio::time::sleep(std::time::Duration::from_millis(100)).await; tokio::time::sleep(std::time::Duration::from_millis(100)).await;
window().eval();
let html = eval_provider(&format!( let res = dioxus::eval(format!(
r#"let element = document.getElementById('{}'); r#"let element = document.getElementById('{}');
return element.innerHTML"#, return element.innerHTML"#,
id id
)) ))
.unwrap(); .await;
if let Ok(serde_json::Value::String(html)) = html.await {
if let Ok(html) = res {
// serde_json::Value::String(html)
println!("html: {}", html); println!("html: {}", html);
value.set(Some(html)); value.set(Some(html));
} }
}); });
});
value.read().clone() value.read().clone()
} }
@ -51,7 +56,7 @@ const EXPECTED_HTML: &str = r#"<div id="5" style="width: 100px; height: 100px; c
fn check_html_renders() -> Element { fn check_html_renders() -> Element {
let inner_html = use_inner_html("main_div"); let inner_html = use_inner_html("main_div");
let desktop_context: DesktopContext = cx.consume_context().unwrap(); let desktop_context: DesktopContext = consume_context();
if let Some(raw_html) = inner_html { if let Some(raw_html) = inner_html {
println!("{}", raw_html); println!("{}", raw_html);

View file

@ -87,7 +87,7 @@ impl LaunchBuilder {
impl<Cfg: Default> LaunchBuilder<Cfg> { impl<Cfg: Default> LaunchBuilder<Cfg> {
#[cfg(feature = "fullstack")] #[cfg(feature = "fullstack")]
/// Inject state into the root component's context that is created on the thread that the app is launched on. /// Inject state into the root component's context that is created on the thread that the app is launched on.
pub fn context_provider( pub fn with_context_provider(
mut self, mut self,
state: impl Fn() -> Box<dyn Any> + Send + Sync + 'static, state: impl Fn() -> Box<dyn Any> + Send + Sync + 'static,
) -> Self { ) -> Self {
@ -98,7 +98,7 @@ impl<Cfg: Default> LaunchBuilder<Cfg> {
#[cfg(not(feature = "fullstack"))] #[cfg(not(feature = "fullstack"))]
/// Inject state into the root component's context that is created on the thread that the app is launched on. /// Inject state into the root component's context that is created on the thread that the app is launched on.
pub fn context_provider(mut self, state: impl Fn() -> Box<dyn Any> + 'static) -> Self { pub fn with_context_provider(mut self, state: impl Fn() -> Box<dyn Any> + 'static) -> Self {
self.contexts self.contexts
.push(Box::new(state) as Box<dyn Fn() -> Box<dyn Any>>); .push(Box::new(state) as Box<dyn Fn() -> Box<dyn Any>>);
self self
@ -106,7 +106,7 @@ impl<Cfg: Default> LaunchBuilder<Cfg> {
#[cfg(feature = "fullstack")] #[cfg(feature = "fullstack")]
/// Inject state into the root component's context. /// Inject state into the root component's context.
pub fn context(mut self, state: impl Any + Clone + Send + Sync + 'static) -> Self { pub fn with_context(mut self, state: impl Any + Clone + Send + Sync + 'static) -> Self {
self.contexts self.contexts
.push(Box::new(move || Box::new(state.clone()))); .push(Box::new(move || Box::new(state.clone())));
self self
@ -114,14 +114,14 @@ impl<Cfg: Default> LaunchBuilder<Cfg> {
#[cfg(not(feature = "fullstack"))] #[cfg(not(feature = "fullstack"))]
/// Inject state into the root component's context. /// Inject state into the root component's context.
pub fn context(mut self, state: impl Any + Clone + 'static) -> Self { pub fn with_context(mut self, state: impl Any + Clone + 'static) -> Self {
self.contexts self.contexts
.push(Box::new(move || Box::new(state.clone()))); .push(Box::new(move || Box::new(state.clone())));
self self
} }
/// Provide a platform-specific config to the builder. /// Provide a platform-specific config to the builder.
pub fn cfg(mut self, config: impl Into<Option<Cfg>>) -> Self { pub fn with_cfg(mut self, config: impl Into<Option<Cfg>>) -> Self {
if let Some(config) = config.into() { if let Some(config) = config.into() {
self.platform_config = Some(config); self.platform_config = Some(config);
} }

View file

@ -76,3 +76,13 @@ pub use dioxus_desktop as desktop;
#[cfg(feature = "tui")] #[cfg(feature = "tui")]
pub use dioxus_tui as tui; pub use dioxus_tui as tui;
/// Try to evaluate javascript in the target window
///
/// For the browser, this is the window object
/// For desktop/mobile, this is the webview object
///
/// For native, it will try and use the platform's JS engine if available
pub async fn eval(src: String) -> std::result::Result<String, Box<dyn std::error::Error>> {
todo!()
}

View file

@ -7,10 +7,10 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
wasm-bindgen.workspace = true wasm-bindgen = { workspace = true }
dioxus-autofmt.workspace = true dioxus-autofmt = { workspace = true }
rsx-rosetta.workspace = true rsx-rosetta = { workspace = true }
html_parser.workspace = true html_parser = { workspace = true }
[lib] [lib]

View file

@ -58,17 +58,16 @@ async-trait = "0.1.71"
bytes = "1.4.0" bytes = "1.4.0"
tower = { version = "0.4.13", features = ["util"], optional = true } tower = { version = "0.4.13", features = ["util"], optional = true }
tower-layer = { version = "0.3.2", optional = true } tower-layer = { version = "0.3.2", optional = true }
web-sys = { version = "0.3.61", optional = true, features = ["Window", "Document", "Element", "HtmlDocument", "Storage", "console"] }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
dioxus-hot-reload = { workspace = true } dioxus-hot-reload = { workspace = true }
[target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { version = "0.3.61", features = ["Window", "Document", "Element", "HtmlDocument", "Storage", "console"] }
[features] [features]
default = ["hot-reload"] default = ["hot-reload"]
hot-reload = ["serde_json", "futures-util"] hot-reload = ["serde_json", "futures-util"]
web = ["dioxus-web"] web = ["dioxus-web", "web-sys"]
desktop = ["dioxus-desktop"] desktop = ["dioxus-desktop"]
warp = ["dep:warp", "ssr"] warp = ["dep:warp", "ssr"]
axum = ["dep:axum", "tower-http", "ssr"] axum = ["dep:axum", "tower-http", "ssr"]

View file

@ -11,7 +11,7 @@ dioxus = { workspace = true, features = ["fullstack"]}
serde = "1.0.159" serde = "1.0.159"
simple_logger = "4.2.0" simple_logger = "4.2.0"
tracing-wasm = "0.2.1" tracing-wasm = "0.2.1"
tracing.workspace = true tracing = { workspace = true }
tracing-subscriber = "0.3.17" tracing-subscriber = "0.3.17"
reqwest = "0.11.18" reqwest = "0.11.18"

View file

@ -16,7 +16,7 @@ execute = "0.2.12"
reqwest = "0.11.18" reqwest = "0.11.18"
simple_logger = "4.2.0" simple_logger = "4.2.0"
tracing-wasm = "0.2.1" tracing-wasm = "0.2.1"
tracing.workspace = true tracing = { workspace = true }
tracing-subscriber = "0.3.17" tracing-subscriber = "0.3.17"
[features] [features]

View file

@ -10,7 +10,7 @@ publish = false
dioxus = { workspace = true, features = ["fullstack"] } dioxus = { workspace = true, features = ["fullstack"] }
serde = "1.0.159" serde = "1.0.159"
tracing-wasm = "0.2.1" tracing-wasm = "0.2.1"
tracing.workspace = true tracing = { workspace = true }
tracing-subscriber = "0.3.17" tracing-subscriber = "0.3.17"
reqwest = "0.11.18" reqwest = "0.11.18"

View file

@ -7,15 +7,19 @@ use std::sync::Arc;
/// Settings for a fullstack app. /// Settings for a fullstack app.
pub struct Config { pub struct Config {
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
server_fn_route: &'static str, pub(crate) server_fn_route: &'static str,
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
server_cfg: ServeConfigBuilder, pub(crate) server_cfg: ServeConfigBuilder,
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
addr: std::net::SocketAddr, pub(crate) addr: std::net::SocketAddr,
#[cfg(feature = "web")] #[cfg(feature = "web")]
web_cfg: dioxus_web::Config, pub(crate) web_cfg: dioxus_web::Config,
#[cfg(feature = "desktop")] #[cfg(feature = "desktop")]
desktop_cfg: dioxus_desktop::Config, pub(crate) desktop_cfg: dioxus_desktop::Config,
} }
#[allow(clippy::derivable_impls)] #[allow(clippy::derivable_impls)]
@ -88,44 +92,6 @@ impl Config {
} }
} }
/// Launch the app.
pub fn launch(self, build_virtual_dom: impl Fn() -> VirtualDom + Send + Sync + 'static) {
#[cfg(feature = "ssr")]
tokio::runtime::Runtime::new()
.unwrap()
.block_on(async move {
self.launch_server(build_virtual_dom).await;
});
#[cfg(not(feature = "ssr"))]
{
#[cfg(feature = "web")]
self.launch_web(build_virtual_dom);
#[cfg(feature = "desktop")]
self.launch_desktop(build_virtual_dom);
}
}
#[cfg(feature = "web")]
/// Launch the web application
pub fn launch_web(self, build_virtual_dom: impl Fn() -> VirtualDom + Send + Sync + 'static) {
#[cfg(not(feature = "ssr"))]
{
let cfg = self.web_cfg.hydrate(true);
dioxus_web::launch::launch_virtual_dom(
// TODO: this should pull the props from the document
build_virtual_dom(),
cfg,
);
}
}
#[cfg(feature = "desktop")]
/// Launch the web application
pub fn launch_desktop<P: AnyProps>(self, build_virtual_dom: impl Fn() -> VirtualDom + 'static) {
let cfg = self.desktop_cfg;
dioxus_desktop::launch::launch_with_props_blocking(self.component, self.props, cfg);
}
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
/// Launch a server application /// Launch a server application
pub async fn launch_server( pub async fn launch_server(

View file

@ -20,17 +20,27 @@ pub fn launch(
} }
vdom vdom
}; };
#[cfg(feature = "ssr")] #[cfg(feature = "ssr")]
tokio::runtime::Runtime::new() tokio::runtime::Runtime::new()
.unwrap() .unwrap()
.block_on(async move { .block_on(async move {
platform_config.launch_server(virtual_dom_factory).await; platform_config.launch_server(virtual_dom_factory).await;
}); });
#[cfg(not(feature = "ssr"))] #[cfg(not(feature = "ssr"))]
{ {
#[cfg(feature = "web")] #[cfg(feature = "web")]
platform_config.launch_web(virtual_dom_factory); {
// TODO: this should pull the props from the document
let cfg = platform_config.web_cfg.hydrate(true);
dioxus_web::launch::launch_virtual_dom(virtual_dom_factory(), cfg);
}
#[cfg(feature = "desktop")] #[cfg(feature = "desktop")]
platform_config.launch_desktop(virtual_dom_factory); {
let cfg = platform_config.desktop_cfg;
dioxus_desktop::launch::launch_virtual_dom(virtual_dom_factory(), cfg)
}
} }
} }

View file

@ -16,7 +16,7 @@ keywords = ["dom", "ui", "gui", "react"]
dioxus-autofmt = { workspace = true } dioxus-autofmt = { workspace = true }
dioxus-rsx = { workspace = true } dioxus-rsx = { workspace = true }
dioxus-html = { workspace = true, features = ["html-to-rsx"]} dioxus-html = { workspace = true, features = ["html-to-rsx"]}
html_parser.workspace = true html_parser = { workspace = true }
proc-macro2 = "1.0.49" proc-macro2 = "1.0.49"
quote = "1.0.23" quote = "1.0.23"
syn = { version = "2.0", features = ["full"] } syn = { version = "2.0", features = ["full"] }

View file

@ -20,7 +20,7 @@ quote = { version = "1.0" }
serde = { version = "1.0", features = ["derive"], optional = true } serde = { version = "1.0", features = ["derive"], optional = true }
internment = { version = "0.7.0", optional = true } internment = { version = "0.7.0", optional = true }
krates = { version = "0.12.6", optional = true } krates = { version = "0.12.6", optional = true }
tracing.workspace = true tracing = { workspace = true }
[features] [features]
default = ["html"] default = ["html"]

View file

@ -30,7 +30,7 @@ argh = "0.1.4"
serde = "1.0.120" serde = "1.0.120"
serde_json = "1.0.61" serde_json = "1.0.61"
fs_extra = "1.2.0" fs_extra = "1.2.0"
dioxus-signals.workspace = true dioxus-signals = { workspace = true }
[features] [features]
default = ["incremental"] default = ["incremental"]