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.

A packaged menu command's window comes to the front (1104)

gelenmedyafebf4ba919bb
diff --git a/crates/rf-win/src/pkgverbs.rs b/crates/rf-win/src/pkgverbs.rs
index af709fae..b7501431 100644
--- a/crates/rf-win/src/pkgverbs.rs
+++ b/crates/rf-win/src/pkgverbs.rs
@@ -525,6 +525,14 @@ pub fn invoke(id: usize) -> anyhow::Result<()> {
});
let cmd = cmd.ok_or_else(|| anyhow::anyhow!("the menu's commands are gone"))?;
let array = item_array(&items)?;
+ // The program the command starts may come to the front. WHY (issue 1104: "Edit in Notepad" from the menu opened Notepad
+ // behind rustyfiles every time, while "Open" and "Open with" brought it to the front). ShellExecute, which those two go
+ // through, hands our right to the foreground to what it starts; a packaged command is activated by Windows' broker
+ // instead, which gets no such right, so the window it opened stayed behind ours.
+ // SAFETY: a plain call; it only widens who may take the foreground until the next input.
+ unsafe {
+ let _ = windows::Win32::UI::WindowsAndMessaging::AllowSetForegroundWindow(windows::Win32::UI::WindowsAndMessaging::ASFW_ANY);
+ }
unsafe { cmd.Invoke(&array, None) }?;
Ok(())
}