Skip to main content

Launcher

Struct Launcher 

Source
pub struct Launcher { /* private fields */ }
Expand description

Starts brep-app --stream as a child process and connects to it.

Implementations§

Source§

impl Launcher

Source

pub fn new(program: impl AsRef<OsStr>) -> Launcher

Run program ("brep-app" on the PATH, or a path to it).

Examples found in repository?
examples/snapshot.rs (line 12)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    let program = std::env::args().nth(1).unwrap_or_else(|| "brep-app".into());
10    let started = Instant::now();
11    // 1280 x 800 logical pixels at density 1. The app ends with the session.
12    let session = Launcher::new(&program).size(1280.0, 800.0, 1.0).launch()?;
13    session.wait_still(Duration::from_millis(1500), Duration::from_secs(120))?;
14    let (width, height) = {
15        let frame = session.frame();
16        (frame.width, frame.height)
17    };
18    println!("ready in {:.1} s: {width} x {height} pixels", started.elapsed().as_secs_f32());
19
20    // The File menu sits at (148, 19) in the default layout.
21    let (x, y) = (148.0, 19.0);
22    let clicked = Instant::now();
23    session.send(Input::PointerMove { x, y });
24    session.send(Input::Button { x, y, button: PointerButton::Primary, down: true, mods: Mods::NONE });
25    session.send(Input::Button { x, y, button: PointerButton::Primary, down: false, mods: Mods::NONE });
26    session.wait_frame(Duration::from_secs(10))?;
27    println!("the click came back as a new frame in {} ms", clicked.elapsed().as_millis());
28    session.wait_still(Duration::from_millis(500), Duration::from_secs(30))?;
29
30    {
31        let frame = session.frame();
32        image::save_buffer("brep-cad.png", &frame.rgba, frame.width, frame.height, image::ColorType::Rgba8)?;
33        println!("saved brep-cad.png after {} frames", frame.frames);
34    }
35    let status = session.shutdown(Duration::from_secs(15))?;
36    println!("the app exited: {status}");
37    Ok(())
38}
Source

pub fn from_command(command: Command) -> Launcher

Run this command, with its own arguments (a document to open, --mcp for an AI agent beside you), environment and working directory. The launcher adds the --stream switches and takes its stdin and stdout.

Source

pub fn size(self, width: f32, height: f32, density: f32) -> Launcher

The session’s size in logical pixels and its density.

Examples found in repository?
examples/snapshot.rs (line 12)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    let program = std::env::args().nth(1).unwrap_or_else(|| "brep-app".into());
10    let started = Instant::now();
11    // 1280 x 800 logical pixels at density 1. The app ends with the session.
12    let session = Launcher::new(&program).size(1280.0, 800.0, 1.0).launch()?;
13    session.wait_still(Duration::from_millis(1500), Duration::from_secs(120))?;
14    let (width, height) = {
15        let frame = session.frame();
16        (frame.width, frame.height)
17    };
18    println!("ready in {:.1} s: {width} x {height} pixels", started.elapsed().as_secs_f32());
19
20    // The File menu sits at (148, 19) in the default layout.
21    let (x, y) = (148.0, 19.0);
22    let clicked = Instant::now();
23    session.send(Input::PointerMove { x, y });
24    session.send(Input::Button { x, y, button: PointerButton::Primary, down: true, mods: Mods::NONE });
25    session.send(Input::Button { x, y, button: PointerButton::Primary, down: false, mods: Mods::NONE });
26    session.wait_frame(Duration::from_secs(10))?;
27    println!("the click came back as a new frame in {} ms", clicked.elapsed().as_millis());
28    session.wait_still(Duration::from_millis(500), Duration::from_secs(30))?;
29
30    {
31        let frame = session.frame();
32        image::save_buffer("brep-cad.png", &frame.rgba, frame.width, frame.height, image::ColorType::Rgba8)?;
33        println!("saved brep-cad.png after {} frames", frame.frames);
34    }
35    let status = session.shutdown(Duration::from_secs(15))?;
36    println!("the app exited: {status}");
37    Ok(())
38}
Source

pub fn ready_timeout(self, timeout: Duration) -> Launcher

How long the app may take to start (default two minutes).

Source

pub fn launch(self) -> Result<Session, Error>

Start the app and connect as the controlling client.

Examples found in repository?
examples/snapshot.rs (line 12)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    let program = std::env::args().nth(1).unwrap_or_else(|| "brep-app".into());
10    let started = Instant::now();
11    // 1280 x 800 logical pixels at density 1. The app ends with the session.
12    let session = Launcher::new(&program).size(1280.0, 800.0, 1.0).launch()?;
13    session.wait_still(Duration::from_millis(1500), Duration::from_secs(120))?;
14    let (width, height) = {
15        let frame = session.frame();
16        (frame.width, frame.height)
17    };
18    println!("ready in {:.1} s: {width} x {height} pixels", started.elapsed().as_secs_f32());
19
20    // The File menu sits at (148, 19) in the default layout.
21    let (x, y) = (148.0, 19.0);
22    let clicked = Instant::now();
23    session.send(Input::PointerMove { x, y });
24    session.send(Input::Button { x, y, button: PointerButton::Primary, down: true, mods: Mods::NONE });
25    session.send(Input::Button { x, y, button: PointerButton::Primary, down: false, mods: Mods::NONE });
26    session.wait_frame(Duration::from_secs(10))?;
27    println!("the click came back as a new frame in {} ms", clicked.elapsed().as_millis());
28    session.wait_still(Duration::from_millis(500), Duration::from_secs(30))?;
29
30    {
31        let frame = session.frame();
32        image::save_buffer("brep-cad.png", &frame.rgba, frame.width, frame.height, image::ColorType::Rgba8)?;
33        println!("saved brep-cad.png after {} frames", frame.frames);
34    }
35    let status = session.shutdown(Duration::from_secs(15))?;
36    println!("the app exited: {status}");
37    Ok(())
38}

Auto Trait Implementations§

§

impl !RefUnwindSafe for Launcher

§

impl !UnwindSafe for Launcher

§

impl Forget for Launcher

§

impl Freeze for Launcher
where *const [u8] is !null: Freeze, PhantomData<[u8]>: Freeze, *const u8 is !null: Freeze, PhantomData<*const i8>: Freeze, *const LeafNode<OsString, Option<OsString>> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(OsString, Option<OsString>)>>: Freeze, PhantomData<Box<dyn FnMut() -> Result<(), Error> + Sync + Send>>: Freeze, *const [u32] is !null: Freeze, PhantomData<[u32]>: Freeze, I32NotAllOnes: Freeze, PhantomData<&'static OwnedFd>: Freeze,

§

impl Move for Launcher

§

impl Send for Launcher
where BoxRaw<[u8]>: Send, CStringArray: Send, NodeRef<Owned, OsString, Option<OsString>, LeafOrInternal>: Send, BoxRaw<(OsString, Option<OsString>)>: Send, RawVecInner: Send, BoxRaw<dyn FnMut() -> Result<(), Error> + Sync + Send>: Send, BoxRaw<[u32]>: Send, I32NotAllOnes: Send, &'static OwnedFd: Send,

§

impl Sync for Launcher
where BoxRaw<[u8]>: Sync, CStringArray: Sync, NodeRef<Owned, OsString, Option<OsString>, LeafOrInternal>: Sync, BoxRaw<(OsString, Option<OsString>)>: Sync, RawVecInner: Sync, BoxRaw<dyn FnMut() -> Result<(), Error> + Sync + Send>: Sync, BoxRaw<[u32]>: Sync, I32NotAllOnes: Sync,

§

impl Unpin for Launcher
where Box<[u8]>: Unpin, *const u8 is !null: Unpin, *const i8: Unpin, *const LeafNode<OsString, Option<OsString>> is !null: Unpin, Box<(OsString, Option<OsString>)>: Unpin, Box<dyn FnMut() -> Result<(), Error> + Sync + Send>: Unpin, Box<[u32]>: Unpin, I32NotAllOnes: Unpin, &'static OwnedFd: Unpin,

§

impl UnsafeUnpin for Launcher

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V