Open david-mkl opened 7 months ago
Here's my workaround for now. You can use the window Focused event on the rust side, then emit that to the frontend. For example
// ....
.on_window_event(|window, event| {
match event {
tauri::WindowEvent::Focused(focus) => {
let app = window.app_handle();
app.emit("visibilitychanged", focus).unwrap()
},
_ => (),
}
})
// ....
Then on the frontend (for example with React)
useEffect(() => {
const listener = listen<boolean>("visibilitychanged", (event) => {
console.log(event)
})
return () => {
listener.then((f) => f())
}
}, [])
Describe the bug
The
visibilitychange
event does not fire when the application loses/gains focus (for example, the user switches to a different application). The event does fire when the window is minimized or maximized.(I am aware of https://github.com/tauri-apps/tauri/issues/6864, but it appears that issue was closed/merged so I am not sure if it fully addressed the issue).
Reproduction
Attach a listener to the
visibilitychange
event and log out the event.The event will not fire when the user switches to another application, but will be fired if the application is minimized or maximized.
Expected behavior
No response
Full
tauri info
output