-
Notifications
You must be signed in to change notification settings - Fork 2k
Web: Run App::logic even when hidden #5112
Copy link
Copy link
Open
Labels
bugSomething is brokenSomething is brokeneframeRelates to epi and eframeRelates to epi and eframewebRelated to running Egui on the webRelated to running Egui on the web
Milestone
Description
If the eframe web app is in hidden (e.g. is in a background tab in the browser), then any call to request_repaint will be ignored, and not result in a call to App::update.
That's because eframe checks if request_repaint has been called from requestAnimationFrame callback, which is not called if the application is hidden.
Solution
If the web page is hidden, then calling request_repaint should schedule a setTimer(…) callback to call App::update() (must done via a setTimer delay, or we could have App::update call request_repaint which in turn calls App::update.
We also need some guards to make sure that multiple calls to request_repaint in a row only results in one call to App::update, for instance via this pseudo-code:
// Won't be called if hidden
fn on_request_animation_frame() {
if state.needs_repaint {
app.update();
paint();
state.needs_repaint = false;
}
}
fn on_request_repaint() {
state.needs_repaint = true;
if document.is_hidden {
setTime(10ms, app_update_if_needed);
}
}
fn app_update_if_needed() {
if state.needs_repaint {
app.update();
state.needs_repaint = false;
}
}Related
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething is brokenSomething is brokeneframeRelates to epi and eframeRelates to epi and eframewebRelated to running Egui on the webRelated to running Egui on the web
Projects
Status
Next up