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
Explorer takeover hides the window at once while it is read (781)
gelenmedya1eae2ad615ff
diff --git a/crates/rf-win/src/explorer_catch.rs b/crates/rf-win/src/explorer_catch.rsindex 0c57ce80..dee56f66 100644--- a/crates/rf-win/src/explorer_catch.rs+++ b/crates/rf-win/src/explorer_catch.rs@@ -20,7 +20,7 @@ use windows::Win32::Foundation::{HWND, LPARAM, WPARAM};use windows::Win32::System::Com::{COINIT_APARTMENTTHREADED, CoInitializeEx};use windows::Win32::UI::Accessibility::{HWINEVENTHOOK, SetWinEventHook};use windows::Win32::UI::WindowsAndMessaging::{- DispatchMessageW, EVENT_OBJECT_SHOW, GA_ROOT, GetAncestor, GetMessageW, KillTimer, MSG, OBJID_WINDOW, PostMessageW, SetTimer,+ DispatchMessageW, EVENT_OBJECT_SHOW, GA_ROOT, GetAncestor, GetMessageW, KillTimer, MSG, OBJID_WINDOW, PostMessageW, SW_HIDE, SW_SHOW, SetTimer, ShowWindow,TranslateMessage, WINEVENT_OUTOFCONTEXT, WINEVENT_SKIPOWNPROCESS, WM_CLOSE, WM_TIMER,};@@ -89,9 +89,21 @@ unsafe extern "system" fn on_show(_: HWINEVENTHOOK, _: u32, hwnd: HWND, id_objecif now_ms() < QUIET_UNTIL.load(Ordering::Relaxed) {return;}+ // Hidden at once, while it is read (issue 781: it was seen for about 750 ms before it closed; hidden here, about 18 ms). The+ // shell's list of windows still reads a hidden window. One that turns out not to be ours is shown again (`look_at_waiting`).+ unsafe {+ let _ = ShowWindow(hwnd, SW_HIDE);+ }WAITING.with(|w| w.borrow_mut().push((key, Instant::now())));}+/// Shows again a window that was hidden while it was read and is not taken over.+fn give_back(key: isize) {+ unsafe {+ let _ = ShowWindow(HWND(key as *mut _), SW_SHOW);+ }+}+fn run() {let _ = unsafe { CoInitializeEx(None, COINIT_APARTMENTTHREADED) };let hook = unsafe {@@ -121,13 +133,16 @@ fn look_at_waiting() {let due: Vec<(isize, Instant)> = WAITING.with(|w| w.borrow().iter().copied().filter(|(_, t)| t.elapsed() >= SETTLE).collect());for (key, first) in due {if !ON.load(Ordering::Relaxed) {- WAITING.with(|w| w.borrow_mut().clear());+ // switched off meanwhile: every window still waiting is shown again+ for (k, _) in WAITING.with(|w| std::mem::take(&mut *w.borrow_mut())) {+ give_back(k);+ }return;}let hwnd = HWND(key as *mut _);- let place = crate::look::target::explorer_place(key);- let done = match place {- Some(c) => {+ use crate::look::target::ExplorerPlace;+ let done = match crate::look::target::explorer_place_now(key) {+ ExplorerPlace::Folder(c) => {let _ = unsafe { PostMessageW(Some(hwnd), WM_CLOSE, WPARAM(0), LPARAM(0)) };log::info!("explorer catch: took over {:?}", c.folder);if let Ok(h) = HANDLER.lock()@@ -137,8 +152,19 @@ fn look_at_waiting() {}true}- // not ready yet, or no file-system folder: tried again for a while, then left alone- None => first.elapsed() >= GIVE_UP,+ // no file-system folder (This PC, Control Panel): left alone, and seen again at once+ ExplorerPlace::Elsewhere => {+ give_back(key);+ true+ }+ // not ready yet: tried again for a while, then left alone (and shown)+ ExplorerPlace::NotReady => {+ let over = first.elapsed() >= GIVE_UP;+ if over {+ give_back(key);+ }+ over+ }};if done {WAITING.with(|w| w.borrow_mut().retain(|(k, _)| *k != key));diff --git a/crates/rf-win/src/look/target.rs b/crates/rf-win/src/look/target.rsindex e3950bcc..f13c3c8e 100644--- a/crates/rf-win/src/look/target.rs+++ b/crates/rf-win/src/look/target.rs@@ -120,20 +120,45 @@ pub fn selected_path(kind: TargetKind, hwnd: isize) -> Option<PathBuf> {/// The folder an Explorer window shows (a file-system folder only) and the item selected in it (issue 37). COM must be started/// on the calling thread.pub fn explorer_place(hwnd: isize) -> Option<crate::explorer_catch::Caught> {+ match explorer_place_now(hwnd) {+ ExplorerPlace::Folder(c) => Some(c),+ _ => None,+ }+}++/// What an Explorer window shows, as far as can be told now.+pub enum ExplorerPlace {+ /// Its view is not there yet (or the shell could not be asked): ask again a little later.+ NotReady,+ /// A place that is no file-system folder (This PC, Control Panel, a library's root): not for rustyfiles.+ Elsewhere,+ /// A file-system folder, and the item selected in it.+ Folder(crate::explorer_catch::Caught),+}++/// [`explorer_place`], telling "not ready" from "no folder of ours" (issue 781: a window hidden while it is read is shown again at+/// once when it is the latter, not after the whole wait).+pub fn explorer_place_now(hwnd: isize) -> ExplorerPlace {use windows::Win32::UI::Shell::{IFolderView, IPersistFolder2, SHGetNameFromIDList};- let windows: IShellWindows = unsafe { CoCreateInstance(&ShellWindows, None, CLSCTX_ALL) }.ok()?;- let browser = explorer_browser(&windows, HWND(hwnd as *mut _))?;- let view = unsafe { browser.QueryActiveShellView() }.ok()?;- let fv: IFolderView = view.cast().ok()?;- let pf: IPersistFolder2 = unsafe { fv.GetFolder() }.ok()?;- let pidl = unsafe { pf.GetCurFolder() }.ok()?;+ let read = || -> Option<(windows::Win32::UI::Shell::IShellView, *mut windows::Win32::UI::Shell::Common::ITEMIDLIST)> {+ let windows: IShellWindows = unsafe { CoCreateInstance(&ShellWindows, None, CLSCTX_ALL) }.ok()?;+ let browser = explorer_browser(&windows, HWND(hwnd as *mut _))?;+ let view = unsafe { browser.QueryActiveShellView() }.ok()?;+ let fv: IFolderView = view.cast().ok()?;+ let pf: IPersistFolder2 = unsafe { fv.GetFolder() }.ok()?;+ let pidl = unsafe { pf.GetCurFolder() }.ok()?;+ Some((view, pidl))+ };+ let Some((view, pidl)) = read() else { return ExplorerPlace::NotReady };let name = unsafe { SHGetNameFromIDList(pidl, SIGDN_FILESYSPATH) };unsafe { CoTaskMemFree(Some(pidl as *const _)) };- let name = name.ok()?;+ let Ok(name) = name else { return ExplorerPlace::Elsewhere };let folder = unsafe { name.to_string() }.ok();unsafe { CoTaskMemFree(Some(name.0 as *const _)) };- let folder = PathBuf::from(folder.filter(|s| !s.is_empty())?);- Some(crate::explorer_catch::Caught { folder, selected: first_selected(&view) })+ match folder.filter(|s| !s.is_empty()) {+ Some(f) => ExplorerPlace::Folder(crate::explorer_catch::Caught { folder: PathBuf::from(f), selected: first_selected(&view) }),+ None => ExplorerPlace::Elsewhere,+ }}/// The first selected item of a shell view, as a path.