use brep_stream_client::{Input, Launcher, Mods, PointerButton};
use std::time::{Duration, Instant};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let program = std::env::args().nth(1).unwrap_or_else(|| "brep-app".into());
let started = Instant::now();
let session = Launcher::new(&program).size(1280.0, 800.0, 1.0).launch()?;
session.wait_still(Duration::from_millis(1500), Duration::from_secs(120))?;
let (width, height) = {
let frame = session.frame();
(frame.width, frame.height)
};
println!("ready in {:.1} s: {width} x {height} pixels", started.elapsed().as_secs_f32());
let (x, y) = (148.0, 19.0);
let clicked = Instant::now();
session.send(Input::PointerMove { x, y });
session.send(Input::Button { x, y, button: PointerButton::Primary, down: true, mods: Mods::NONE });
session.send(Input::Button { x, y, button: PointerButton::Primary, down: false, mods: Mods::NONE });
session.wait_frame(Duration::from_secs(10))?;
println!("the click came back as a new frame in {} ms", clicked.elapsed().as_millis());
session.wait_still(Duration::from_millis(500), Duration::from_secs(30))?;
{
let frame = session.frame();
image::save_buffer("brep-cad.png", &frame.rgba, frame.width, frame.height, image::ColorType::Rgba8)?;
println!("saved brep-cad.png after {} frames", frame.frames);
}
let status = session.shutdown(Duration::from_secs(15))?;
println!("the app exited: {status}");
Ok(())
}