Fix: race condition in asset resolution

This commit is contained in:
Jonathan Kelley committed 2024-11-01 15:34:48 -07:00
1 parent 24b6853c24
commit e19e8d48fe
3 files changed
+21 -11

No files matched your search

Generated
+3
View File
@@ -3371,6 +3371,9 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-core-types" name = "dioxus-core-types"
version = "0.6.0-alpha.3" version = "0.6.0-alpha.3"
dependencies = [
"once_cell",
]
[[package]] [[package]]
name = "dioxus-desktop" name = "dioxus-desktop"
+1
View File
@@ -11,3 +11,4 @@ keywords = ["dom", "ui", "gui", "react", ]
[dependencies] [dependencies]
once_cell.workspace = true
+17 -11
View File
@@ -1,16 +1,22 @@
static mut BUNDLED: bool = false; use once_cell::sync::Lazy;
static mut CHECKED_YET: bool = false;
pub fn is_bundled_app() -> bool { pub fn is_bundled_app() -> bool {
// unsafe to implement a dumb cell without pulling in deps / mutexes static BUNDLED: Lazy<bool> = Lazy::new(|| {
// we're okay with a race condition here since the bundled flag is always set to the same value // If the env var is set, we're bundled
unsafe { if std::env::var("DIOXUS_CLI_ENABLED").is_ok() {
if !CHECKED_YET { return true;
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());
} }
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
} }