Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant't listen event 'tauri://close-requested' or 'tauri://destroyed' #2996

Closed
lity opened this issue Dec 1, 2021 · 6 comments
Closed

Cant't listen event 'tauri://close-requested' or 'tauri://destroyed' #2996

lity opened this issue Dec 1, 2021 · 6 comments
Assignees

Comments

@lity
Copy link

lity commented Dec 1, 2021

1

2

I follow the guide of window.WebviewWindow ( https://tauri.studio/en/docs/api/js/classes/window.WebviewWindow ), everything is OK.
But if I change the event from 'tauri://created' to 'tauri://close-requested' (or tauri://destroyed), the event handler won't be invoked.

What I want to do is to save working data and close other hidden windows after user click 'close' button of the main window.
I have tried listen 'tauri://close-requested' , ' tauri://destroyed' and set window.onbeforeunload, none of them works.

Please help.

@lity lity added the type: bug label Dec 1, 2021
@lity
Copy link
Author

lity commented Dec 1, 2021

1

Listening events in setup method in Rust layer is OK, but I just wanna make it simple in Javascript layer.

@lity
Copy link
Author

lity commented Dec 10, 2021

looking forward to next version

@barbalex
Copy link

barbalex commented Jan 14, 2022

me too (somehow these words sound inapropriate lately...)

@ghost
Copy link

ghost commented Nov 5, 2022

For those who still struggle

import { window } from "@tauri-apps/api"
import { TauriEvent } from "@tauri-apps/api/event"

window.getCurrent().listen(TauriEvent.WINDOW_CLOSE_REQUESTED, () => {
  alert("Closing window and maybe saving some data :)")
})

@gugiserman
Copy link

For those who still struggle

import { window } from "@tauri-apps/api"

window.getCurrent().listen(TauriEvent.WINDOW_CLOSE_REQUESTED, () => {
  alert("Closing window and maybe saving some data :)")
})

Unfortunately this is also not working for me. I have tried pretty much everything I could find in any of the docs and examples 😢

I don't get any WINDOW_CLOSE_REQUESTED, WINDOW_DESTROYED or beforeunload when I run my app in fullscreen, for some reason.

If I make it windowed, it will trigger both from Cmd+W or by clicking at the red X button just fine.

I'm testing it fullscreen on macOS Big Sur. Any ideas?

@ghost
Copy link

ghost commented Nov 12, 2022

For those who still struggle

import { window } from "@tauri-apps/api"

window.getCurrent().listen(TauriEvent.WINDOW_CLOSE_REQUESTED, () => {
  alert("Closing window and maybe saving some data :)")
})

Unfortunately this is also not working for me. I have tried pretty much everything I could find in any of the docs and examples cry

I don't get any WINDOW_CLOSE_REQUESTED, WINDOW_DESTROYED or beforeunload when I run my app in fullscreen, for some reason.

If I make it windowed, it will trigger both from Cmd+W or by clicking at the red X button just fine.

I'm testing it fullscreen on macOS Big Sur. Any ideas?

I'm on linux. Most likely you are listening to wrong window

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants