diff --git a/crates/client/src/gui.rs b/crates/client/src/gui.rs index 3bac5da..b60a327 100644 --- a/crates/client/src/gui.rs +++ b/crates/client/src/gui.rs @@ -58,6 +58,7 @@ mod share_view; mod sidebar; mod snippet; mod social; +mod surface; mod voice_note; mod voice_settings; mod voice_stats; diff --git a/crates/client/src/gui/camera_view.rs b/crates/client/src/gui/camera_view.rs index 6c5a976..98d35f5 100644 --- a/crates/client/src/gui/camera_view.rs +++ b/crates/client/src/gui/camera_view.rs @@ -1,11 +1,9 @@ use common::model::Id; -use std::sync::Arc; use common::share::{Fps, Kind, Quality, Resolution}; use gpui_kit::{ - AnyElement, Context, Entity, InteractiveElement, IntoElement, ObjectFit, ParentElement, - RenderImage, StatefulInteractiveElement, Styled, StyledImage, Task, Window, assets::IconName, - component::Icon, div, img, px, + AnyElement, AppContext as _, Context, Entity, InteractiveElement, IntoElement, ParentElement, + StatefulInteractiveElement, Styled, Task, Window, assets::IconName, component::Icon, div, px, }; use super::{ @@ -13,6 +11,7 @@ use super::{ media_view::into_render_image, notify_error, share_view::{self, FRAME_TICK}, + surface::Surface, text, widget::{icon_button, spawn_warn}, }; @@ -38,8 +37,12 @@ pub(super) fn tile_quality(stage: Stage) -> WatchQuality { } pub(super) struct Tile { - pub(super) generation: Option, - pub(super) frame: Option>, + pub(super) shown: bool, + pub(super) surface: Entity, +} + +fn tile_cover(stage: Stage) -> bool { + stage != Stage::Grid } impl Yumush { @@ -61,11 +64,13 @@ impl Yumush { if self.chat.tiles.contains_key(&source) { continue; } + let cover = tile_cover(self.chat.stage); + let surface = cx.new(|_| Surface::new(cover)); self.chat.tiles.insert( source, Tile { - generation: None, - frame: None, + shown: false, + surface, }, ); changed = true; @@ -92,7 +97,11 @@ impl Yumush { .copied() .collect(); for source in gone { - if let Some(frame) = self.chat.tiles.remove(&source).and_then(|tile| tile.frame) { + if let Some(tile) = self.chat.tiles.remove(&source) + && let Some(frame) = tile + .surface + .update(cx, |surface, cx| surface.replace(None, cx)) + { cx.drop_image(frame, None); } if viewing != Some(source) { @@ -113,12 +122,15 @@ impl Yumush { let Some(frame) = self.network.share_frame(user_id, kind) else { continue; }; - tile.generation = Some(frame.generation); let next = into_render_image(frame); - if let Some(old) = std::mem::replace(&mut tile.frame, next) { + changed |= !tile.shown && next.is_some(); + tile.shown |= next.is_some(); + if let Some(old) = tile + .surface + .update(cx, |surface, cx| surface.replace(next, cx)) + { cx.drop_image(old, None); } - changed = true; } if changed { @@ -130,10 +142,12 @@ impl Yumush { self.chat.stage = stage; let viewing = self.viewing(); let quality = tile_quality(stage); - for &(user_id, kind) in self.chat.tiles.keys() { + for (&(user_id, kind), tile) in &self.chat.tiles { if viewing != Some((user_id, kind)) { self.network.set_watch_quality(user_id, kind, quality); } + tile.surface + .update(cx, |surface, cx| surface.set_cover(tile_cover(stage), cx)); } cx.notify(); } @@ -321,19 +335,16 @@ fn stage_tile( let entity = entity.clone(); let focused = yumush.is_watching(user_id, kind); let speaking = yumush.chat.waves.speaking.contains(&user_id); - let frame = yumush + let surface = yumush .chat .tiles .get(&(user_id, kind)) - .and_then(|tile| tile.frame.clone()) - .or_else(|| yumush.viewer_frame(user_id, kind)); + .filter(|tile| tile.shown) + .map(|tile| tile.surface.clone()); let user = yumush.chat.author(user_id); let name = user.map_or("Someone", |user| user.username.as_str()); - let content = match (frame, user) { - (Some(frame), _) => img(frame) - .size_full() - .object_fit(ObjectFit::Cover) - .into_any_element(), + let content = match (surface, user) { + (Some(surface), _) => surface.into_any_element(), (None, Some(user)) => div() .size_full() .flex() @@ -401,19 +412,17 @@ fn grid_cell( (user_id, kind): (Id, Kind), shared: bool, ) -> AnyElement { - let frame = yumush + let surface = yumush .chat .tiles .get(&(user_id, kind)) - .and_then(|tile| tile.frame.clone()); + .filter(|tile| tile.shown) + .map(|tile| tile.surface.clone()); let speaking = yumush.chat.waves.speaking.contains(&user_id); let user = yumush.chat.author(user_id); let name = user.map_or("Someone", |user| user.username.as_str()); - let content = match (frame, user) { - (Some(frame), _) => img(frame) - .size_full() - .object_fit(ObjectFit::Contain) - .into_any_element(), + let content = match (surface, user) { + (Some(surface), _) => surface.into_any_element(), (None, Some(user)) => div() .size_full() .flex() diff --git a/crates/client/src/gui/share_view.rs b/crates/client/src/gui/share_view.rs index b54c1d2..a5727c3 100644 --- a/crates/client/src/gui/share_view.rs +++ b/crates/client/src/gui/share_view.rs @@ -11,8 +11,7 @@ const TOP_QUALITY: Quality = Quality { }; use gpui_kit::{ Anchor, AnyElement, AppContext, Context, Div, Entity, InteractiveElement, IntoElement, - MouseButton, ObjectFit, ParentElement, RenderImage, StatefulInteractiveElement, Styled, - StyledImage, Subscription, Task, Window, + MouseButton, ParentElement, StatefulInteractiveElement, Styled, Subscription, Task, Window, assets::IconName, component::{ Icon, @@ -20,7 +19,7 @@ use gpui_kit::{ slider::{Slider, SliderEvent, SliderState}, switch::Switch, }, - div, img, + div, prelude::FluentBuilder as _, px, }; @@ -32,6 +31,7 @@ use super::{ media_view::into_render_image, notify_error, pop_in, settings_page::segmented, + surface::Surface, text, widget::{icon_button, spawn_warn}, }; @@ -88,8 +88,8 @@ impl AudioMode { pub(super) struct Viewer { user_id: Id, kind: Kind, - generation: Option, - frame: Option>, + shown: bool, + surface: Entity, pub(super) fullscreen: bool, volume: Entity, restore: f32, @@ -244,14 +244,6 @@ impl Yumush { .is_some_and(|viewer| viewer.user_id == user_id && viewer.kind == kind) } - pub(super) fn viewer_frame(&self, user_id: Id, kind: Kind) -> Option> { - self.chat - .viewer - .as_ref() - .filter(|viewer| viewer.user_id == user_id && viewer.kind == kind) - .and_then(|viewer| viewer.frame.clone()) - } - pub(super) fn viewing(&self) -> Option<(Id, Kind)> { self.chat .viewer @@ -300,8 +292,8 @@ impl Yumush { self.chat.viewer = Some(Viewer { user_id, kind, - generation: None, - frame: None, + shown: false, + surface: cx.new(|_| Surface::new(false)), fullscreen: false, volume, restore: FULL_VOLUME, @@ -339,9 +331,12 @@ impl Yumush { let Some(viewer) = self.chat.viewer.take() else { return; }; - if let Some(frame) = viewer.frame { - cx.defer(move |cx| cx.drop_image(frame, None)); - } + let surface = viewer.surface.clone(); + cx.defer(move |cx| { + if let Some(frame) = surface.update(cx, |surface, cx| surface.replace(None, cx)) { + cx.drop_image(frame, None); + } + }); let network = self.network.clone(); if self.chat.tiles.contains_key(&(viewer.user_id, viewer.kind)) { network.set_watch_quality( @@ -367,23 +362,30 @@ impl Yumush { let Some(frame) = self.network.share_frame(viewer.user_id, viewer.kind) else { return; }; - viewer.generation = Some(frame.generation); let next = into_render_image(frame); + let appeared = !viewer.shown && next.is_some(); + viewer.shown |= next.is_some(); + let previous = viewer + .surface + .update(cx, |surface, cx| surface.replace(next.clone(), cx)); if let Some(tile) = self.chat.tiles.get_mut(&(viewer.user_id, viewer.kind)) { - tile.generation = viewer.generation; - if let Some(old) = std::mem::replace(&mut tile.frame, next.clone()) - && !viewer - .frame + tile.shown |= next.is_some(); + if let Some(old) = tile + .surface + .update(cx, |surface, cx| surface.replace(next, cx)) + && !previous .as_ref() .is_some_and(|current| Arc::ptr_eq(current, &old)) { cx.drop_image(old, None); } } - if let Some(old) = std::mem::replace(&mut viewer.frame, next) { + if let Some(old) = previous { cx.drop_image(old, None); } - cx.notify(); + if appeared { + cx.notify(); + } } pub(super) fn toggle_fullscreen(&mut self, cx: &mut Context) { @@ -516,12 +518,7 @@ impl Yumush { let entity = entity.clone(); move |_, _, cx| entity.update(cx, |yumush, cx| yumush.close_viewer(cx)) }) - .children( - viewer - .frame - .clone() - .map(|frame| img(frame).size_full().object_fit(ObjectFit::Contain)), - ), + .when(viewer.shown, |video| video.child(viewer.surface.clone())), ) .child( div() diff --git a/crates/client/src/gui/surface.rs b/crates/client/src/gui/surface.rs new file mode 100644 index 0000000..a718c3a --- /dev/null +++ b/crates/client/src/gui/surface.rs @@ -0,0 +1,48 @@ +use std::sync::Arc; + +use gpui_kit::{ + Context, IntoElement, ObjectFit, ParentElement, Render, RenderImage, Styled, StyledImage, + Window, div, img, +}; + +pub(super) struct Surface { + frame: Option>, + cover: bool, +} + +impl Surface { + pub(super) fn new(cover: bool) -> Self { + Self { frame: None, cover } + } + + pub(super) fn replace( + &mut self, + frame: Option>, + cx: &mut Context, + ) -> Option> { + cx.notify(); + std::mem::replace(&mut self.frame, frame) + } + + pub(super) fn set_cover(&mut self, cover: bool, cx: &mut Context) { + if self.cover != cover { + self.cover = cover; + cx.notify(); + } + } +} + +impl Render for Surface { + fn render(&mut self, _: &mut Window, _: &mut Context) -> impl IntoElement { + let fit = if self.cover { + ObjectFit::Cover + } else { + ObjectFit::Contain + }; + div().size_full().children( + self.frame + .clone() + .map(|frame| img(frame).size_full().object_fit(fit)), + ) + } +} diff --git a/harness/down.sh b/harness/down.sh index dc65686..30508a6 100755 --- a/harness/down.sh +++ b/harness/down.sh @@ -2,4 +2,5 @@ STATE="${HARNESS_STATE:-/tmp/claude-1000/yumush-harness}" [ -f "$STATE/pids" ] || exit 0 tac "$STATE/pids" | while read -r name pid; do kill "$pid" 2>/dev/null && echo "stopped $name $pid"; done +systemctl --user stop yumush-harness-session.scope 2>/dev/null rm -f "$STATE/pids" "$STATE/env" "$STATE/env2" diff --git a/harness/up.sh b/harness/up.sh index f3bfd1a..1a14bab 100755 --- a/harness/up.sh +++ b/harness/up.sh @@ -10,7 +10,7 @@ printf '[server_config]\ndatabase_path = "yumush.db"\nserver_address = "127.0.0. cp "$HERE/portals.conf" "$STATE/xdg/xdg-desktop-portal/niri-portals.conf" (cd "$STATE/server" && YUMUSH_CONFIG_DIR="$STATE/server" exec "$ROOT/target/${PROFILE:-harness}/server" >"$STATE/server.log" 2>&1) & echo "server $!" >> "$STATE/pids" -dbus-run-session -- "$HERE/session.sh" "$STATE" >"$STATE/session.log" 2>&1 & +systemd-run --user --scope --collect -q -u yumush-harness-session dbus-run-session -- "$HERE/session.sh" "$STATE" >"$STATE/session.log" 2>&1 & echo "session $!" >> "$STATE/pids" for _ in $(seq 100); do [ -s "$STATE/env" ] && break; sleep 0.2; done cat "$STATE/env"