Skip to content

Commit

Permalink
Merge 0c0938c into 1955629
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 authored Jul 6, 2024
2 parents 1955629 + 0c0938c commit 9735f73
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ log = ["freya/log"]
devtools = ["freya/devtools"]
use_camera = ["freya/use_camera"]
hot-reload = ["freya/hot-reload"]
skia = ["freya/skia"]
custom-tokio-rt = ["freya/custom-tokio-rt"]

[patch.crates-io]
# dioxus = { git = "https://github.com/DioxusLabs/dioxus", rev = "7beacdf9c76ae5412d3c2bcd55f7c5d87f486a0f" }
Expand Down
4 changes: 3 additions & 1 deletion crates/freya/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ features = ["freya-engine/mocked-engine"]
no-default-features = true

[features]
custom-tokio-rt = []
skia = ["freya-engine/skia-engine"]
hot-reload = ["freya-renderer/hot-reload", "dioxus/hot-reload"]
log = ["dep:tracing", "dep:tracing-subscriber"]
devtools = ["dep:freya-devtools"]
use_camera = ["freya-hooks/use_camera"]
mocked-engine-development = ["freya-engine/mocked-engine"] # This is just for the CI
default = ["freya-engine/skia-engine"]
default = ["skia"]

[dependencies]
freya-devtools = { workspace = true, optional = true }
Expand Down
9 changes: 9 additions & 0 deletions crates/freya/src/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ pub fn launch_cfg<T: 'static + Clone>(app: AppComponent, config: LaunchConfig<T>
(vdom, None, None)
}
};
#[cfg(not(feature = "custom-tokio-rt"))]
{
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();
let _guard = rt.enter();
}

DesktopRenderer::launch(vdom, sdom, config, devtools, hovered_node);
}

Expand Down
7 changes: 0 additions & 7 deletions crates/renderer/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@ impl<'a, State: Clone + 'static> DesktopRenderer<'a, State> {
devtools: Option<Devtools>,
hovered_node: HoveredNode,
) {
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();

let _guard = rt.enter();

let event_loop = EventLoop::<EventMessage>::with_user_event()
.build()
.expect("Failed to create event loop.");
Expand Down
17 changes: 17 additions & 0 deletions examples/custom_tokio_rt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]

use freya::prelude::*;

#[cfg(not(feature = "custom-tokio-rt"))]
fn main() {
panic!("Run this example without the `custom-tokio-rt` feature.");
}

#[cfg(feature = "custom-tokio-rt")]
#[tokio::main]
async fn main() {
launch_with_title(|| rsx!(label { "Hello, World!" }), "Custom Tokio Runtime")
}

0 comments on commit 9735f73

Please sign in to comment.