mirror of
https://github.com/DioxusLabs/dioxus
synced 2025-02-16 21:58:25 +00:00
fix manganis support for dioxus desktop
This commit is contained in:
parent
ef101dd876
commit
3270f7341a
9 changed files with 63 additions and 58 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -5902,7 +5902,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "manganis"
|
name = "manganis"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/DioxusLabs/collect-assets?rev=e0093a4#e0093a47f0fa3bb50c49cd21aee5aa674faa24ad"
|
source = "git+https://github.com/DioxusLabs/collect-assets?rev=f982698#f982698027fc27d22acfb4121fba389ec125d538"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"manganis-macro",
|
"manganis-macro",
|
||||||
]
|
]
|
||||||
|
@ -5910,7 +5910,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "manganis-cli-support"
|
name = "manganis-cli-support"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/DioxusLabs/collect-assets?rev=e0093a4#e0093a47f0fa3bb50c49cd21aee5aa674faa24ad"
|
source = "git+https://github.com/DioxusLabs/collect-assets?rev=f982698#f982698027fc27d22acfb4121fba389ec125d538"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cargo-lock 9.0.0",
|
"cargo-lock 9.0.0",
|
||||||
|
@ -5936,7 +5936,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "manganis-common"
|
name = "manganis-common"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/DioxusLabs/collect-assets?rev=e0093a4#e0093a47f0fa3bb50c49cd21aee5aa674faa24ad"
|
source = "git+https://github.com/DioxusLabs/collect-assets?rev=f982698#f982698027fc27d22acfb4121fba389ec125d538"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"base64 0.21.7",
|
"base64 0.21.7",
|
||||||
|
@ -5951,7 +5951,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "manganis-macro"
|
name = "manganis-macro"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
source = "git+https://github.com/DioxusLabs/collect-assets?rev=e0093a4#e0093a47f0fa3bb50c49cd21aee5aa674faa24ad"
|
source = "git+https://github.com/DioxusLabs/collect-assets?rev=f982698#f982698027fc27d22acfb4121fba389ec125d538"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.21.7",
|
"base64 0.21.7",
|
||||||
"manganis-cli-support",
|
"manganis-cli-support",
|
||||||
|
|
|
@ -99,11 +99,11 @@ thiserror = "1.0.40"
|
||||||
prettyplease = { package = "prettier-please", version = "0.2", features = [
|
prettyplease = { package = "prettier-please", version = "0.2", features = [
|
||||||
"verbatim",
|
"verbatim",
|
||||||
] }
|
] }
|
||||||
manganis-cli-support = { git = "https://github.com/DioxusLabs/collect-assets", rev = "e0093a4", features = [
|
manganis-cli-support = { git = "https://github.com/DioxusLabs/collect-assets", rev = "f982698", features = [
|
||||||
"webp",
|
"webp",
|
||||||
"html",
|
"html",
|
||||||
] }
|
] }
|
||||||
manganis = { git = "https://github.com/DioxusLabs/collect-assets", rev = "e0093a4" }
|
manganis = { git = "https://github.com/DioxusLabs/collect-assets", rev = "f982698" }
|
||||||
|
|
||||||
# This is a "virtual package"
|
# This is a "virtual package"
|
||||||
# It is not meant to be published, but is used so "cargo run --example XYZ" works properly
|
# It is not meant to be published, but is used so "cargo run --example XYZ" works properly
|
||||||
|
|
|
@ -4,7 +4,8 @@ use dioxus::prelude::*;
|
||||||
static ASSET_PATH: &str = "examples/assets/logo.png";
|
static ASSET_PATH: &str = "examples/assets/logo.png";
|
||||||
|
|
||||||
#[cfg(feature = "collect-assets")]
|
#[cfg(feature = "collect-assets")]
|
||||||
static ASSET_PATH: &str = manganis::mg!(image("examples/assets/logo.png").format(ImageType::Avif));
|
static ASSET_PATH: &str =
|
||||||
|
manganis::mg!(image("examples/assets/logo.png").format(ImageType::Avif)).path();
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
launch(app);
|
launch(app);
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use dioxus::prelude::*;
|
use dioxus::prelude::*;
|
||||||
|
|
||||||
const _STYLE: &str = manganis::mg!(file("./public/tailwind.css"));
|
const _STYLE: &str = manganis::mg!(file("public/tailwind.css"));
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
launch(app);
|
launch(app);
|
||||||
|
|
|
@ -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
|
/// 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 {
|
pub fn new() -> Self {
|
||||||
// Set up the collect asset config
|
// Set up the collect asset config
|
||||||
manganis_cli_support::Config::default()
|
manganis_cli_support::Config::default()
|
||||||
|
@ -49,7 +49,7 @@ impl WebAssetConfigDropGuard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for WebAssetConfigDropGuard {
|
impl Drop for AssetConfigDropGuard {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// Reset the config
|
// Reset the config
|
||||||
manganis_cli_support::Config::default().save();
|
manganis_cli_support::Config::default().save();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
assets::{asset_manifest, create_assets_head, process_assets, WebAssetConfigDropGuard},
|
assets::{asset_manifest, create_assets_head, process_assets, AssetConfigDropGuard},
|
||||||
error::{Error, Result},
|
error::{Error, Result},
|
||||||
tools::Tool,
|
tools::Tool,
|
||||||
};
|
};
|
||||||
|
@ -87,7 +87,7 @@ pub fn build(
|
||||||
let out_dir = config.out_dir();
|
let out_dir = config.out_dir();
|
||||||
let asset_dir = config.asset_dir();
|
let asset_dir = config.asset_dir();
|
||||||
|
|
||||||
let _guard = WebAssetConfigDropGuard::new();
|
let _guard = AssetConfigDropGuard::new();
|
||||||
let _manganis_support = ManganisSupportGuard::default();
|
let _manganis_support = ManganisSupportGuard::default();
|
||||||
|
|
||||||
// start to build the assets
|
// start to build the assets
|
||||||
|
@ -339,6 +339,7 @@ pub fn build_desktop(
|
||||||
let ignore_files = build_assets(config)?;
|
let ignore_files = build_assets(config)?;
|
||||||
let _guard = dioxus_cli_config::__private::save_config(config);
|
let _guard = dioxus_cli_config::__private::save_config(config);
|
||||||
let _manganis_support = ManganisSupportGuard::default();
|
let _manganis_support = ManganisSupportGuard::default();
|
||||||
|
let _guard = AssetConfigDropGuard::new();
|
||||||
|
|
||||||
let mut cmd = subprocess::Exec::cmd("cargo")
|
let mut cmd = subprocess::Exec::cmd("cargo")
|
||||||
.set_rust_flags(rust_flags)
|
.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 {
|
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 crate_root = crate_root().unwrap();
|
||||||
let custom_html_file = crate_root.join("index.html");
|
let custom_html_file = crate_root.join("index.html");
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
use crate::assets::AssetConfigDropGuard;
|
||||||
#[cfg(feature = "plugin")]
|
#[cfg(feature = "plugin")]
|
||||||
use crate::plugin::PluginManager;
|
use crate::plugin::PluginManager;
|
||||||
use crate::{assets::WebAssetConfigDropGuard, server::fullstack};
|
use crate::server::fullstack;
|
||||||
use dioxus_cli_config::Platform;
|
use dioxus_cli_config::Platform;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -69,7 +70,7 @@ impl Build {
|
||||||
Platform::Fullstack => {
|
Platform::Fullstack => {
|
||||||
// Fullstack mode must be built with web configs on the desktop
|
// Fullstack mode must be built with web configs on the desktop
|
||||||
// (server) binary as well as the web binary
|
// (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 client_rust_flags = fullstack::client_rust_flags(&self.build);
|
||||||
let server_rust_flags = fullstack::server_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
|
// 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
|
// 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);
|
index.insert_str(index.find("</head>").expect("Head element to exist"), &head);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,46 +133,40 @@ pub(super) fn index_request(
|
||||||
.ok()
|
.ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
// let assets_head = {
|
fn assets_head() -> Option<String> {
|
||||||
// #[cfg(all(
|
#[cfg(any(
|
||||||
// debug_assertions,
|
target_os = "windows",
|
||||||
// any(
|
target_os = "macos",
|
||||||
// target_os = "windows",
|
target_os = "linux",
|
||||||
// target_os = "macos",
|
target_os = "dragonfly",
|
||||||
// target_os = "linux",
|
target_os = "freebsd",
|
||||||
// target_os = "dragonfly",
|
target_os = "netbsd",
|
||||||
// target_os = "freebsd",
|
target_os = "openbsd"
|
||||||
// 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) {
|
||||||
// None
|
Ok(s) => Some(s),
|
||||||
// }
|
Err(err) => {
|
||||||
// #[cfg(not(all(
|
tracing::error!("Failed to read {head:?}: {err}");
|
||||||
// debug_assertions,
|
None
|
||||||
// any(
|
}
|
||||||
// target_os = "windows",
|
}
|
||||||
// target_os = "macos",
|
}
|
||||||
// target_os = "linux",
|
#[cfg(not(any(
|
||||||
// target_os = "dragonfly",
|
target_os = "windows",
|
||||||
// target_os = "freebsd",
|
target_os = "macos",
|
||||||
// target_os = "netbsd",
|
target_os = "linux",
|
||||||
// target_os = "openbsd"
|
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) {
|
None
|
||||||
// Ok(s) => Some(s),
|
}
|
||||||
// Err(err) => {
|
}
|
||||||
// tracing::error!("Failed to read {head:?}: {err}");
|
|
||||||
// None
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
/// Handle a request from the webview
|
/// Handle a request from the webview
|
||||||
///
|
///
|
||||||
|
|
Loading…
Add table
Reference in a new issue