I’m dismissing an auxiliary overlay window in tauri using a tauri command that works as follows in main.rs
:
fn hide_search_bar(window: Window) -> Result<(), String> {
let overlay = window
.get_window("overlay")
.ok_or("Overlay window not found")?;
if overlay.is_visible().map_err(|e| e.to_string())? {
overlay.hide().map_err(|e| e.to_string())?;
}
Ok(())
}
I then invoke this function from the window’s front-end as follows in overlay.tsx
:
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === "Escape") {
logEvent("Escape key pressed")();
invoke("hide_search_bar")
.then(() => {
setOverlayVisible(false);
})
.catch(console.error);
}
};
While this works fine, the issue that I seem to be facing is that dismissing this window also causes the home or primary window to pop back into focus and onto the front of the desktop (assuming that it is not minimised, on another window or full screen).
After discussing this issue with one of the maintainers of the tauri library, this is apparently macOS behavior and isn’t a tauri specific issue. Regardless, I was wondering if there were any sort of workarounds to help address this issue.
I’ve tried momentarily hiding and bringing back the main window in the same command using thread::sleep
but that doesn’t seem to work as it seems to interfere with the registration of the escape keyboard event itself.
Testing is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.