diff --git a/egui_web/CHANGELOG.md b/egui_web/CHANGELOG.md index 000b3487..d64a79dc 100644 --- a/egui_web/CHANGELOG.md +++ b/egui_web/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to the `egui_web` integration will be noted in this file. * Made the WebGL painter opt-in ([#1020](https://github.com/emilk/egui/pull/1020)). * Fix glow failure Chrome ((#1092)[https://github.com/emilk/egui/pull/1092]). * Shift-scroll will now result in horizontal scrolling on all platforms ((#1136)[https://github.com/emilk/egui/pull/1136]). +* Update `epi::IntegrationInfo::web_location_hash` on `hashchange` event ([#1140](https://github.com/emilk/egui/pull/1140)). ## 0.16.0 - 2021-12-29 diff --git a/egui_web/src/backend.rs b/egui_web/src/backend.rs index eb473233..f6692e76 100644 --- a/egui_web/src/backend.rs +++ b/egui_web/src/backend.rs @@ -82,7 +82,7 @@ impl epi::backend::RepaintSignal for NeedRepaint { // ---------------------------------------------------------------------------- pub struct AppRunner { - frame: epi::Frame, + pub(crate) frame: epi::Frame, egui_ctx: egui::Context, painter: Box, pub(crate) input: WebInput, diff --git a/egui_web/src/lib.rs b/egui_web/src/lib.rs index dbdb87b4..3faff02e 100644 --- a/egui_web/src/lib.rs +++ b/egui_web/src/lib.rs @@ -668,6 +668,22 @@ fn install_document_events(runner_ref: &AppRunnerRef) -> Result<(), JsValue> { closure.forget(); } + { + // hashchange + let runner_ref = runner_ref.clone(); + let closure = Closure::wrap(Box::new(move || { + let runner_lock = runner_ref.0.lock(); + let mut frame_lock = runner_lock.frame.lock(); + + // `epi::Frame::info(&self)` clones `epi::IntegrationInfo`, but we need to modify the original here + if let Some(web_info) = &mut frame_lock.info.web_info { + web_info.web_location_hash = location_hash().unwrap_or_default(); + } + }) as Box); + window.add_event_listener_with_callback("hashchange", closure.as_ref().unchecked_ref())?; + closure.forget(); + } + Ok(()) }