Selaa lähdekoodia

Merge branch 'master' into fix-event-bubbling

Evan Almloff 1 vuosi sitten
vanhempi
commit
e113562c7c

+ 1 - 1
packages/cli/Cargo.toml

@@ -22,7 +22,7 @@ serde = { version = "1.0.136", features = ["derive"] }
 serde_json = "1.0.79"
 toml = "0.5.8"
 fs_extra = "1.2.0"
-cargo_toml = "0.11.4"
+cargo_toml = "0.16.0"
 futures = "0.3.21"
 notify = { version = "5.0.0-pre.16", features = ["serde"] }
 html_parser  = { workspace = true }

+ 4 - 4
packages/cli/src/cli/bundle.rs

@@ -132,10 +132,10 @@ impl Bundle {
             .project_out_directory(crate_config.out_dir)
             .package_settings(PackageSettings {
                 product_name: crate_config.dioxus_config.application.name.clone(),
-                version: package.version,
-                description: package.description.unwrap_or_default(),
-                homepage: package.homepage,
-                authors: Some(package.authors),
+                version: package.version().to_string(),
+                description: package.description().unwrap_or_default().to_string(),
+                homepage: Some(package.homepage().unwrap_or_default().to_string()),
+                authors: Some(Vec::from(package.authors())),
                 default_run: Some(crate_config.dioxus_config.application.name.clone()),
             })
             .binaries(binaries)

+ 6 - 6
packages/core/src/lib.rs

@@ -32,7 +32,7 @@ pub(crate) mod innerlude {
     pub use crate::nodes::RenderReturn;
     pub use crate::nodes::*;
     pub use crate::properties::*;
-    pub use crate::runtime::{in_runtime, override_runtime, Runtime};
+    pub use crate::runtime::{Runtime, RuntimeGuard};
     pub use crate::scheduler::*;
     pub use crate::scope_context::*;
     pub use crate::scopes::*;
@@ -87,11 +87,11 @@ pub use crate::innerlude::{
 pub mod prelude {
     pub use crate::innerlude::{
         consume_context, consume_context_from_scope, current_scope_id, fc_to_builder, has_context,
-        in_runtime, override_runtime, provide_context, provide_context_to_scope,
-        provide_root_context, push_future, remove_future, schedule_update_any, spawn,
-        spawn_forever, suspend, throw, AnyValue, Component, Element, Event, EventHandler, Fragment,
-        IntoAttributeValue, LazyNodes, Properties, Runtime, Scope, ScopeId, ScopeState, Scoped,
-        TaskId, Template, TemplateAttribute, TemplateNode, Throw, VNode, VirtualDom,
+        provide_context, provide_context_to_scope, provide_root_context, push_future,
+        remove_future, schedule_update_any, spawn, spawn_forever, suspend, throw, AnyValue,
+        Component, Element, Event, EventHandler, Fragment, IntoAttributeValue, LazyNodes,
+        Properties, Runtime, RuntimeGuard, Scope, ScopeId, ScopeState, Scoped, TaskId, Template,
+        TemplateAttribute, TemplateNode, Throw, VNode, VirtualDom,
     };
 }
 

+ 34 - 47
packages/core/src/runtime.rs

@@ -7,51 +7,6 @@ thread_local! {
     static RUNTIMES: RefCell<Vec<Rc<Runtime>>> = RefCell::new(vec![]);
 }
 
-/// Run some code within a runtime
-pub fn in_runtime<R>(runtime: Rc<Runtime>, f: impl FnOnce() -> R) -> R {
-    let _guard = RuntimeGuard::new(runtime);
-    f()
-}
-
-/// Override the current runtime. This must be used to override the current runtime when importing components from a dynamic library that has it's own runtime.
-///
-/// ```rust
-/// use dioxus::prelude::*;
-///
-/// fn main() {
-///     let virtual_dom = VirtualDom::new(app);
-/// }
-///
-/// fn app(cx: Scope) -> Element {
-///     render!{ Component { runtime: Runtime::current().unwrap() } }
-/// }
-///
-/// // In a dynamic library
-/// #[derive(Props)]
-/// struct ComponentProps {
-///    runtime: std::rc::Rc<Runtime>,
-/// }
-///
-/// impl PartialEq for ComponentProps {
-///     fn eq(&self, _other: &Self) -> bool {
-///         true
-///     }
-/// }
-///
-/// fn Component(cx: Scope<ComponentProps>) -> Element {
-///     cx.use_hook(|| override_runtime(cx.props.runtime.clone()));
-///
-///     render! { div {} }
-/// }
-/// ```
-pub fn override_runtime(runtime: Rc<Runtime>) {
-    RUNTIMES.with(|stack| {
-        let mut stack = stack.borrow_mut();
-        stack.pop();
-        stack.push(runtime);
-    });
-}
-
 /// Pushes a new scope onto the stack
 pub(crate) fn push_runtime(runtime: Rc<Runtime>) {
     RUNTIMES.with(|stack| stack.borrow_mut().push(runtime));
@@ -143,10 +98,42 @@ impl Runtime {
     }
 }
 
-pub(crate) struct RuntimeGuard(Rc<Runtime>);
+/// A gaurd for a new runtime. This must be used to override the current runtime when importing components from a dynamic library that has it's own runtime.
+///
+/// ```rust
+/// use dioxus::prelude::*;
+///
+/// fn main() {
+///     let virtual_dom = VirtualDom::new(app);
+/// }
+///
+/// fn app(cx: Scope) -> Element {
+///     render!{ Component { runtime: Runtime::current().unwrap() } }
+/// }
+///
+/// // In a dynamic library
+/// #[derive(Props)]
+/// struct ComponentProps {
+///    runtime: std::rc::Rc<Runtime>,
+/// }
+///
+/// impl PartialEq for ComponentProps {
+///     fn eq(&self, _other: &Self) -> bool {
+///         true
+///     }
+/// }
+///
+/// fn Component(cx: Scope<ComponentProps>) -> Element {
+///     cx.use_hook(|| RuntimeGuard::new(cx.props.runtime.clone()));
+///
+///     render! { div {} }
+/// }
+/// ```
+pub struct RuntimeGuard(Rc<Runtime>);
 
 impl RuntimeGuard {
-    pub(crate) fn new(runtime: Rc<Runtime>) -> Self {
+    /// Create a new runtime guard that sets the current Dioxus runtime. The runtime will be reset when the guard is dropped
+    pub fn new(runtime: Rc<Runtime>) -> Self {
         push_runtime(runtime.clone());
         Self(runtime)
     }

+ 1 - 0
packages/desktop/Cargo.toml

@@ -56,6 +56,7 @@ tokio_runtime = ["tokio"]
 fullscreen = ["wry/fullscreen"]
 transparent = ["wry/transparent"]
 devtools = ["wry/devtools"]
+tray = ["wry/tray"]
 dox = ["wry/dox"]
 hot-reload = ["dioxus-hot-reload"]
 

+ 44 - 0
packages/hooks/src/usestate.rs

@@ -336,6 +336,50 @@ impl<T> PartialEq<UseState<T>> for UseState<T> {
     }
 }
 
+impl<T: std::cmp::PartialOrd> PartialOrd<T> for UseState<T> {
+    fn ge(&self, other: &T) -> bool {
+        *self.current_val >= *other
+    }
+
+    fn gt(&self, other: &T) -> bool {
+        *self.current_val > *other
+    }
+
+    fn le(&self, other: &T) -> bool {
+        *self.current_val <= *other
+    }
+
+    fn lt(&self, other: &T) -> bool {
+        *self.current_val < *other
+    }
+
+    fn partial_cmp(&self, other: &T) -> Option<std::cmp::Ordering> {
+        (*self.current_val).partial_cmp(other)
+    }
+}
+
+impl<T: std::cmp::PartialOrd> PartialOrd<UseState<T>> for UseState<T> {
+    fn ge(&self, other: &UseState<T>) -> bool {
+        self.current_val >= other.current_val
+    }
+
+    fn gt(&self, other: &UseState<T>) -> bool {
+        self.current_val > other.current_val
+    }
+
+    fn le(&self, other: &UseState<T>) -> bool {
+        self.current_val <= other.current_val
+    }
+
+    fn lt(&self, other: &UseState<T>) -> bool {
+        self.current_val < other.current_val
+    }
+
+    fn partial_cmp(&self, other: &UseState<T>) -> Option<std::cmp::Ordering> {
+        self.current_val.partial_cmp(&other.current_val)
+    }
+}
+
 impl<T: Debug> Debug for UseState<T> {
     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
         write!(f, "{:?}", self.current_val)