Skip to main content

set_context

Function set_context 

Source
pub fn set_context(ctx: &Context)
Expand description

Sets the app’s context on this thread, so that queries and commands wake it up when they finish, including the ones in progress.

A RouterApp sets it at the start of each frame. Call it yourself when queries or commands run before the router’s first frame, or in an app without a router, e.g. in the app’s constructor, with eframe’s CreationContext::egui_ctx:

use egui_kit::remote::{self, Command};

struct Shell {
    check_session: Command<bool, String>,
}

impl Shell {
    fn new(ctx: &egui::Context) -> Self {
        // Without it, a reactive app would show its spinner until the mouse moves.
        remote::set_context(ctx);
        let check_session = remote::command();
        check_session.run(async { Ok(true) });
        Self { check_session }
    }
}