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
If the eframe web app is in hidden (e.g. is in a background tab in the browser), then any call to
request_repaintwill be ignored, and not result in a call toApp::update.That's because eframe checks if
request_repainthas been called fromrequestAnimationFramecallback, which is not called if the application is hidden.Solution
If the web page is hidden, then calling
request_repaintshould schedule asetTimer(…)callback to callApp::update()(must done via a setTimer delay, or we could haveApp::updatecallrequest_repaintwhich in turn callsApp::update.We also need some guards to make sure that multiple calls to
request_repaintin a row only results in one call toApp::update, for instance via this pseudo-code:Related
App::logic#5113