|
| 1 | +//! Test that the Rerun Viewer UI wakes up as new messages arrive, |
| 2 | +//! even if the viewer is hidden. |
| 3 | +//! |
| 4 | +//! ## Test setup - build the viewer |
| 5 | +//! * `pixi run rerun-build` |
| 6 | +//! * `pixi run rerun-build-web` |
| 7 | +//! |
| 8 | +//! ## Test matrix |
| 9 | +//! * Run `cargo r -p test_ui_wakeup` and test: |
| 10 | +//! * That the viewer wakes up in the background when it's alt-tabbed |
| 11 | +//! * That the viewer wakes up when minimized (it should log "Received a message from…") |
| 12 | +//! * Run `cargo r -p test_ui_wakeup -- --serve` and test: |
| 13 | +//! * The viewer wakes up when browser is alt-tabbed away |
| 14 | +//! * Switch to a different browser tab, send a few messages, switch back. The messages should be there |
| 15 | +//! (this is not a conclusive test, as the messages might have been received on tab select) |
| 16 | +
|
| 17 | +use std::io::Read as _; |
| 18 | + |
| 19 | +#[derive(Debug, clap::Parser)] |
| 20 | +#[clap(author, version, about)] |
| 21 | +struct Args { |
| 22 | + #[command(flatten)] |
| 23 | + rerun: rerun::clap::RerunArgs, |
| 24 | +} |
| 25 | + |
| 26 | +fn main() -> anyhow::Result<()> { |
| 27 | + re_log::setup_logging(); |
| 28 | + |
| 29 | + use clap::Parser as _; |
| 30 | + let args = Args::parse(); |
| 31 | + |
| 32 | + // This is so that re_viewer logs incoming messages: |
| 33 | + let rust_log = "info,re_viewer=trace"; |
| 34 | + eprintln!("Setting RUST_LOG={rust_log}"); |
| 35 | + std::env::set_var("RUST_LOG", rust_log); |
| 36 | + |
| 37 | + println!("Starting Viewer…"); |
| 38 | + let (rec, _serve_guard) = args.rerun.init("rerun_example_ui_wakeup")?; |
| 39 | + |
| 40 | + // Wait out some log spam from the viewer starting: |
| 41 | + std::thread::sleep(std::time::Duration::from_secs(1)); |
| 42 | + |
| 43 | + println!("Now put the viewer in the background (alt-tab, minimize, put in background tab, etc"); |
| 44 | + |
| 45 | + for i in 0.. { |
| 46 | + println!("Sending message number {i}…"); |
| 47 | + rec.log( |
| 48 | + "Text", |
| 49 | + &rerun::TextDocument::new(format!("This is message number {i}")), |
| 50 | + )?; |
| 51 | + println!("Press ENTER to send more data to the viewer"); |
| 52 | + |
| 53 | + wait_from_enter(); |
| 54 | + } |
| 55 | + |
| 56 | + Ok(()) |
| 57 | +} |
| 58 | + |
| 59 | +fn wait_from_enter() { |
| 60 | + let _ = std::io::stdin() |
| 61 | + .read(&mut [0u8]) |
| 62 | + .expect("Failed to read from stdin"); |
| 63 | +} |
0 commit comments