mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-22 12:13:04 +00:00
add platform specific functions for launching apps for workspaces
This commit is contained in:
parent
71a08678a6
commit
db35a9b48c
53 changed files with 127 additions and 57 deletions
|
@ -1,7 +1,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use dioxus::{events::*, html::MouseEvent, prelude::*};
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -2,7 +2,7 @@ use dioxus::prelude::*;
|
|||
use dioxus_signals::use_signal;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -6,7 +6,7 @@ use dioxus::prelude::*;
|
|||
use futures_util::StreamExt;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::rc::Rc;
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -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,7 +1,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -2,7 +2,7 @@ use dioxus::prelude::*;
|
|||
use std::collections::HashMap;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -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,7 +1,7 @@
|
|||
use dioxus::{dioxus_core::CapturedError, prelude::*};
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -4,7 +4,7 @@ use dioxus::prelude::*;
|
|||
use tokio::time::sleep;
|
||||
|
||||
fn main() {
|
||||
launch(App);
|
||||
launch_desktop(App);
|
||||
}
|
||||
|
||||
fn App() -> Element {
|
||||
|
|
|
@ -7,7 +7,7 @@ fn main() {
|
|||
println!("{e:?}");
|
||||
true
|
||||
}))
|
||||
.launch()
|
||||
.launch_desktop()
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -13,7 +13,7 @@ fn main() {
|
|||
.with_resizable(false),
|
||||
),
|
||||
)
|
||||
.launch()
|
||||
.launch_desktop()
|
||||
}
|
||||
|
||||
#[derive(Routable, Clone)]
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::fmt::Display;
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
const FIELDS: &[(&str, &str)] = &[
|
||||
|
|
|
@ -2,7 +2,7 @@ use dioxus::prelude::*;
|
|||
use dioxus_router::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(App);
|
||||
launch_desktop(App);
|
||||
}
|
||||
|
||||
#[component]
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -2,7 +2,7 @@ use dioxus::prelude::*;
|
|||
use dioxus_router::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(Route::Home {});
|
||||
launch_desktop(Route::Home {});
|
||||
}
|
||||
|
||||
// ANCHOR: router
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
|
||||
fn main() {
|
||||
todo!()
|
||||
// launch(App);
|
||||
//launch_desktop(App);
|
||||
}
|
||||
|
||||
// use core::{fmt, str::FromStr};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -2,7 +2,7 @@ use dioxus::prelude::*;
|
|||
use dioxus_desktop::use_global_shortcut;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -2,7 +2,7 @@ use dioxus::prelude::*;
|
|||
use std::time::Duration;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -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,7 +1,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -54,7 +54,7 @@ fn Nav() -> Element {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
launch(Route::Blog {
|
||||
launch_desktop(Route::Blog {
|
||||
id: "hello".to_string(),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -25,7 +25,7 @@ fn main() {
|
|||
.with_inner_size(LogicalSize::new(600.0, 800.0)),
|
||||
),
|
||||
)
|
||||
.launch()
|
||||
.launch_desktop()
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -4,7 +4,7 @@ use dioxus::prelude::*;
|
|||
use rand::{thread_rng, Rng};
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -79,5 +79,5 @@ fn app() -> Element {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use dioxus::prelude::*;
|
|||
use std::time::Duration;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -26,7 +26,7 @@ fn main() {
|
|||
}
|
||||
});
|
||||
}
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -10,7 +10,7 @@ fn main() {
|
|||
.with_decorations(false),
|
||||
),
|
||||
)
|
||||
.launch()
|
||||
.launch_desktop()
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -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,7 +1,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
launch(app);
|
||||
launch_desktop(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue