0

I'm currently working on understanding building Rust apps using Bevy in WebAssembly. Under normal circumstances, the exit_all_on_closed variable in the following code allows for the app to close when the window the app is launched in is closed.

fn main() {
    App::new()
        .add_plugins(DefaultPlugins.set(WindowPlugin {
            window: WindowDescriptor {
                title: "Extreme".to_string(),
                ..default()
            },
            add_primary_window: true,
            exit_on_all_closed: true,
            close_when_requested: true,
        }))
        .run()
}

Since I'm launching the app in my browser using a wasm server, I'd assumed that closing either the tab the app launches in or the entire browser would trigger the app exit, but it does not. Is there functionality in Bevy to handle that? Is there another work around?

Attempted: set exit_all_on_closed to true, launch app in browser, and close browser. Expected app to exit.

Actual result: Browser window closed but app is still running.

cafce25
  • 15,907
  • 4
  • 25
  • 31
tangoti84
  • 45
  • 6
  • Can you specify what software you mean when you say “a wasm server”? That will help clarify what the situation is. (It's likely the answer is “the server knows absolutely nothing about what Bevy is doing”.) – Kevin Reid Feb 01 '23 at 18:40
  • Sure, it was probably misleading to say "wasm server". I think it would be better to say that I am using wasm to launch my application in the browser. – tangoti84 Feb 04 '23 at 21:30

1 Answers1

1

You can use the browsers beforeunload event via web-sys to track when users close a tab or a browser window containing your application.

Using this in combination with onload would also allow you to track all currently open instances.

frankenapps
  • 5,800
  • 6
  • 28
  • 69