Skip to content

Web: Run App::logic even when hidden #5112

@emilk

Description

@emilk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is brokeneframeRelates to epi and eframewebRelated to running Egui on the web

    Projects

    Status

    Next up

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions