Skip to main content

ShadowDom

Struct ShadowDom 

Source
pub struct ShadowDom<D: Desktop> { /* private fields */ }
Expand description

A cached registry of named live element handles. Does not own the desktop; callers pass &D to the methods that need to re-query the UIA tree.

Implementations§

Source§

impl<D: Desktop> ShadowDom<D>

Source

pub fn new() -> Self

Source

pub fn set_depth(&mut self, depth: usize)

Set the current subflow depth. At depth 0, all anchors use their raw name. At depth N, Stable/Ephemeral anchors are stored under ":".repeat(N) + name.

Source

pub fn depth(&self) -> usize

Get the current subflow depth.

Source

pub fn set_launch_context(&mut self, ctx: LaunchContext)

Store the launch context so root-anchor first-resolutions use it for filtering.

Source

pub fn mount( &mut self, anchors: Vec<AnchorDef>, desktop: &D, ) -> Result<(), AutomataError>

Register anchor definitions and immediately resolve Root-tier anchors.

Source

pub fn insert(&mut self, name: impl Into<String>, element: D::Elem)

Insert an element directly into the cache (used for Ephemeral captures).

Source

pub fn get( &mut self, name: &str, desktop: &D, ) -> Result<&D::Elem, AutomataError>

Retrieve a live handle by name. Re-queries if the cached handle is stale.

Returns Err if the anchor cannot be resolved (root gone, selector not found after walk-up, or name not registered).

Source

pub fn invalidate_session(&mut self, session_name: &str)

Remove a session anchor and all stable anchors that depend on it.

Source

pub fn unmount(&mut self, names: &[&str], desktop: &D)

Unmount anchors by name, removing their definition, cached handle, and snapshot. The symmetric inverse of mount: after this call the names are completely unknown to the registry.

Root and Session anchors are globally shared and cannot be unmounted this way; a warning is logged and the name is skipped.

Any Tab anchor whose tab was opened by the workflow (created=true) is closed via desktop.browser().close_tab() before its handle is removed.

Source

pub fn is_live(&self, name: &str) -> bool

Check whether a handle is currently cached and live (no re-query).

Source

pub fn find_descendant( &mut self, scope: &str, selector: &SelectorPath, desktop: &D, ) -> Result<Option<D::Elem>, AutomataError>

Find a descendant element matching selector within scope, using a stale-first strategy with partial-tree re-resolution:

  1. Cache hit, live → return immediately (1 COM call, no DFS).
  2. Cache hit, stale, step-parent live → re-run the selector’s last step from the cached step-parent (narrow search — O(subtree) not O(whole tree)). Update the cache on success; fall through on failure.
  3. Cache hit, stale, step-parent also stale → clear cache entry, fall through to full DFS.
  4. Cache miss → full find_one traversal from the anchor root; cache both the result and its step-parent for next time.

The cache is cleared whenever the scope anchor is re-resolved or unmounted.

Source

pub fn sync_changes(&mut self, name: &str, desktop: &D) -> Vec<String>

Snapshot the live subtree of name, diff against the previous snapshot, emit each change to the tracer, and return the change lines.

The returned Vec is empty when nothing changed. Each line has the form:

dom: <scope>: ADDED [role "name"]
dom: <scope> > [role "name"]: REMOVED [child-role "child"]
dom: <scope>: name "old" → "new"

Primarily used by the executor’s poll loop, but also directly testable.

Source

pub fn sync(&mut self, name: &str, desktop: &D)

Like [sync_changes] but discards the return value. Convenience for the executor’s poll loop.

Source

pub fn anchor_pid(&self, name: &str) -> Option<u32>

Returns the effective PID for a registered anchor. Prefers the locked PID (captured on first resolution) over the statically declared PID, since the locked value is always the more specific one.

Source

pub fn anchor_hwnd(&self, name: &str) -> Option<u64>

Returns the locked HWND for a registered anchor, if one was captured on first resolution.

Source

pub fn tab_handle(&self, name: &str) -> Option<&TabHandle>

Return a reference to the tab handle for name, if present.

Source

pub fn cleanup_depth(&mut self, depth: usize, desktop: &D)

Remove all anchors stored at exactly depth (keys prefixed with exactly ":".repeat(depth) followed by a non-colon character). Acts as a safety net for anything not explicitly unmounted by the subflow. Any created Tab anchors at this depth are closed via desktop.browser().close_tab().

Trait Implementations§

Source§

impl<D: Desktop> Default for ShadowDom<D>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<D> Freeze for ShadowDom<D>

§

impl<D> RefUnwindSafe for ShadowDom<D>
where <D as Desktop>::Elem: RefUnwindSafe,

§

impl<D> Send for ShadowDom<D>
where <D as Desktop>::Elem: Send,

§

impl<D> Sync for ShadowDom<D>
where <D as Desktop>::Elem: Sync,

§

impl<D> Unpin for ShadowDom<D>
where <D as Desktop>::Elem: Unpin,

§

impl<D> UnsafeUnpin for ShadowDom<D>

§

impl<D> UnwindSafe for ShadowDom<D>
where <D as Desktop>::Elem: UnwindSafe,

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.