From: Ian Jackson Date: Fri, 29 Jan 2021 22:55:16 +0000 (+0000) Subject: wdt: Provide WindowGuard::client() X-Git-Tag: otter-0.4.0~633 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e2cf90d6481c6806ceaba9ee74d7726506b202a3;p=otter.git wdt: Provide WindowGuard::client() Signed-off-by: Ian Jackson --- diff --git a/wdriver.rs b/wdriver.rs index c904cdb7..24d9da0f 100644 --- a/wdriver.rs +++ b/wdriver.rs @@ -778,6 +778,7 @@ pub struct WindowGuard<'g> { su: &'g mut Setup, w: &'g Window, matrix: OnceCell, + client: OnceCell, } impl Debug for WindowGuard<'_> { @@ -801,6 +802,18 @@ impl<'g> WindowGuard<'g> { } } + #[throws(AE)] + pub fn client(&mut self) -> String { + let us = self.client.get_or_try_init(||{ + let us = self.execute_script(r##"return us;"##)?; + let us = us.value(); + let us = us.as_str().ok_or_else( + || anyhow!("return us script gave {:?}", &us))?; + Ok::<_,AE>(us.to_owned()) + }).context("obtain client ID")?; + us.clone() + } + #[throws(AE)] pub fn piece_held(&self, pc: &str) -> Option { let held = self.execute_script(&format!(r##" @@ -1009,6 +1022,7 @@ impl Setup { w, su: self, matrix: default(), + client: default(), } } }