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.
Rust archive-managerdesktop-appdual-paneexplorer-alternativefile-browserfile-explorerfile-managerfluent-designgpu-acceleratedgpuimacosmicaproductivityquick-lookrustrust-guitabswindowswindows-11windows-explorer
Shell host tells the guard the desktop is ready (757)
gelenmedya194ccd3c8a32
diff --git a/crates/rf-app/src/dock/host.rs b/crates/rf-app/src/dock/host.rsindex d87537ff..5a108768 100644--- a/crates/rf-app/src/dock/host.rs+++ b/crates/rf-app/src/dock/host.rs@@ -2058,6 +2058,14 @@ pub fn run(messages: Option<UnboundedReceiver<String>>, cx: &mut App) {super::parts_status::start(cx);// the parts that depend on who owns the shell window (see shell::live)crate::shell::live::start(cx);+ // The guard that started this host as the Windows shell waits for word that the desktop is usable (issue 757: the word never+ // came, so every sign-in ended in the guard's fall-back to Explorer). Queued after the windows' setup job above, so it comes once+ // they exist. Nothing happens in a dock the file manager started (the guard's variable is not there).+ on_message_loop(cx, || match rf_win::shellhost::ready::signal_if_asked() {+ Ok(true) => log::info!("shell: the guard was told the desktop is ready"),+ Ok(false) => {}+ Err(e) => log::warn!("shell: the guard could not be told the desktop is ready: {e}"),+ });// the other monitors' docks (nothing at all with the switch off and no secondary dock: no list of monitors is even read)sync_docks(cx);diff --git a/crates/rf-win/src/shellhost/mod.rs b/crates/rf-win/src/shellhost/mod.rsindex b73e47c9..a706f6e1 100644--- a/crates/rf-win/src/shellhost/mod.rs+++ b/crates/rf-win/src/shellhost/mod.rs@@ -15,6 +15,7 @@ pub mod appcmd;pub mod minimized;pub mod mode;pub mod probe;+pub mod ready;pub mod shellhook;pub mod watch;pub mod workarea;diff --git a/crates/rf-win/src/shellhost/ready.rs b/crates/rf-win/src/shellhost/ready.rsnew file mode 100644index 00000000..2a863663--- /dev/null+++ b/crates/rf-win/src/shellhost/ready.rs@@ -0,0 +1,65 @@+//! The shell host tells the guard that started it that the desktop is usable.+//!+//! The guard (`rustyfiles-shellguard`, rustyfiles as the Windows shell) makes a named event, starts the host with its name in+//! `RUSTYFILES_SHELL_READY_EVENT`, and waits for it: a host that has not signalled within its deadline counts as crashed, and a few+//! of those in a row give the session back to Explorer.+//!+//! WHY THIS IS HERE (issue 757, 1.0.7): the host half of that handshake was missing. Nothing in the app read the variable or set the+//! event, so every sign-in with the switch on went through six "crashes" in three minutes and ended in the guard's fall-back, with+//! the switch off again. Only a host the guard started has the variable; a dock started by the file manager has none.++use std::ffi::OsStr;++use windows::Win32::Foundation::CloseHandle;+use windows::Win32::System::Threading::{EVENT_MODIFY_STATE, OpenEventW, SetEvent};+use windows::core::PCWSTR;++/// The variable the guard puts the event's name in.+pub const VAR: &str = "RUSTYFILES_SHELL_READY_EVENT";++/// Signals the guard's event when this process was started by the guard. `Ok(false)`: not started so, nothing to do.+pub fn signal_if_asked() -> Result<bool, String> {+ match std::env::var_os(VAR) {+ Some(name) if !name.is_empty() => signal(&name).map(|_| true),+ _ => Ok(false),+ }+}++/// Sets the named event `name` (opened for that alone, closed again).+pub fn signal(name: &OsStr) -> Result<(), String> {+ use std::os::windows::ffi::OsStrExt;+ let w: Vec<u16> = name.encode_wide().chain(std::iter::once(0)).collect();+ unsafe {+ let h = OpenEventW(EVENT_MODIFY_STATE, false, PCWSTR(w.as_ptr())).map_err(|e| format!("open {}: {e}", name.to_string_lossy()))?;+ let r = SetEvent(h).map_err(|e| format!("set {}: {e}", name.to_string_lossy()));+ let _ = CloseHandle(h);+ r+ }+}++#[cfg(test)]+mod tests {+ use windows::Win32::Foundation::{CloseHandle, WAIT_OBJECT_0, WAIT_TIMEOUT};+ use windows::Win32::System::Threading::{CreateEventW, WaitForSingleObject};+ use windows::core::PCWSTR;++ /// As the guard makes it (manual reset, not signalled): after `signal` it is signalled.+ #[test]+ fn the_guards_event_is_signalled() {+ let name = format!("Local\\rustyfiles-shell-ready-test-{}", std::process::id());+ let w: Vec<u16> = name.encode_utf16().chain(std::iter::once(0)).collect();+ unsafe {+ let ev = CreateEventW(None, true, false, PCWSTR(w.as_ptr())).unwrap();+ assert_eq!(WaitForSingleObject(ev, 0), WAIT_TIMEOUT, "not signalled yet");+ super::signal(std::ffi::OsStr::new(&name)).unwrap();+ assert_eq!(WaitForSingleObject(ev, 0), WAIT_OBJECT_0, "signalled");+ let _ = CloseHandle(ev);+ }+ }++ /// An event that does not exist is an error, not a panic.+ #[test]+ fn a_missing_event_is_an_error() {+ assert!(super::signal(std::ffi::OsStr::new("Local\\rustyfiles-no-such-event-for-a-test")).is_err());+ }+}