diff --git a/Cargo.lock b/Cargo.lock index 7de909999..e09e46e35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3371,6 +3371,9 @@ dependencies = [ [[package]] name = "dioxus-core-types" version = "0.6.0-alpha.3" +dependencies = [ + "once_cell", +] [[package]] name = "dioxus-desktop" diff --git a/packages/core-types/Cargo.toml b/packages/core-types/Cargo.toml index a0d61ff56..a6a67bb68 100644 --- a/packages/core-types/Cargo.toml +++ b/packages/core-types/Cargo.toml @@ -11,3 +11,4 @@ keywords = ["dom", "ui", "gui", "react", ] [dependencies] +once_cell.workspace = true diff --git a/packages/core-types/src/bundled.rs b/packages/core-types/src/bundled.rs index e7967d9ad..5fd1319ee 100644 --- a/packages/core-types/src/bundled.rs +++ b/packages/core-types/src/bundled.rs @@ -1,16 +1,22 @@ -static mut BUNDLED: bool = false; -static mut CHECKED_YET: bool = false; +use once_cell::sync::Lazy; pub fn is_bundled_app() -> bool { - // unsafe to implement a dumb cell without pulling in deps / mutexes - // we're okay with a race condition here since the bundled flag is always set to the same value - unsafe { - if !CHECKED_YET { - CHECKED_YET = true; - BUNDLED = std::env::var("DIOXUS_CLI_ENABLED").is_ok() - || !matches!(std::env::var("CARGO_MANIFEST_DIR"), Ok(path) if !path.is_empty()); + static BUNDLED: Lazy = Lazy::new(|| { + // If the env var is set, we're bundled + if std::env::var("DIOXUS_CLI_ENABLED").is_ok() { + return true; } - BUNDLED - } + // If the cargo manifest dir is set, we're not bundled. + // Generally this is only set with `cargo run` + if let Ok(path) = std::env::var("CARGO_MANIFEST_DIR") { + if !path.is_empty() { + return false; + } + } + + true + }); + + *BUNDLED }