Skip to main content

ContextWatchdog

Struct ContextWatchdog 

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

Watches for context changes by diffing consecutive snapshots.

Implementations§

Source§

impl ContextWatchdog

Source

pub fn new() -> Self

Examples found in repository?
examples/dump_context.rs (line 49)
10fn main() {
11    let mut merger = ContextMerger::new().with_defaults("Example App", "Main");
12    merger.push(ContextContribution::new(
13        "test_source",
14        vec![ContextElement {
15            id: "button:submit".into(),
16            label: Some("Submit".into()),
17            description: None,
18            element_type: "button".into(),
19            value: None,
20            bounds: Some(Bounds {
21                x: 100,
22                y: 200,
23                width: 120,
24                height: 32,
25            }),
26            state: ElementState {
27                focused: true,
28                ..Default::default()
29            },
30            parent_id: None,
31            actions: Vec::new(),
32            confidence: 0.0,
33            source: ContextSource::NativeApi,
34            content_role: ContentRole::Interactive,
35            properties: Default::default(),
36        }],
37    ));
38
39    let ctx = merger.build();
40    println!("{}", serde_json::to_string_pretty(&ctx).unwrap());
41
42    let reference = ctx.elements[0].to_reference(1920, 1080);
43    let resolved = cel_context::resolve_reference(&ctx, &reference);
44    println!(
45        "resolved reference: {:?}",
46        resolved.map(|el| el.id.as_str())
47    );
48
49    let mut watchdog = ContextWatchdog::new();
50    assert!(watchdog.tick(&ctx, true).is_empty());
51
52    let mut changed = ctx.clone();
53    changed.elements[0].state.focused = false;
54    let events = watchdog.tick(&changed, true);
55    println!("watchdog events: {events:?}");
56}
Source

pub fn tick( &mut self, context: &ScreenContext, network_idle: bool, ) -> Vec<CelEvent>

Compare the current context against the previous snapshot and emit events.

context: The current screen context. network_idle: Whether the network monitor reports idle state.

Returns a list of events that occurred since the last tick.

Examples found in repository?
examples/dump_context.rs (line 50)
10fn main() {
11    let mut merger = ContextMerger::new().with_defaults("Example App", "Main");
12    merger.push(ContextContribution::new(
13        "test_source",
14        vec![ContextElement {
15            id: "button:submit".into(),
16            label: Some("Submit".into()),
17            description: None,
18            element_type: "button".into(),
19            value: None,
20            bounds: Some(Bounds {
21                x: 100,
22                y: 200,
23                width: 120,
24                height: 32,
25            }),
26            state: ElementState {
27                focused: true,
28                ..Default::default()
29            },
30            parent_id: None,
31            actions: Vec::new(),
32            confidence: 0.0,
33            source: ContextSource::NativeApi,
34            content_role: ContentRole::Interactive,
35            properties: Default::default(),
36        }],
37    ));
38
39    let ctx = merger.build();
40    println!("{}", serde_json::to_string_pretty(&ctx).unwrap());
41
42    let reference = ctx.elements[0].to_reference(1920, 1080);
43    let resolved = cel_context::resolve_reference(&ctx, &reference);
44    println!(
45        "resolved reference: {:?}",
46        resolved.map(|el| el.id.as_str())
47    );
48
49    let mut watchdog = ContextWatchdog::new();
50    assert!(watchdog.tick(&ctx, true).is_empty());
51
52    let mut changed = ctx.clone();
53    changed.elements[0].state.focused = false;
54    let events = watchdog.tick(&changed, true);
55    println!("watchdog events: {events:?}");
56}
Source

pub fn merge_events(&self, events: Vec<CelEvent>) -> Vec<CelEvent>

Merge source-specific push events that have already been normalized to CEL events.

Source

pub fn merge_ax_events<T>(&self, _events: Vec<T>) -> Vec<CelEvent>

Compatibility shim for runtimes that still receive source-specific accessibility events. Convert those events before calling merge_events if push-event fidelity matters.

Source

pub fn reset(&mut self)

Reset the watchdog state (e.g., when restarting monitoring).

Trait Implementations§

Source§

impl Default for ContextWatchdog

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.