(root: Component, props: P, cfg: Config)
}
});
+ // Copy over any assets we find
+ crate::collect_assets::copy_assets();
+
// We start the tokio runtime *on this thread*
// Any future we poll later will use this runtime to spawn tasks and for IO
let rt = tokio::runtime::Builder::new_multi_thread()
diff --git a/packages/desktop/src/protocol.rs b/packages/desktop/src/protocol.rs
index 53652f82f..4046ee42f 100644
--- a/packages/desktop/src/protocol.rs
+++ b/packages/desktop/src/protocol.rs
@@ -51,10 +51,12 @@ fn module_loader(root_name: &str) -> String {
)
}
+#[allow(unused_variables)]
pub(super) fn desktop_handler(
request: &Request>,
custom_head: Option,
custom_index: Option,
+ assets_head: Option,
root_name: &str,
) -> Result>> {
// If the request is for the root, we'll serve the index.html file.
@@ -70,9 +72,24 @@ pub(super) fn desktop_handler(
// Otherwise, we'll serve the default index.html and apply a custom head if that's specified.
let mut template = include_str!("./index.html").to_string();
- if let Some(custom_head) = custom_head {
- template = template.replace("", &custom_head);
+ #[allow(unused_mut)]
+ let mut head = custom_head.unwrap_or_default();
+ #[cfg(debug_assertions)]
+ {
+ use assets_cli_support::AssetManifestExt;
+ let manifest = assets_cli_support::AssetManifest::load();
+ head += &manifest.head();
}
+ #[cfg(not(debug_assertions))]
+ {
+ if let Some(assets_head) = assets_head {
+ head += &assets_head;
+ } else {
+ log::warn!("No assets head found. You can compile assets with the dioxus-cli in release mode");
+ }
+ }
+
+ template = template.replace("", &head);
template
.replace("", &module_loader(root_name))
diff --git a/packages/desktop/src/webview.rs b/packages/desktop/src/webview.rs
index 469aa8068..49475e903 100644
--- a/packages/desktop/src/webview.rs
+++ b/packages/desktop/src/webview.rs
@@ -18,6 +18,16 @@ pub fn build(
let custom_head = cfg.custom_head.clone();
let index_file = cfg.custom_index.clone();
let root_name = cfg.root_name.clone();
+ let assets_head = {
+ #[cfg(debug_assertions)]
+ {
+ None
+ }
+ #[cfg(not(debug_assertions))]
+ {
+ std::fs::read_to_string("public/assets_head.html").ok()
+ }
+ };
// We assume that if the icon is None in cfg, then the user just didnt set it
if cfg.window.window.window_icon.is_none() {
@@ -45,7 +55,13 @@ pub fn build(
}
})
.with_custom_protocol(String::from("dioxus"), move |r| {
- protocol::desktop_handler(r, custom_head.clone(), index_file.clone(), &root_name)
+ protocol::desktop_handler(
+ r,
+ custom_head.clone(),
+ index_file.clone(),
+ assets_head.clone(),
+ &root_name,
+ )
})
.with_file_drop_handler(move |window, evet| {
file_handler