fix manganis support for dioxus desktop
This commit is contained in:
1 parent
ef101dd876
commit
3270f7341a
9 files changed
+63
-58
No files matched your search
@@ -37,9 +37,9 @@ pub(crate) fn process_assets(config: &CrateConfig, manifest: &AssetManifest) ->
|
||||
}
|
||||
|
||||
/// A guard that sets up the environment for the web renderer to compile in. This guard sets the location that assets will be served from
|
||||
pub(crate) struct WebAssetConfigDropGuard;
|
||||
pub(crate) struct AssetConfigDropGuard;
|
||||
|
||||
impl WebAssetConfigDropGuard {
|
||||
impl AssetConfigDropGuard {
|
||||
pub fn new() -> Self {
|
||||
// Set up the collect asset config
|
||||
manganis_cli_support::Config::default()
|
||||
@@ -49,7 +49,7 @@ impl WebAssetConfigDropGuard {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for WebAssetConfigDropGuard {
|
||||
impl Drop for AssetConfigDropGuard {
|
||||
fn drop(&mut self) {
|
||||
// Reset the config
|
||||
manganis_cli_support::Config::default().save();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
assets::{asset_manifest, create_assets_head, process_assets, WebAssetConfigDropGuard},
|
||||
assets::{asset_manifest, create_assets_head, process_assets, AssetConfigDropGuard},
|
||||
error::{Error, Result},
|
||||
tools::Tool,
|
||||
};
|
||||
@@ -87,7 +87,7 @@ pub fn build(
|
||||
let out_dir = config.out_dir();
|
||||
let asset_dir = config.asset_dir();
|
||||
|
||||
let _guard = WebAssetConfigDropGuard::new();
|
||||
let _guard = AssetConfigDropGuard::new();
|
||||
let _manganis_support = ManganisSupportGuard::default();
|
||||
|
||||
// start to build the assets
|
||||
@@ -339,6 +339,7 @@ pub fn build_desktop(
|
||||
let ignore_files = build_assets(config)?;
|
||||
let _guard = dioxus_cli_config::__private::save_config(config);
|
||||
let _manganis_support = ManganisSupportGuard::default();
|
||||
let _guard = AssetConfigDropGuard::new();
|
||||
|
||||
let mut cmd = subprocess::Exec::cmd("cargo")
|
||||
.set_rust_flags(rust_flags)
|
||||
@@ -535,7 +536,7 @@ fn prettier_build(cmd: subprocess::Exec) -> anyhow::Result<Vec<Diagnostic>> {
|
||||
}
|
||||
|
||||
pub fn gen_page(config: &CrateConfig, manifest: Option<&AssetManifest>, serve: bool) -> String {
|
||||
let _gaurd = WebAssetConfigDropGuard::new();
|
||||
let _guard = AssetConfigDropGuard::new();
|
||||
|
||||
let crate_root = crate_root().unwrap();
|
||||
let custom_html_file = crate_root.join("index.html");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::assets::AssetConfigDropGuard;
|
||||
#[cfg(feature = "plugin")]
|
||||
use crate::plugin::PluginManager;
|
||||
use crate::{assets::WebAssetConfigDropGuard, server::fullstack};
|
||||
use crate::server::fullstack;
|
||||
use dioxus_cli_config::Platform;
|
||||
|
||||
use super::*;
|
||||
@@ -69,7 +70,7 @@ impl Build {
|
||||
Platform::Fullstack => {
|
||||
// Fullstack mode must be built with web configs on the desktop
|
||||
// (server) binary as well as the web binary
|
||||
let _config = WebAssetConfigDropGuard::new();
|
||||
let _config = AssetConfigDropGuard::new();
|
||||
let client_rust_flags = fullstack::client_rust_flags(&self.build);
|
||||
let server_rust_flags = fullstack::server_rust_flags(&self.build);
|
||||
{
|
||||
|
||||
@@ -105,7 +105,16 @@ pub(super) fn index_request(
|
||||
|
||||
// Insert a custom head if provided
|
||||
// We look just for the closing head tag. If a user provided a custom index with weird syntax, this might fail
|
||||
if let Some(head) = custom_head {
|
||||
let head = match custom_head {
|
||||
Some(mut head) => {
|
||||
if let Some(assets_head) = assets_head() {
|
||||
head.push_str(&assets_head);
|
||||
}
|
||||
Some(head)
|
||||
}
|
||||
None => assets_head(),
|
||||
};
|
||||
if let Some(head) = head {
|
||||
index.insert_str(index.find("</head>").expect("Head element to exist"), &head);
|
||||
}
|
||||
|
||||
@@ -124,46 +133,40 @@ pub(super) fn index_request(
|
||||
.ok()
|
||||
}
|
||||
|
||||
// let assets_head = {
|
||||
// #[cfg(all(
|
||||
// debug_assertions,
|
||||
// any(
|
||||
// target_os = "windows",
|
||||
// target_os = "macos",
|
||||
// target_os = "linux",
|
||||
// target_os = "dragonfly",
|
||||
// target_os = "freebsd",
|
||||
// target_os = "netbsd",
|
||||
// target_os = "openbsd"
|
||||
// )
|
||||
// ))]
|
||||
// {
|
||||
// None
|
||||
// }
|
||||
// #[cfg(not(all(
|
||||
// debug_assertions,
|
||||
// any(
|
||||
// target_os = "windows",
|
||||
// target_os = "macos",
|
||||
// target_os = "linux",
|
||||
// target_os = "dragonfly",
|
||||
// target_os = "freebsd",
|
||||
// target_os = "netbsd",
|
||||
// target_os = "openbsd"
|
||||
// )
|
||||
// )))]
|
||||
// {
|
||||
// let head = crate::protocol::get_asset_root_or_default();
|
||||
// let head = head.join("dist/__assets_head.html");
|
||||
// match std::fs::read_to_string(&head) {
|
||||
// Ok(s) => Some(s),
|
||||
// Err(err) => {
|
||||
// tracing::error!("Failed to read {head:?}: {err}");
|
||||
// None
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
fn assets_head() -> Option<String> {
|
||||
#[cfg(any(
|
||||
target_os = "windows",
|
||||
target_os = "macos",
|
||||
target_os = "linux",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
{
|
||||
let head = crate::protocol::get_asset_root_or_default();
|
||||
let head = head.join("__assets_head.html");
|
||||
match std::fs::read_to_string(&head) {
|
||||
Ok(s) => Some(s),
|
||||
Err(err) => {
|
||||
tracing::error!("Failed to read {head:?}: {err}");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(not(any(
|
||||
target_os = "windows",
|
||||
target_os = "macos",
|
||||
target_os = "linux",
|
||||
target_os = "dragonfly",
|
||||
target_os = "freebsd",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
)))]
|
||||
{
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle a request from the webview
|
||||
///
|
||||
|
||||
Reference in new issue
Block a user