Send a LoopDestroyed event when the browser is closed (#1155)
* Add the plumbing for handling browser closes * Implement the business logic for handling closes
This commit is contained in:
parent
7ee9d5639b
commit
e87bc3db20
4 changed files with 31 additions and 1 deletions
|
|
@ -9,12 +9,19 @@ use crate::platform::web::WindowExtStdweb;
|
|||
use crate::window::Window;
|
||||
|
||||
use stdweb::js;
|
||||
use stdweb::web::event::BeforeUnloadEvent;
|
||||
use stdweb::web::html_element::CanvasElement;
|
||||
use stdweb::web::window;
|
||||
use stdweb::web::IEventTarget;
|
||||
|
||||
pub fn throw(msg: &str) {
|
||||
js! { throw @{msg} }
|
||||
}
|
||||
|
||||
pub fn on_unload(mut handler: impl FnMut() + 'static) {
|
||||
window().add_event_listener(move |_: BeforeUnloadEvent| handler());
|
||||
}
|
||||
|
||||
impl WindowExtStdweb for Window {
|
||||
fn canvas(&self) -> CanvasElement {
|
||||
self.window.canvas().raw().clone()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue