Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.
Play on phone: stream the player from the start, sound to the watcher
Beebc0d576d87a0
diff --git a/desktop/app/src/pc_audio_stream.rs b/desktop/app/src/pc_audio_stream.rsindex 26732e1..03e7efb 100644--- a/desktop/app/src/pc_audio_stream.rs+++ b/desktop/app/src/pc_audio_stream.rs@@ -297,6 +297,11 @@ fn capture_and_stream_once() -> Result<(), String> {'capture: while is_enabled() {std::thread::sleep(Duration::from_millis(2));+ // Another phone asked for the sound (it watches the PC's playback):+ // start over for that one.+ if target() != wanted && target().is_some_and(|t| peers.contains(&t)) {+ break 'capture;+ }// SAFETY: Drain available capture packets from `IAudioCaptureClient`.unsafe {loop {diff --git a/desktop/app/src/play_on_phone.rs b/desktop/app/src/play_on_phone.rsindex f654773..167c1ff 100644--- a/desktop/app/src/play_on_phone.rs+++ b/desktop/app/src/play_on_phone.rs@@ -139,6 +139,9 @@ pub struct Place {/// How often the picture's place is looked up again.const FOLLOW_EVERY: Duration = Duration::from_millis(500);+/// How long a browser's player may take to show up in UI Automation+/// before the whole page is streamed instead.+const FIND_PLAYER: Duration = Duration::from_secs(2);impl Place {/// The window the picture is in.@@ -160,6 +163,7 @@ impl Watched {browser::use_physical_pixels();let automation = Automation::new().ok();let mut window: Option<Window> = None;+ let started = std::time::Instant::now();while !stopped.load(Ordering::Relaxed) {// The window it played in, while it's still there; else find it again.if window.as_ref().is_none_or(|w| browser::frame_of(w.hwnd).is_none()) {@@ -169,7 +173,14 @@ impl Watched {let place = window.as_ref().and_then(|w| {let frame = browser::frame_of(w.hwnd)?;let on_screen = match &automation {- Some(a) if browser::is_browser(&w.program) => a.video_rect(w)?,+ // A browser builds what UI Automation sees of a page+ // only once asked: give the player a moment to show+ // up before streaming the whole page.+ Some(a) if browser::is_browser(&w.program) => match a.player_rect(w) {+ Some(player) => player,+ None if started.elapsed() < FIND_PLAYER => return None,+ None => a.page_rect(w).unwrap_or(frame),+ },_ => frame,};let in_window = RECT {diff --git a/desktop/app/src/win/browser.rs b/desktop/app/src/win/browser.rsindex 3babbed..65ce884 100644--- a/desktop/app/src/win/browser.rs+++ b/desktop/app/src/win/browser.rs@@ -225,16 +225,32 @@ impl Automation {/// Where on screen the video plays in `window`, in physical pixels:/// YouTube's player when it's there, else the page, else the window.+ #[cfg(test)]pub fn video_rect(&self, window: &Window) -> Option<RECT> {- let root = self.root(window);- let element = root.as_ref().and_then(|root| {- self.find(root, UIA_ClassNamePropertyId, VARIANT::from("video-stream html5-main-video")).or_else(- || self.find(root, UIA_ControlTypePropertyId, VARIANT::from(UIA_DocumentControlTypeId.0)),- )- });+ self.player_rect(window).or_else(|| self.page_rect(window)).or_else(|| frame_of(window.hwnd))+ }++ /// Where YouTube's player is in `window`, once the browser exposes its+ /// page (a moment after it's first asked).+ pub fn player_rect(&self, window: &Window) -> Option<RECT> {+ let root = self.root(window)?;+ self.rect_of(self.find(+ &root,+ UIA_ClassNamePropertyId,+ VARIANT::from("video-stream html5-main-video"),+ ))+ }++ /// Where the page is in `window`.+ pub fn page_rect(&self, window: &Window) -> Option<RECT> {+ let root = self.root(window)?;+ self.rect_of(self.find(&root, UIA_ControlTypePropertyId, VARIANT::from(UIA_DocumentControlTypeId.0)))+ }++ fn rect_of(&self, element: Option<IUIAutomationElement>) -> Option<RECT> {// SAFETY: a COM call on a live element.let rect = element.and_then(|e| unsafe { e.CurrentBoundingRectangle() }.ok());- rect.filter(|r| r.right - r.left >= 64 && r.bottom - r.top >= 64).or_else(|| frame_of(window.hwnd))+ rect.filter(|r| r.right - r.left >= 64 && r.bottom - r.top >= 64)}}