mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +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,
|
- On Web, use the correct canvas size when calculating the new size during scale factor change,
|
||||||
instead of using the output bitmap size.
|
instead of using the output bitmap size.
|
||||||
- On Web, scale factor and dark mode detection are now more robust.
|
- 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
|
# 0.28.6
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,6 @@ version = "0.3.22"
|
||||||
features = [
|
features = [
|
||||||
'console',
|
'console',
|
||||||
'CssStyleDeclaration',
|
'CssStyleDeclaration',
|
||||||
'BeforeUnloadEvent',
|
|
||||||
'Document',
|
'Document',
|
||||||
'DomRect',
|
'DomRect',
|
||||||
'Element',
|
'Element',
|
||||||
|
|
|
@ -15,7 +15,7 @@ use crate::dpi::{LogicalSize, Size};
|
||||||
use crate::platform::web::WindowExtWebSys;
|
use crate::platform::web::WindowExtWebSys;
|
||||||
use crate::window::Window;
|
use crate::window::Window;
|
||||||
use wasm_bindgen::closure::Closure;
|
use wasm_bindgen::closure::Closure;
|
||||||
use web_sys::{BeforeUnloadEvent, Element, HtmlCanvasElement};
|
use web_sys::{Element, HtmlCanvasElement};
|
||||||
|
|
||||||
pub fn throw(msg: &str) {
|
pub fn throw(msg: &str) {
|
||||||
wasm_bindgen::throw_str(msg);
|
wasm_bindgen::throw_str(msg);
|
||||||
|
@ -28,18 +28,13 @@ pub fn exit_fullscreen(window: &web_sys::Window) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct UnloadEventHandle {
|
pub struct UnloadEventHandle {
|
||||||
_listener: event_handle::EventListenerHandle<dyn FnMut(BeforeUnloadEvent)>,
|
_listener: event_handle::EventListenerHandle<dyn FnMut()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_unload(
|
pub fn on_unload(window: &web_sys::Window, handler: impl FnMut() + 'static) -> UnloadEventHandle {
|
||||||
window: &web_sys::Window,
|
let closure = Closure::new(handler);
|
||||||
mut handler: impl FnMut() + 'static,
|
|
||||||
) -> UnloadEventHandle {
|
|
||||||
let closure = Closure::wrap(
|
|
||||||
Box::new(move |_: BeforeUnloadEvent| handler()) as Box<dyn FnMut(BeforeUnloadEvent)>
|
|
||||||
);
|
|
||||||
|
|
||||||
let listener = event_handle::EventListenerHandle::new(window, "beforeunload", closure);
|
let listener = event_handle::EventListenerHandle::new(window, "pagehide", closure);
|
||||||
UnloadEventHandle {
|
UnloadEventHandle {
|
||||||
_listener: listener,
|
_listener: listener,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue