mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 13:51:30 +11:00
Replace beforeunload
with pagehide
This commit is contained in:
parent
12fb37d827
commit
ab46aa5b79
|
@ -74,6 +74,7 @@ And please only add new entries to the top of this list, right below the `# Unre
|
|||
- On Web, use the correct canvas size when calculating the new size during scale factor change,
|
||||
instead of using the output bitmap size.
|
||||
- On Web, scale factor and dark mode detection are now more robust.
|
||||
- On Web, fix the bfcache by not using the `beforeunload` event.
|
||||
|
||||
# 0.28.6
|
||||
|
||||
|
|
|
@ -133,7 +133,6 @@ version = "0.3.22"
|
|||
features = [
|
||||
'console',
|
||||
'CssStyleDeclaration',
|
||||
'BeforeUnloadEvent',
|
||||
'Document',
|
||||
'DomRect',
|
||||
'Element',
|
||||
|
|
|
@ -15,7 +15,7 @@ use crate::dpi::{LogicalSize, Size};
|
|||
use crate::platform::web::WindowExtWebSys;
|
||||
use crate::window::Window;
|
||||
use wasm_bindgen::closure::Closure;
|
||||
use web_sys::{BeforeUnloadEvent, Element, HtmlCanvasElement};
|
||||
use web_sys::{Element, HtmlCanvasElement};
|
||||
|
||||
pub fn throw(msg: &str) {
|
||||
wasm_bindgen::throw_str(msg);
|
||||
|
@ -28,18 +28,13 @@ pub fn exit_fullscreen(window: &web_sys::Window) {
|
|||
}
|
||||
|
||||
pub struct UnloadEventHandle {
|
||||
_listener: event_handle::EventListenerHandle<dyn FnMut(BeforeUnloadEvent)>,
|
||||
_listener: event_handle::EventListenerHandle<dyn FnMut()>,
|
||||
}
|
||||
|
||||
pub fn on_unload(
|
||||
window: &web_sys::Window,
|
||||
mut handler: impl FnMut() + 'static,
|
||||
) -> UnloadEventHandle {
|
||||
let closure = Closure::wrap(
|
||||
Box::new(move |_: BeforeUnloadEvent| handler()) as Box<dyn FnMut(BeforeUnloadEvent)>
|
||||
);
|
||||
pub fn on_unload(window: &web_sys::Window, handler: impl FnMut() + 'static) -> UnloadEventHandle {
|
||||
let closure = Closure::new(handler);
|
||||
|
||||
let listener = event_handle::EventListenerHandle::new(window, "beforeunload", closure);
|
||||
let listener = event_handle::EventListenerHandle::new(window, "pagehide", closure);
|
||||
UnloadEventHandle {
|
||||
_listener: listener,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue