Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

Add RUSTYFILES_WINDOWS_DIALOG env bypass for native file dialogs

jokwa135106f54cd1e23
diff --git a/crates/rf-dialog/src/lib.rs b/crates/rf-dialog/src/lib.rs
index 66fe29e6..2bcc1901 100644
--- a/crates/rf-dialog/src/lib.rs
+++ b/crates/rf-dialog/src/lib.rs
@@ -1145,7 +1145,14 @@ mod com {
let listed = || {
crate::proto::windows_apps_path().and_then(|p| std::fs::read_to_string(p).ok()).is_some_and(|t| crate::proto::windows_app_listed(&t, &exe))
};
- if let Some(app) = UNTOUCHED.iter().copied().find(|a| exe.eq_ignore_ascii_case(a)).or_else(|| listed().then_some("listed by the user")) {
+ let env_bypass = || crate::env_bypass_enabled(std::env::var("RUSTYFILES_WINDOWS_DIALOG").ok().as_deref());
+ if let Some(app) = UNTOUCHED
+ .iter()
+ .copied()
+ .find(|a| exe.eq_ignore_ascii_case(a))
+ .or_else(|| env_bypass().then_some("RUSTYFILES_WINDOWS_DIALOG"))
+ .or_else(|| listed().then_some("listed by the user"))
+ {
crate::log(&format!("create: {app}, Windows' dialog"));
let real = real_dialog(if self.save { &FileSaveDialog } else { &FileOpenDialog })?;
return unsafe { real.query(iid, object).ok() };
@@ -1193,3 +1200,25 @@ mod com {
#[allow(dead_code)]
const _: (HRESULT, HRESULT) = (S_OK, E_NOINTERFACE);
}
+
+/// Whether `RUSTYFILES_WINDOWS_DIALOG` enables native Windows dialogs for this process and its children.
+pub(crate) fn env_bypass_enabled(val: Option<&str>) -> bool {
+ val.map(str::trim).is_some_and(|v| v.eq_ignore_ascii_case("1") || v.eq_ignore_ascii_case("true") || v.eq_ignore_ascii_case("yes") || v.eq_ignore_ascii_case("on"))
+}
+
+#[cfg(test)]
+mod tests {
+ use super::env_bypass_enabled;
+
+ #[test]
+ fn env_bypass_parses_truthy_values_only() {
+ assert!(env_bypass_enabled(Some("1")));
+ assert!(env_bypass_enabled(Some(" true ")));
+ assert!(env_bypass_enabled(Some("YES")));
+ assert!(env_bypass_enabled(Some("On")));
+ assert!(!env_bypass_enabled(None));
+ assert!(!env_bypass_enabled(Some("")));
+ assert!(!env_bypass_enabled(Some("0")));
+ assert!(!env_bypass_enabled(Some("false")));
+ }
+}