Forráskód Böngészése

add platform specific functions for launching apps for workspaces

Evan Almloff 1 éve
szülő
commit
db35a9b48c
53 módosított fájl, 127 hozzáadás és 57 törlés
  1. 1 1
      examples/all_css.rs
  2. 1 1
      examples/all_events.rs
  3. 1 1
      examples/clock.rs
  4. 1 1
      examples/compose.rs
  5. 1 1
      examples/control_focus.rs
  6. 1 1
      examples/counter.rs
  7. 1 1
      examples/crm.rs
  8. 1 1
      examples/custom_assets.rs
  9. 1 1
      examples/disabled.rs
  10. 1 1
      examples/dog_app.rs
  11. 1 1
      examples/dynamic_asset.rs
  12. 1 1
      examples/error_handle.rs
  13. 1 1
      examples/eval.rs
  14. 1 1
      examples/file_explorer.rs
  15. 1 1
      examples/file_upload.rs
  16. 1 1
      examples/filedragdrop.rs
  17. 1 1
      examples/flat_router.rs
  18. 1 1
      examples/form.rs
  19. 1 1
      examples/generic_component.rs
  20. 1 1
      examples/hello_world.rs
  21. 1 1
      examples/hydration.rs
  22. 1 1
      examples/inputs.rs
  23. 1 1
      examples/link.rs
  24. 1 1
      examples/login_form.rs
  25. 1 1
      examples/multiwindow.rs
  26. 1 1
      examples/nested_listeners.rs
  27. 1 1
      examples/optional_props.rs
  28. 1 1
      examples/pattern_reducer.rs
  29. 1 1
      examples/readme.rs
  30. 1 1
      examples/router.rs
  31. 1 1
      examples/rsx_usage.rs
  32. 1 1
      examples/scroll_to_top.rs
  33. 1 1
      examples/shortcut.rs
  34. 1 1
      examples/shorthand.rs
  35. 1 1
      examples/signals.rs
  36. 1 1
      examples/simple_desktop.rs
  37. 1 1
      examples/simple_list.rs
  38. 1 1
      examples/simple_router.rs
  39. 1 1
      examples/streams.rs
  40. 1 1
      examples/suspense.rs
  41. 1 1
      examples/svg.rs
  42. 1 1
      examples/svg_basic.rs
  43. 1 1
      examples/tailwind/src/main.rs
  44. 1 1
      examples/tasks.rs
  45. 1 1
      examples/textarea.rs
  46. 1 1
      examples/todomvc.rs
  47. 1 1
      examples/video_stream.rs
  48. 1 1
      examples/web_component.rs
  49. 1 1
      examples/window_event.rs
  50. 1 1
      examples/window_focus.rs
  51. 1 1
      examples/window_zoom.rs
  52. 1 1
      examples/xss_safety.rs
  53. 75 5
      packages/dioxus/src/launch.rs

+ 1 - 1
examples/all_css.rs

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

+ 1 - 1
examples/all_events.rs

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

+ 1 - 1
examples/clock.rs

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

+ 1 - 1
examples/compose.rs

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

+ 1 - 1
examples/control_focus.rs

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

+ 1 - 1
examples/counter.rs

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

+ 1 - 1
examples/crm.rs

@@ -3,7 +3,7 @@ use dioxus::prelude::*;
 use dioxus_router::prelude::*;
 
 fn main() {
-    launch(app);
+    launch_desktop(app);
 }
 
 /// A type alias that reprsents a shared context between components

+ 1 - 1
examples/custom_assets.rs

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

+ 1 - 1
examples/disabled.rs

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

+ 1 - 1
examples/dog_app.rs

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

+ 1 - 1
examples/dynamic_asset.rs

@@ -2,7 +2,7 @@ use dioxus::prelude::*;
 use dioxus_desktop::{use_asset_handler, wry::http::Response};
 
 fn main() {
-    launch(app);
+    launch_desktop(app);
 }
 
 fn app() -> Element {

+ 1 - 1
examples/error_handle.rs

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

+ 1 - 1
examples/eval.rs

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

+ 1 - 1
examples/file_explorer.rs

@@ -14,7 +14,7 @@ use dioxus_desktop::{Config, WindowBuilder};
 fn main() {
     LaunchBuilder::new(app)
         .cfg(Config::new().with_window(WindowBuilder::new().with_resizable(true)))
-        .launch()
+        .launch_desktop()
 }
 
 const _STYLE: &str = manganis::mg!(file("./examples/assets/fileexplorer.css"));

+ 1 - 1
examples/file_upload.rs

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

+ 1 - 1
examples/filedragdrop.rs

@@ -7,7 +7,7 @@ fn main() {
             println!("{e:?}");
             true
         }))
-        .launch()
+        .launch_desktop()
 }
 
 fn app() -> Element {

+ 1 - 1
examples/flat_router.rs

@@ -13,7 +13,7 @@ fn main() {
                     .with_resizable(false),
             ),
         )
-        .launch()
+        .launch_desktop()
 }
 
 #[derive(Routable, Clone)]

+ 1 - 1
examples/form.rs

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

+ 1 - 1
examples/generic_component.rs

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

+ 1 - 1
examples/hello_world.rs

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

+ 1 - 1
examples/hydration.rs

@@ -21,7 +21,7 @@ fn main() {
             // We then launch the app with the pre-rendered HTML
             dioxus_ssr::pre_render(&pre_rendered_dom)
         }))
-        .launch();
+        .launch_desktop();
 }
 
 fn app() -> Element {

+ 1 - 1
examples/inputs.rs

@@ -5,7 +5,7 @@
 use dioxus::prelude::*;
 
 fn main() {
-    launch(app);
+    launch_desktop(app);
 }
 
 const FIELDS: &[(&str, &str)] = &[

+ 1 - 1
examples/link.rs

@@ -2,7 +2,7 @@ use dioxus::prelude::*;
 use dioxus_router::prelude::*;
 
 fn main() {
-    launch(App);
+    launch_desktop(App);
 }
 
 #[component]

+ 1 - 1
examples/login_form.rs

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

+ 1 - 1
examples/multiwindow.rs

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

+ 1 - 1
examples/nested_listeners.rs

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

+ 1 - 1
examples/optional_props.rs

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

+ 1 - 1
examples/pattern_reducer.rs

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

+ 1 - 1
examples/readme.rs

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

+ 1 - 1
examples/router.rs

@@ -2,7 +2,7 @@ use dioxus::prelude::*;
 use dioxus_router::prelude::*;
 
 fn main() {
-    launch(Route::Home {});
+    launch_desktop(Route::Home {});
 }
 
 // ANCHOR: router

+ 1 - 1
examples/rsx_usage.rs

@@ -40,7 +40,7 @@
 
 fn main() {
     todo!()
-    // launch(App);
+    //launch_desktop(App);
 }
 
 // use core::{fmt, str::FromStr};

+ 1 - 1
examples/scroll_to_top.rs

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

+ 1 - 1
examples/shortcut.rs

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

+ 1 - 1
examples/shorthand.rs

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

+ 1 - 1
examples/signals.rs

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

+ 1 - 1
examples/simple_desktop.rs

@@ -9,7 +9,7 @@ fn main() {
         .with_module_level("dioxus", log::LevelFilter::Trace)
         .init()
         .unwrap();
-    launch(Route::Home {});
+    launch_desktop(Route::Home {});
 }
 
 #[derive(Routable, Clone)]

+ 1 - 1
examples/simple_list.rs

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

+ 1 - 1
examples/simple_router.rs

@@ -54,7 +54,7 @@ fn Nav() -> Element {
 }
 
 fn main() {
-    launch(Route::Blog {
+    launch_desktop(Route::Blog {
         id: "hello".to_string(),
     });
 }

+ 1 - 1
examples/streams.rs

@@ -4,7 +4,7 @@ use futures_util::{future, stream, Stream, StreamExt};
 use std::time::Duration;
 
 fn main() {
-    launch(app);
+    launch_desktop(app);
 }
 
 fn app() -> Element {

+ 1 - 1
examples/suspense.rs

@@ -25,7 +25,7 @@ fn main() {
                     .with_inner_size(LogicalSize::new(600.0, 800.0)),
             ),
         )
-        .launch()
+        .launch_desktop()
 }
 
 fn app() -> Element {

+ 1 - 1
examples/svg.rs

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

+ 1 - 1
examples/svg_basic.rs

@@ -79,5 +79,5 @@ fn app() -> Element {
 }
 
 fn main() {
-    launch(app);
+    launch_desktop(app);
 }

+ 1 - 1
examples/tailwind/src/main.rs

@@ -6,7 +6,7 @@ const _STYLE: &str = manganis::mg!(file("./public/tailwind.css"));
 
 fn main() {
     #[cfg(not(target_arch = "wasm32"))]
-    launch(app);
+   launch_desktop(app);
     #[cfg(target_arch = "wasm32")]
     dioxus_web::launch(app);
 }

+ 1 - 1
examples/tasks.rs

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

+ 1 - 1
examples/textarea.rs

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

+ 1 - 1
examples/todomvc.rs

@@ -4,7 +4,7 @@ use dioxus_elements::input_data::keyboard_types::Key;
 use std::collections::HashMap;
 
 fn main() {
-    launch(app);
+    launch_desktop(app);
 }
 
 #[derive(PartialEq, Eq, Clone, Copy)]

+ 1 - 1
examples/video_stream.rs

@@ -26,7 +26,7 @@ fn main() {
                 }
             });
     }
-    launch(app);
+    launch_desktop(app);
 }
 
 fn app() -> Element {

+ 1 - 1
examples/web_component.rs

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

+ 1 - 1
examples/window_event.rs

@@ -10,7 +10,7 @@ fn main() {
                     .with_decorations(false),
             ),
         )
-        .launch()
+        .launch_desktop()
 }
 
 fn app() -> Element {

+ 1 - 1
examples/window_focus.rs

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

+ 1 - 1
examples/window_zoom.rs

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

+ 1 - 1
examples/xss_safety.rs

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

+ 75 - 5
packages/dioxus/src/launch.rs

@@ -12,18 +12,20 @@ pub struct LaunchBuilder<
     Component: ComponentFunction<Phantom, Props = Props>,
     Props: Clone + 'static,
     Phantom: 'static,
+    Platform: PlatformBuilder<Props> = CurrentPlatform,
 > {
     cross_platform_config: CrossPlatformConfig<Component, Props, Phantom>,
-    platform_config: Option<<CurrentPlatform as PlatformBuilder<Props>>::Config>,
+    platform_config: Option<<Platform as PlatformBuilder<Props>>::Config>,
 }
 
+// Default platform builder
 impl<
         Component: ComponentFunction<Phantom, Props = Props>,
         Props: Clone + 'static,
         Phantom: 'static,
     > LaunchBuilder<Component, Props, Phantom>
 {
-    /// Create a new builder for your application.
+    /// Create a new builder for your application. This will create a launch configuration for the current platform based on the features enabled on the `dioxus` crate.
     pub fn new(component: Component) -> Self
     where
         Props: Default,
@@ -37,7 +39,15 @@ impl<
             platform_config: None,
         }
     }
+}
 
+impl<
+        Component: ComponentFunction<Phantom, Props = Props>,
+        Props: Clone + 'static,
+        Phantom: 'static,
+        Platform: PlatformBuilder<Props>,
+    > LaunchBuilder<Component, Props, Phantom, Platform>
+{
     /// Pass some props to your application.
     pub fn props(mut self, props: Props) -> Self {
         self.cross_platform_config.props = props;
@@ -55,7 +65,7 @@ impl<
     /// Provide a platform-specific config to the builder.
     pub fn cfg(
         mut self,
-        config: impl Into<Option<<CurrentPlatform as PlatformBuilder<Props>>::Config>>,
+        config: impl Into<Option<<Platform as PlatformBuilder<Props>>::Config>>,
     ) -> Self {
         if let Some(config) = config.into() {
             self.platform_config = Some(config);
@@ -66,7 +76,39 @@ impl<
     #[allow(clippy::unit_arg)]
     /// Launch the app.
     pub fn launch(self) {
-        CurrentPlatform::launch(
+        Platform::launch(
+            self.cross_platform_config,
+            self.platform_config.unwrap_or_default(),
+        );
+    }
+}
+
+#[cfg(feature = "web")]
+impl<
+        Component: ComponentFunction<Phantom, Props = Props>,
+        Props: Clone + 'static,
+        Phantom: 'static,
+    > LaunchBuilder<Component, Props, Phantom, dioxus_web::WebPlatform>
+{
+    /// Launch your web application.
+    pub fn launch_web(self) {
+        dioxus_web::WebPlatform::launch(
+            self.cross_platform_config,
+            self.platform_config.unwrap_or_default(),
+        );
+    }
+}
+
+#[cfg(feature = "desktop")]
+impl<
+        Component: ComponentFunction<Phantom, Props = Props>,
+        Props: Clone + 'static,
+        Phantom: 'static,
+    > LaunchBuilder<Component, Props, Phantom, dioxus_desktop::DesktopPlatform>
+{
+    /// Launch your desktop application.
+    pub fn launch_desktop(self) {
+        dioxus_desktop::DesktopPlatform::launch(
             self.cross_platform_config,
             self.platform_config.unwrap_or_default(),
         );
@@ -75,7 +117,7 @@ impl<
 
 #[cfg(feature = "desktop")]
 type CurrentPlatform = dioxus_desktop::DesktopPlatform;
-#[cfg(feature = "web")]
+#[cfg(all(feature = "web", not(feature = "desktop")))]
 type CurrentPlatform = dioxus_web::WebPlatform;
 #[cfg(not(any(feature = "desktop", feature = "web")))]
 type CurrentPlatform = ();
@@ -92,3 +134,31 @@ pub fn launch<
 {
     LaunchBuilder::new(component).launch()
 }
+
+#[cfg(feature = "web")]
+/// Launch your web application without any additional configuration. See [`LaunchBuilder`] for more options.
+pub fn launch_web<
+    Component: ComponentFunction<Phantom, Props = Props>,
+    Props: Clone + 'static,
+    Phantom: 'static,
+>(
+    component: Component,
+) where
+    Props: Default,
+{
+    LaunchBuilder::new(component).launch_web()
+}
+
+#[cfg(feature = "desktop")]
+/// Launch your desktop application without any additional configuration. See [`LaunchBuilder`] for more options.
+pub fn launch_desktop<
+    Component: ComponentFunction<Phantom, Props = Props>,
+    Props: Clone + 'static,
+    Phantom: 'static,
+>(
+    component: Component,
+) where
+    Props: Default,
+{
+    LaunchBuilder::new(component).launch_desktop()
+}