BlueGit

ict rusty-teams

feat(chat): shared videos play inline like Teams

- Play on a video card opens the SharePoint player in place (embed.aspx by path)
- The player follows the card while scrolling and is cut at the timeline edges
- It closes when the card leaves the timeline or the chat changes
- Links in the player open in the browser; without WebView2 the card opens the browser as before

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-05 · 3 weeks ago

Hash
33b53d7dca94a4e885bac58dda2401be95bb4ba6
Parent
f239793d
6 files changed +369 −11
crates/app/src/inline_video.rs added +208 −0
@@ -0,0 +1,208 @@
1 use std::cell::Cell;
2 use std::rc::Rc;
3
4 use gpui_kit::*;
5
6 #[cfg(windows)]
7 mod native_windows;
8 #[cfg(windows)]
9 use native_windows as native;
10 #[cfg(not(windows))]
11 mod native_stub;
12 #[cfg(not(windows))]
13 use native_stub as native;
14
15 use native::Native;
16 pub use native::available;
17 #[cfg(windows)]
18 pub use native::configure;
19
20 const PERSONAL_SITE: &str = "/personal/";
21 const TEAM_SITES: [&str; 2] = ["/sites/", "/teams/"];
22 const PLAYER_OPTIONS: &str = "%7B%22ust%22%3Atrue%2C%22hv%22%3A%22CopyEmbedCode%22%7D";
23
24 /// SharePoint's embeddable player for a video stored in OneDrive or a team site.
25 pub fn player_url(content_url: &str) -> Option<String> {
26 let rest = content_url.strip_prefix("https://")?;
27 let (host, path) = rest.split_once('/')?;
28 if !host.ends_with(".sharepoint.com") {
29 return None;
30 }
31 let path = format!("/{}", path.split(['?', '#']).next()?);
32 let site_prefix = std::iter::once(PERSONAL_SITE)
33 .chain(TEAM_SITES)
34 .find(|prefix| path.starts_with(prefix))?;
35 let site_name = path[site_prefix.len()..].split('/').next()?;
36 if site_name.is_empty() || path.len() <= site_prefix.len() + site_name.len() + 1 {
37 return None;
38 }
39 let site = format!("https://{host}{site_prefix}{site_name}");
40 Some(format!(
41 "{site}/_layouts/15/embed.aspx?id={path}&embed={PLAYER_OPTIONS}"
42 ))
43 }
44
45 struct Playing {
46 key: SharedString,
47 window: WindowId,
48 native: Native,
49 painted_in: Rc<Cell<u64>>,
50 }
51
52 #[derive(Default)]
53 pub struct InlineVideo {
54 playing: Option<Playing>,
55 frame: Rc<Cell<u64>>,
56 }
57
58 impl Global for InlineVideo {}
59
60 pub fn play(key: SharedString, content_url: &str, window: &mut Window, cx: &mut App) -> bool {
61 let Some(url) = player_url(content_url).filter(|_| available()) else {
62 return false;
63 };
64 stop(cx);
65 let Some((native, mut new_windows)) = Native::open(&url, window) else {
66 return false;
67 };
68 cx.spawn(async move |cx| {
69 while let Some(target) = new_windows.recv().await {
70 cx.update(|cx| cx.open_url(&target));
71 }
72 })
73 .detach();
74 let state = cx.default_global::<InlineVideo>();
75 state.playing = Some(Playing {
76 key,
77 window: window.window_handle().window_id(),
78 native,
79 painted_in: Rc::new(Cell::new(u64::MAX)),
80 });
81 window.refresh();
82 true
83 }
84
85 pub fn stop(cx: &mut App) {
86 if !cx.has_global::<InlineVideo>() {
87 return;
88 }
89 if let Some(playing) = cx.global_mut::<InlineVideo>().playing.take() {
90 playing.native.close();
91 }
92 }
93
94 /// Keeps the player on the slot while the slot is painted.
95 pub fn slot(key: SharedString) -> impl IntoElement {
96 canvas(
97 move |bounds, window, cx| {
98 let Some(state) = cx.try_global::<InlineVideo>() else {
99 return;
100 };
101 let Some(playing) = state.playing.as_ref().filter(|playing| playing.key == key) else {
102 return;
103 };
104 playing.painted_in.set(state.frame.get());
105 let visible = window.content_mask().bounds.intersect(&bounds);
106 let hidden: Vec<Bounds<Pixels>> = clipped_parts(bounds, visible);
107 playing.native.place(
108 bounds,
109 &hidden,
110 window.scale_factor(),
111 visible.size.height > px(0.),
112 );
113 },
114 |_, _, _, _| {},
115 )
116 .absolute()
117 .inset_0()
118 }
119
120 /// Paints after the timeline: closes a player whose slot was not painted this frame.
121 pub fn sentinel() -> impl IntoElement {
122 canvas(
123 |_, window, cx| {
124 let window_id = window.window_handle().window_id();
125 let Some(state) = cx.try_global::<InlineVideo>() else {
126 return false;
127 };
128 let frame = state.frame.get();
129 state.frame.set(frame.wrapping_add(1));
130 state.playing.as_ref().is_some_and(|playing| {
131 playing.window == window_id && playing.painted_in.get() != frame
132 })
133 },
134 |_, orphaned, _, cx| {
135 if orphaned {
136 stop(cx);
137 }
138 },
139 )
140 .absolute()
141 .size_0()
142 }
143
144 fn clipped_parts(bounds: Bounds<Pixels>, visible: Bounds<Pixels>) -> Vec<Bounds<Pixels>> {
145 if visible.size.height <= px(0.) || visible.size.width <= px(0.) {
146 return Vec::new();
147 }
148 let mut parts = Vec::new();
149 if visible.top() > bounds.top() {
150 parts.push(Bounds::from_corners(
151 bounds.origin,
152 point(bounds.right(), visible.top()),
153 ));
154 }
155 if visible.bottom() < bounds.bottom() {
156 parts.push(Bounds::from_corners(
157 point(bounds.left(), visible.bottom()),
158 bounds.bottom_right(),
159 ));
160 }
161 parts
162 }
163
164 #[cfg(test)]
165 mod tests {
166 use gpui_kit::{Bounds, point, px, size};
167
168 use super::{clipped_parts, player_url};
169
170 #[test]
171 fn a_onedrive_chat_video_plays_in_the_personal_site_player() {
172 let url = player_url(
173 "https://contoso-my.sharepoint.com/personal/ann_contoso_com/Documents/Chat%20Files/clip.mp4",
174 );
175 let expected = "https://contoso-my.sharepoint.com/personal/ann_contoso_com/_layouts/15/embed.aspx?id=/personal/ann_contoso_com/Documents/Chat%20Files/clip.mp4&embed=%7B%22ust%22%3Atrue%2C%22hv%22%3A%22CopyEmbedCode%22%7D";
176 assert_eq!(url.as_deref(), Some(expected));
177 }
178
179 #[test]
180 fn a_channel_video_plays_in_the_team_site_player() {
181 let url = player_url(
182 "https://contoso.sharepoint.com/sites/Dev/Shared%20Documents/General/demo.mp4?web=1",
183 )
184 .unwrap();
185 assert!(url.starts_with("https://contoso.sharepoint.com/sites/Dev/_layouts/15/embed.aspx?id=/sites/Dev/Shared%20Documents/General/demo.mp4&"));
186 }
187
188 #[test]
189 fn other_hosts_have_no_inline_player() {
190 assert_eq!(player_url("https://example.com/personal/a/clip.mp4"), None);
191 assert_eq!(player_url("https://contoso.sharepoint.com/clip.mp4"), None);
192 assert_eq!(
193 player_url("https://contoso-my.sharepoint.com/personal/"),
194 None
195 );
196 }
197
198 #[test]
199 fn only_the_parts_outside_the_clip_are_cut_away() {
200 let bounds = Bounds::new(point(px(0.), px(0.)), size(px(100.), px(100.)));
201 let visible = Bounds::new(point(px(0.), px(30.)), size(px(100.), px(50.)));
202 let parts = clipped_parts(bounds, visible);
203 assert_eq!(parts.len(), 2);
204 assert_eq!(parts[0].size.height, px(30.));
205 assert_eq!(parts[1].origin.y, px(80.));
206 assert!(clipped_parts(bounds, bounds).is_empty());
207 }
208 }
@@ -0,0 +1,208 @@
1use std::cell::Cell;
2use std::rc::Rc;
3
4use gpui_kit::*;
5
6#[cfg(windows)]
7mod native_windows;
8#[cfg(windows)]
9use native_windows as native;
10#[cfg(not(windows))]
11mod native_stub;
12#[cfg(not(windows))]
13use native_stub as native;
14
15use native::Native;
16pub use native::available;
17#[cfg(windows)]
18pub use native::configure;
19
20const PERSONAL_SITE: &str = "/personal/";
21const TEAM_SITES: [&str; 2] = ["/sites/", "/teams/"];
22const PLAYER_OPTIONS: &str = "%7B%22ust%22%3Atrue%2C%22hv%22%3A%22CopyEmbedCode%22%7D";
23
24/// SharePoint's embeddable player for a video stored in OneDrive or a team site.
25pub fn player_url(content_url: &str) -> Option<String> {
26 let rest = content_url.strip_prefix("https://")?;
27 let (host, path) = rest.split_once('/')?;
28 if !host.ends_with(".sharepoint.com") {
29 return None;
30 }
31 let path = format!("/{}", path.split(['?', '#']).next()?);
32 let site_prefix = std::iter::once(PERSONAL_SITE)
33 .chain(TEAM_SITES)
34 .find(|prefix| path.starts_with(prefix))?;
35 let site_name = path[site_prefix.len()..].split('/').next()?;
36 if site_name.is_empty() || path.len() <= site_prefix.len() + site_name.len() + 1 {
37 return None;
38 }
39 let site = format!("https://{host}{site_prefix}{site_name}");
40 Some(format!(
41 "{site}/_layouts/15/embed.aspx?id={path}&embed={PLAYER_OPTIONS}"
42 ))
43}
44
45struct Playing {
46 key: SharedString,
47 window: WindowId,
48 native: Native,
49 painted_in: Rc<Cell<u64>>,
50}
51
52#[derive(Default)]
53pub struct InlineVideo {
54 playing: Option<Playing>,
55 frame: Rc<Cell<u64>>,
56}
57
58impl Global for InlineVideo {}
59
60pub fn play(key: SharedString, content_url: &str, window: &mut Window, cx: &mut App) -> bool {
61 let Some(url) = player_url(content_url).filter(|_| available()) else {
62 return false;
63 };
64 stop(cx);
65 let Some((native, mut new_windows)) = Native::open(&url, window) else {
66 return false;
67 };
68 cx.spawn(async move |cx| {
69 while let Some(target) = new_windows.recv().await {
70 cx.update(|cx| cx.open_url(&target));
71 }
72 })
73 .detach();
74 let state = cx.default_global::<InlineVideo>();
75 state.playing = Some(Playing {
76 key,
77 window: window.window_handle().window_id(),
78 native,
79 painted_in: Rc::new(Cell::new(u64::MAX)),
80 });
81 window.refresh();
82 true
83}
84
85pub fn stop(cx: &mut App) {
86 if !cx.has_global::<InlineVideo>() {
87 return;
88 }
89 if let Some(playing) = cx.global_mut::<InlineVideo>().playing.take() {
90 playing.native.close();
91 }
92}
93
94/// Keeps the player on the slot while the slot is painted.
95pub fn slot(key: SharedString) -> impl IntoElement {
96 canvas(
97 move |bounds, window, cx| {
98 let Some(state) = cx.try_global::<InlineVideo>() else {
99 return;
100 };
101 let Some(playing) = state.playing.as_ref().filter(|playing| playing.key == key) else {
102 return;
103 };
104 playing.painted_in.set(state.frame.get());
105 let visible = window.content_mask().bounds.intersect(&bounds);
106 let hidden: Vec<Bounds<Pixels>> = clipped_parts(bounds, visible);
107 playing.native.place(
108 bounds,
109 &hidden,
110 window.scale_factor(),
111 visible.size.height > px(0.),
112 );
113 },
114 |_, _, _, _| {},
115 )
116 .absolute()
117 .inset_0()
118}
119
120/// Paints after the timeline: closes a player whose slot was not painted this frame.
121pub fn sentinel() -> impl IntoElement {
122 canvas(
123 |_, window, cx| {
124 let window_id = window.window_handle().window_id();
125 let Some(state) = cx.try_global::<InlineVideo>() else {
126 return false;
127 };
128 let frame = state.frame.get();
129 state.frame.set(frame.wrapping_add(1));
130 state.playing.as_ref().is_some_and(|playing| {
131 playing.window == window_id && playing.painted_in.get() != frame
132 })
133 },
134 |_, orphaned, _, cx| {
135 if orphaned {
136 stop(cx);
137 }
138 },
139 )
140 .absolute()
141 .size_0()
142}
143
144fn clipped_parts(bounds: Bounds<Pixels>, visible: Bounds<Pixels>) -> Vec<Bounds<Pixels>> {
145 if visible.size.height <= px(0.) || visible.size.width <= px(0.) {
146 return Vec::new();
147 }
148 let mut parts = Vec::new();
149 if visible.top() > bounds.top() {
150 parts.push(Bounds::from_corners(
151 bounds.origin,
152 point(bounds.right(), visible.top()),
153 ));
154 }
155 if visible.bottom() < bounds.bottom() {
156 parts.push(Bounds::from_corners(
157 point(bounds.left(), visible.bottom()),
158 bounds.bottom_right(),
159 ));
160 }
161 parts
162}
163
164#[cfg(test)]
165mod tests {
166 use gpui_kit::{Bounds, point, px, size};
167
168 use super::{clipped_parts, player_url};
169
170 #[test]
171 fn a_onedrive_chat_video_plays_in_the_personal_site_player() {
172 let url = player_url(
173 "https://contoso-my.sharepoint.com/personal/ann_contoso_com/Documents/Chat%20Files/clip.mp4",
174 );
175 let expected = "https://contoso-my.sharepoint.com/personal/ann_contoso_com/_layouts/15/embed.aspx?id=/personal/ann_contoso_com/Documents/Chat%20Files/clip.mp4&embed=%7B%22ust%22%3Atrue%2C%22hv%22%3A%22CopyEmbedCode%22%7D";
176 assert_eq!(url.as_deref(), Some(expected));
177 }
178
179 #[test]
180 fn a_channel_video_plays_in_the_team_site_player() {
181 let url = player_url(
182 "https://contoso.sharepoint.com/sites/Dev/Shared%20Documents/General/demo.mp4?web=1",
183 )
184 .unwrap();
185 assert!(url.starts_with("https://contoso.sharepoint.com/sites/Dev/_layouts/15/embed.aspx?id=/sites/Dev/Shared%20Documents/General/demo.mp4&"));
186 }
187
188 #[test]
189 fn other_hosts_have_no_inline_player() {
190 assert_eq!(player_url("https://example.com/personal/a/clip.mp4"), None);
191 assert_eq!(player_url("https://contoso.sharepoint.com/clip.mp4"), None);
192 assert_eq!(
193 player_url("https://contoso-my.sharepoint.com/personal/"),
194 None
195 );
196 }
197
198 #[test]
199 fn only_the_parts_outside_the_clip_are_cut_away() {
200 let bounds = Bounds::new(point(px(0.), px(0.)), size(px(100.), px(100.)));
201 let visible = Bounds::new(point(px(0.), px(30.)), size(px(100.), px(50.)));
202 let parts = clipped_parts(bounds, visible);
203 assert_eq!(parts.len(), 2);
204 assert_eq!(parts[0].size.height, px(30.));
205 assert_eq!(parts[1].origin.y, px(80.));
206 assert!(clipped_parts(bounds, bounds).is_empty());
207 }
208}
crates/app/src/inline_video/native_stub.rs added +25 −0
@@ -0,0 +1,25 @@
1 use gpui_kit::*;
2 use tokio::sync::mpsc::UnboundedReceiver;
3
4 pub fn available() -> bool {
5 false
6 }
7
8 pub struct Native;
9
10 impl Native {
11 pub fn open(_url: &str, _window: &Window) -> Option<(Native, UnboundedReceiver<String>)> {
12 None
13 }
14
15 pub fn place(
16 &self,
17 _bounds: Bounds<Pixels>,
18 _hidden: &[Bounds<Pixels>],
19 _scale: f32,
20 _visible: bool,
21 ) {
22 }
23
24 pub fn close(&self) {}
25 }
@@ -0,0 +1,25 @@
1use gpui_kit::*;
2use tokio::sync::mpsc::UnboundedReceiver;
3
4pub fn available() -> bool {
5 false
6}
7
8pub struct Native;
9
10impl Native {
11 pub fn open(_url: &str, _window: &Window) -> Option<(Native, UnboundedReceiver<String>)> {
12 None
13 }
14
15 pub fn place(
16 &self,
17 _bounds: Bounds<Pixels>,
18 _hidden: &[Bounds<Pixels>],
19 _scale: f32,
20 _visible: bool,
21 ) {
22 }
23
24 pub fn close(&self) {}
25}
crates/app/src/inline_video/native_windows.rs added +97 −0
@@ -0,0 +1,97 @@
1 use std::cell::{Cell, OnceCell, RefCell};
2 use std::path::PathBuf;
3 use std::sync::OnceLock;
4
5 use gpui_kit::*;
6 use tokio::sync::mpsc::{UnboundedReceiver, unbounded_channel};
7 use webview::{EmbedBounds, EmbedEvent, EmbedHost, EmbedSpec, MainEmbed};
8
9 use crate::notify::platform;
10 use crate::theme;
11
12 static USER_DATA_FOLDER: OnceLock<PathBuf> = OnceLock::new();
13
14 thread_local! {
15 static HOST: OnceCell<EmbedHost> = const { OnceCell::new() };
16 }
17
18 pub fn configure(user_data_folder: PathBuf) {
19 let _ = USER_DATA_FOLDER.set(user_data_folder);
20 }
21
22 pub fn available() -> bool {
23 USER_DATA_FOLDER.get().is_some()
24 }
25
26 fn host() -> Option<EmbedHost> {
27 let folder = USER_DATA_FOLDER.get()?;
28 Some(HOST.with(|host| host.get_or_init(|| EmbedHost::new(folder.clone())).clone()))
29 }
30
31 fn physical(bounds: Bounds<Pixels>, scale: f32) -> EmbedBounds {
32 EmbedBounds::from_logical(
33 f32::from(bounds.origin.x),
34 f32::from(bounds.origin.y),
35 f32::from(bounds.size.width),
36 f32::from(bounds.size.height),
37 scale,
38 )
39 }
40
41 pub struct Native {
42 embed: MainEmbed,
43 placed: Cell<Option<(EmbedBounds, bool)>>,
44 cut: RefCell<Vec<EmbedBounds>>,
45 }
46
47 impl Native {
48 pub fn open(url: &str, window: &Window) -> Option<(Native, UnboundedReceiver<String>)> {
49 let parent = platform::native_handle(window)?;
50 let (embed, mut events) = host()?.open(EmbedSpec {
51 parent,
52 url: url.to_owned(),
53 background: theme::background_hex(),
54 })?;
55 let (opened, new_windows) = unbounded_channel();
56 std::thread::spawn(move || {
57 while let Some(event) = events.blocking_recv() {
58 match event {
59 EmbedEvent::NewWindow(target) => {
60 let _ = opened.send(target);
61 }
62 EmbedEvent::Closed => break,
63 EmbedEvent::Navigated(_) | EmbedEvent::Loaded => {}
64 }
65 }
66 });
67 let native = Native {
68 embed,
69 placed: Cell::new(None),
70 cut: RefCell::new(Vec::new()),
71 };
72 Some((native, new_windows))
73 }
74
75 pub fn place(
76 &self,
77 bounds: Bounds<Pixels>,
78 hidden: &[Bounds<Pixels>],
79 scale: f32,
80 visible: bool,
81 ) {
82 let cut: Vec<EmbedBounds> = hidden.iter().map(|part| physical(*part, scale)).collect();
83 if *self.cut.borrow() != cut {
84 self.embed.set_cutouts(cut.clone());
85 *self.cut.borrow_mut() = cut;
86 }
87 let placement = (physical(bounds, scale), visible);
88 if self.placed.get() != Some(placement) {
89 self.placed.set(Some(placement));
90 self.embed.place(placement.0, placement.1);
91 }
92 }
93
94 pub fn close(&self) {
95 self.embed.close();
96 }
97 }
@@ -0,0 +1,97 @@
1use std::cell::{Cell, OnceCell, RefCell};
2use std::path::PathBuf;
3use std::sync::OnceLock;
4
5use gpui_kit::*;
6use tokio::sync::mpsc::{UnboundedReceiver, unbounded_channel};
7use webview::{EmbedBounds, EmbedEvent, EmbedHost, EmbedSpec, MainEmbed};
8
9use crate::notify::platform;
10use crate::theme;
11
12static USER_DATA_FOLDER: OnceLock<PathBuf> = OnceLock::new();
13
14thread_local! {
15 static HOST: OnceCell<EmbedHost> = const { OnceCell::new() };
16}
17
18pub fn configure(user_data_folder: PathBuf) {
19 let _ = USER_DATA_FOLDER.set(user_data_folder);
20}
21
22pub fn available() -> bool {
23 USER_DATA_FOLDER.get().is_some()
24}
25
26fn host() -> Option<EmbedHost> {
27 let folder = USER_DATA_FOLDER.get()?;
28 Some(HOST.with(|host| host.get_or_init(|| EmbedHost::new(folder.clone())).clone()))
29}
30
31fn physical(bounds: Bounds<Pixels>, scale: f32) -> EmbedBounds {
32 EmbedBounds::from_logical(
33 f32::from(bounds.origin.x),
34 f32::from(bounds.origin.y),
35 f32::from(bounds.size.width),
36 f32::from(bounds.size.height),
37 scale,
38 )
39}
40
41pub struct Native {
42 embed: MainEmbed,
43 placed: Cell<Option<(EmbedBounds, bool)>>,
44 cut: RefCell<Vec<EmbedBounds>>,
45}
46
47impl Native {
48 pub fn open(url: &str, window: &Window) -> Option<(Native, UnboundedReceiver<String>)> {
49 let parent = platform::native_handle(window)?;
50 let (embed, mut events) = host()?.open(EmbedSpec {
51 parent,
52 url: url.to_owned(),
53 background: theme::background_hex(),
54 })?;
55 let (opened, new_windows) = unbounded_channel();
56 std::thread::spawn(move || {
57 while let Some(event) = events.blocking_recv() {
58 match event {
59 EmbedEvent::NewWindow(target) => {
60 let _ = opened.send(target);
61 }
62 EmbedEvent::Closed => break,
63 EmbedEvent::Navigated(_) | EmbedEvent::Loaded => {}
64 }
65 }
66 });
67 let native = Native {
68 embed,
69 placed: Cell::new(None),
70 cut: RefCell::new(Vec::new()),
71 };
72 Some((native, new_windows))
73 }
74
75 pub fn place(
76 &self,
77 bounds: Bounds<Pixels>,
78 hidden: &[Bounds<Pixels>],
79 scale: f32,
80 visible: bool,
81 ) {
82 let cut: Vec<EmbedBounds> = hidden.iter().map(|part| physical(*part, scale)).collect();
83 if *self.cut.borrow() != cut {
84 self.embed.set_cutouts(cut.clone());
85 *self.cut.borrow_mut() = cut;
86 }
87 let placement = (physical(bounds, scale), visible);
88 if self.placed.get() != Some(placement) {
89 self.placed.set(Some(placement));
90 self.embed.place(placement.0, placement.1);
91 }
92 }
93
94 pub fn close(&self) {
95 self.embed.close();
96 }
97}
crates/app/src/main.rs +2 −0
@@ -6,6 +6,7 @@
6 6 mod active_appearance;
7 7 pub mod agents;
8 8 pub mod call;
9 mod inline_video;
9 10 #[cfg(test)]
10 11 mod layout_guard;
11 12 pub mod notify;
@@ -112,6 +113,7 @@ fn transport(
112 113 Some(directory) => directory.join(WEBVIEW_FOLDER),
113 114 None => data_path(WEBVIEW_FOLDER),
114 115 };
116 inline_video::configure(user_data_folder.clone());
115 117 let transport = webview::start(webview::HostConfig {
116 118 user_data_folder,
117 119 window_title: format!("{APP_NAME} - Sign in"),
@@ -6,6 +6,7 @@
6mod active_appearance;
6mod active_appearance;
7pub mod agents;
7pub mod agents;
8pub mod call;
8pub mod call;
9mod inline_video;
9#[cfg(test)]
10#[cfg(test)]
10mod layout_guard;
11mod layout_guard;
11pub mod notify;
12pub mod notify;
@@ -112,6 +113,7 @@ fn transport(
112 Some(directory) => directory.join(WEBVIEW_FOLDER),
113 Some(directory) => directory.join(WEBVIEW_FOLDER),
113 None => data_path(WEBVIEW_FOLDER),
114 None => data_path(WEBVIEW_FOLDER),
114 };
115 };
116 inline_video::configure(user_data_folder.clone());
115 let transport = webview::start(webview::HostConfig {
117 let transport = webview::start(webview::HostConfig {
116 user_data_folder,
118 user_data_folder,
117 window_title: format!("{APP_NAME} - Sign in"),
119 window_title: format!("{APP_NAME} - Sign in"),
crates/app/src/views/attachments.rs +35 −11
@@ -11,6 +11,7 @@ use super::widgets::{icon, symbol};
11 11 use crate::data::Directory;
12 12 use crate::downloads::{self, DownloadState};
13 13 use crate::format;
14 use crate::inline_video;
14 15 use crate::remote_image;
15 16 use crate::render::{Block, render_blocks};
16 17 use crate::rows::LocalImage;
@@ -243,7 +244,7 @@ fn save_button(
243 244 }
244 245 }
245 246
246 fn file_preview(card: &FileCard, directory: &Directory) -> Option<Div> {
247 fn file_preview(card: &FileCard, id: &str, directory: &Directory) -> Option<Stateful<Div>> {
247 248 let image = card
248 249 .preview()
249 250 .and_then(|preview| directory.image(&preview.url).map(|entry| entry.path.clone()));
@@ -251,6 +252,7 @@ fn file_preview(card: &FileCard, directory: &Directory) -> Option<Div> {
251 252 return None;
252 253 }
253 254 let frame = div()
255 .id(SharedString::from(format!("{id}-preview")))
254 256 .relative()
255 257 .w_full()
256 258 .h(px(FILE_PREVIEW_HEIGHT))
@@ -263,18 +265,33 @@ fn file_preview(card: &FileCard, directory: &Directory) -> Option<Div> {
263 265 })),
264 266 None => frame,
265 267 };
268 let player_key = SharedString::from(format!("{id}-player"));
269 let content_url = card.open_url.clone();
266 270 Some(frame.when(card.kind == FileKind::Video, |frame| {
267 frame.child(
268 h_flex().absolute().inset_0().items_center().justify_center().child(
271 let play_key = player_key.clone();
272 frame
273 .child(inline_video::slot(player_key))
274 .on_click(move |_, window, cx| {
275 if inline_video::play(play_key.clone(), &content_url, window, cx) {
276 cx.stop_propagation();
277 }
278 })
279 .child(
269 280 h_flex()
270 .size(px(PLAY_BUTTON_SIZE))
271 .rounded_full()
281 .absolute()
282 .inset_0()
272 283 .items_center()
273 284 .justify_center()
274 .bg(black().opacity(0.5))
275 .child(icon(IconName::Play, 18., theme::white())),
276 ),
277 )
285 .child(
286 h_flex()
287 .size(px(PLAY_BUTTON_SIZE))
288 .rounded_full()
289 .items_center()
290 .justify_center()
291 .bg(black().opacity(0.5))
292 .child(icon(IconName::Play, 18., theme::white())),
293 ),
294 )
278 295 }))
279 296 }
280 297
@@ -294,6 +311,7 @@ fn file_view(
294 311 let button = actions
295 312 .filter(|_| !card.open_url.is_empty() && card.kind != FileKind::Loop)
296 313 .map(|actions| save_button(state, format!("{id}-save"), index, actions.activate.clone()));
314 let preview = file_preview(card, &id, directory);
297 315 let row = h_flex()
298 316 .w_full()
299 317 .gap(px(12.))
@@ -332,7 +350,7 @@ fn file_view(
332 350 .bg(theme::surface())
333 351 .cursor_pointer()
334 352 .hover(|card| card.bg(theme::row_hover()))
335 .children(file_preview(card, directory))
353 .children(preview)
336 354 .child(row)
337 355 .when_some(progress, |card, fraction| {
338 356 card.child(
@@ -467,7 +485,13 @@ pub fn attachments_view(
467 485 }),
468 486 )
469 487 .children(files.iter().enumerate().map(|(index, card)| {
470 file_view(card, format!("{id}-file-{index}"), index, file_actions, directory)
488 file_view(
489 card,
490 format!("{id}-file-{index}"),
491 index,
492 file_actions,
493 directory,
494 )
471 495 })),
472 496 )
473 497 }
@@ -11,6 +11,7 @@ use super::widgets::{icon, symbol};
11use crate::data::Directory;
11use crate::data::Directory;
12use crate::downloads::{self, DownloadState};
12use crate::downloads::{self, DownloadState};
13use crate::format;
13use crate::format;
14use crate::inline_video;
14use crate::remote_image;
15use crate::remote_image;
15use crate::render::{Block, render_blocks};
16use crate::render::{Block, render_blocks};
16use crate::rows::LocalImage;
17use crate::rows::LocalImage;
@@ -243,7 +244,7 @@ fn save_button(
243 }
244 }
244}
245}
245
246
246fn file_preview(card: &FileCard, directory: &Directory) -> Option<Div> {
247fn file_preview(card: &FileCard, id: &str, directory: &Directory) -> Option<Stateful<Div>> {
247 let image = card
248 let image = card
248 .preview()
249 .preview()
249 .and_then(|preview| directory.image(&preview.url).map(|entry| entry.path.clone()));
250 .and_then(|preview| directory.image(&preview.url).map(|entry| entry.path.clone()));
@@ -251,6 +252,7 @@ fn file_preview(card: &FileCard, directory: &Directory) -> Option<Div> {
251 return None;
252 return None;
252 }
253 }
253 let frame = div()
254 let frame = div()
255 .id(SharedString::from(format!("{id}-preview")))
254 .relative()
256 .relative()
255 .w_full()
257 .w_full()
256 .h(px(FILE_PREVIEW_HEIGHT))
258 .h(px(FILE_PREVIEW_HEIGHT))
@@ -263,18 +265,33 @@ fn file_preview(card: &FileCard, directory: &Directory) -> Option<Div> {
263 })),
265 })),
264 None => frame,
266 None => frame,
265 };
267 };
268 let player_key = SharedString::from(format!("{id}-player"));
269 let content_url = card.open_url.clone();
266 Some(frame.when(card.kind == FileKind::Video, |frame| {
270 Some(frame.when(card.kind == FileKind::Video, |frame| {
267 frame.child(
271 let play_key = player_key.clone();
268 h_flex().absolute().inset_0().items_center().justify_center().child(
272 frame
273 .child(inline_video::slot(player_key))
274 .on_click(move |_, window, cx| {
275 if inline_video::play(play_key.clone(), &content_url, window, cx) {
276 cx.stop_propagation();
277 }
278 })
279 .child(
269 h_flex()
280 h_flex()
270 .size(px(PLAY_BUTTON_SIZE))
281 .absolute()
271 .rounded_full()
282 .inset_0()
272 .items_center()
283 .items_center()
273 .justify_center()
284 .justify_center()
274 .bg(black().opacity(0.5))
285 .child(
275 .child(icon(IconName::Play, 18., theme::white())),
286 h_flex()
276 ),
287 .size(px(PLAY_BUTTON_SIZE))
277 )
288 .rounded_full()
289 .items_center()
290 .justify_center()
291 .bg(black().opacity(0.5))
292 .child(icon(IconName::Play, 18., theme::white())),
293 ),
294 )
278 }))
295 }))
279}
296}
280
297
@@ -294,6 +311,7 @@ fn file_view(
294 let button = actions
311 let button = actions
295 .filter(|_| !card.open_url.is_empty() && card.kind != FileKind::Loop)
312 .filter(|_| !card.open_url.is_empty() && card.kind != FileKind::Loop)
296 .map(|actions| save_button(state, format!("{id}-save"), index, actions.activate.clone()));
313 .map(|actions| save_button(state, format!("{id}-save"), index, actions.activate.clone()));
314 let preview = file_preview(card, &id, directory);
297 let row = h_flex()
315 let row = h_flex()
298 .w_full()
316 .w_full()
299 .gap(px(12.))
317 .gap(px(12.))
@@ -332,7 +350,7 @@ fn file_view(
332 .bg(theme::surface())
350 .bg(theme::surface())
333 .cursor_pointer()
351 .cursor_pointer()
334 .hover(|card| card.bg(theme::row_hover()))
352 .hover(|card| card.bg(theme::row_hover()))
335 .children(file_preview(card, directory))
353 .children(preview)
336 .child(row)
354 .child(row)
337 .when_some(progress, |card, fraction| {
355 .when_some(progress, |card, fraction| {
338 card.child(
356 card.child(
@@ -467,7 +485,13 @@ pub fn attachments_view(
467 }),
485 }),
468 )
486 )
469 .children(files.iter().enumerate().map(|(index, card)| {
487 .children(files.iter().enumerate().map(|(index, card)| {
470 file_view(card, format!("{id}-file-{index}"), index, file_actions, directory)
488 file_view(
489 card,
490 format!("{id}-file-{index}"),
491 index,
492 file_actions,
493 directory,
494 )
471 })),
495 })),
472 )
496 )
473}
497}
crates/app/src/views/conversation.rs +2 −0
@@ -920,6 +920,7 @@ impl ConversationView {
920 920 self.restore_subject(None, window, cx);
921 921 self.toolbar_hovered = None;
922 922 self.reset_copilot();
923 crate::inline_video::stop(cx);
923 924 self.toolbar_pinned = None;
924 925 self.toolbar_suppressed = None;
925 926 self.agent_layouts.clear();
@@ -4101,6 +4102,7 @@ impl Render for ConversationView {
4101 4102 cx.propagate();
4102 4103 }
4103 4104 }));
4105 let root = root.child(crate::inline_video::sentinel());
4104 4106 match copilot_island {
4105 4107 Some(island) => h_flex()
4106 4108 .size_full()
@@ -920,6 +920,7 @@ impl ConversationView {
920 self.restore_subject(None, window, cx);
920 self.restore_subject(None, window, cx);
921 self.toolbar_hovered = None;
921 self.toolbar_hovered = None;
922 self.reset_copilot();
922 self.reset_copilot();
923 crate::inline_video::stop(cx);
923 self.toolbar_pinned = None;
924 self.toolbar_pinned = None;
924 self.toolbar_suppressed = None;
925 self.toolbar_suppressed = None;
925 self.agent_layouts.clear();
926 self.agent_layouts.clear();
@@ -4101,6 +4102,7 @@ impl Render for ConversationView {
4101 cx.propagate();
4102 cx.propagate();
4102 }
4103 }
4103 }));
4104 }));
4105 let root = root.child(crate::inline_video::sentinel());
4104 match copilot_island {
4106 match copilot_island {
4105 Some(island) => h_flex()
4107 Some(island) => h_flex()
4106 .size_full()
4108 .size_full()