BlueGit

ict rusty-teams

Merge remote-tracking branch 'origin/main' into fix/echo-bot-chat

# Conflicts:
#	crates/app-base/src/assets.rs

metis Daniel Däschle · pushed by metis

Authored 2026-10-17 · 6 weeks ago

Hash
9ee740485dbde5376421bbc5ff3b64279832f72b
50 files changed +3029 −1752
Cargo.lock +0 −2
@@ -4074,8 +4074,6 @@ dependencies = [
4074 4074 [[package]]
4075 4075 name = "gpui-pre-windows"
4076 4076 version = "0.3.8"
4077 source = "registry+https://github.com/rust-lang/crates.io-index"
4078 checksum = "371f9bb13f97e3bea2f8b8e5e81232bb74d735153c244ae67f7400e743925b1c"
4079 4077 dependencies = [
4080 4078 "accesskit",
4081 4079 "accesskit_windows",
@@ -4074,8 +4074,6 @@ dependencies = [
4074[[package]]
4074[[package]]
4075name = "gpui-pre-windows"
4075name = "gpui-pre-windows"
4076version = "0.3.8"
4076version = "0.3.8"
4077source = "registry+https://github.com/rust-lang/crates.io-index"
4078checksum = "371f9bb13f97e3bea2f8b8e5e81232bb74d735153c244ae67f7400e743925b1c"
4079dependencies = [
4077dependencies = [
4080 "accesskit",
4078 "accesskit",
4081 "accesskit_windows",
4079 "accesskit_windows",
crates/app-base/src/assets.rs +8 −5
@@ -8,7 +8,7 @@ macro_rules! symbols {
8 8 };
9 9 }
10 10
11 const SYMBOLS: [(&str, &[u8]); 51] = symbols![
11 const SYMBOLS: [(&str, &[u8]); 54] = symbols![
12 12 "bot",
13 13 "done",
14 14 "done_all",
@@ -56,10 +56,13 @@ const SYMBOLS: [(&str, &[u8]); 51] = symbols![
56 56 "call",
57 57 "call_missed",
58 58 "videocam",
59 "radio_button_checked",
60 "stop_circle",
61 "play_arrow",
62 "description",
59 "fluent_video",
60 "fluent_record",
61 "fluent_record_stop",
62 "fluent_cloud_arrow_up",
63 "fluent_share",
64 "fluent_clock",
65 "fluent_document_text",
63 66 ];
64 67
65 68 pub struct AppAssets;
@@ -8,7 +8,7 @@ macro_rules! symbols {
8 };
8 };
9}
9}
10
10
11const SYMBOLS: [(&str, &[u8]); 51] = symbols![
11const SYMBOLS: [(&str, &[u8]); 54] = symbols![
12 "bot",
12 "bot",
13 "done",
13 "done",
14 "done_all",
14 "done_all",
@@ -56,10 +56,13 @@ const SYMBOLS: [(&str, &[u8]); 51] = symbols![
56 "call",
56 "call",
57 "call_missed",
57 "call_missed",
58 "videocam",
58 "videocam",
59 "radio_button_checked",
59 "fluent_video",
60 "stop_circle",
60 "fluent_record",
61 "play_arrow",
61 "fluent_record_stop",
62 "description",
62 "fluent_cloud_arrow_up",
63 "fluent_share",
64 "fluent_clock",
65 "fluent_document_text",
63];
66];
64
67
65pub struct AppAssets;
68pub struct AppAssets;
crates/app-state/src/app_state.rs +1 −1
@@ -63,7 +63,7 @@ pub enum AppEvent {
63 63 Forward,
64 64 ImageViewer,
65 65 StatusMessage,
66 NotificationSettings,
66 Settings(crate::settings_section::SettingsSection),
67 67 Profile,
68 68 Call,
69 69 Ring,
@@ -63,7 +63,7 @@ pub enum AppEvent {
63 Forward,
63 Forward,
64 ImageViewer,
64 ImageViewer,
65 StatusMessage,
65 StatusMessage,
66 NotificationSettings,
66 Settings(crate::settings_section::SettingsSection),
67 Profile,
67 Profile,
68 Call,
68 Call,
69 Ring,
69 Ring,
crates/app-state/src/call_rows.rs +471 −93
@@ -1,9 +1,17 @@
1 1 use std::collections::{HashMap, HashSet};
2 2
3 use chrono::{DateTime, FixedOffset, NaiveDate, Utc};
4 use store::MessageRecord;
3 5 use teams_core::{CallEvent, CallPhase, CallType, ImageRef, format_duration};
4 6
7 use crate::format;
8
5 9 const MAX_AVATARS: usize = 4;
6 const RECORDING_FALLBACK_TITLE: &str = "Meeting recording";
10 const RECAP_FALLBACK_TITLE: &str = "Meeting";
11 const RECAP_DATE_FORMAT: &str = "%A, %-d %B %Y %H:%M";
12 const RECAP_TIME_FORMAT: &str = "%H:%M";
13 const AUTO_STOP_SECONDS: i64 = 5;
14 const WEEKDAY_STAMP_DAYS: i64 = 6;
7 15
8 16 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
9 17 pub enum CallIcon {
@@ -12,6 +20,7 @@ pub enum CallIcon {
12 20 Video,
13 21 Record,
14 22 RecordStop,
23 Saved,
15 24 }
16 25
17 26 #[derive(Debug, Clone, PartialEq, Eq)]
@@ -23,11 +32,27 @@ pub struct CallParticipant {
23 32 #[derive(Debug, Clone, PartialEq, Eq)]
24 33 pub struct RecordingCard {
25 34 pub message_id: String,
26 pub title: String,
27 35 pub duration: Option<String>,
28 36 pub url: Option<String>,
29 37 pub thumbnail: Option<ImageRef>,
30 38 pub transcript: bool,
39 pub expires_in_days: Option<i64>,
40 }
41
42 /// The card Teams puts under the "Meeting ended" line of a meeting with a recording.
43 #[derive(Debug, Clone, PartialEq, Eq)]
44 pub struct RecapCard {
45 pub title: String,
46 pub date_line: String,
47 pub recording: RecordingCard,
48 }
49
50 /// A meeting or recording event as Teams draws it: one muted line, icon in the avatar column.
51 #[derive(Debug, Clone, PartialEq, Eq)]
52 pub struct CallNotice {
53 pub stamp: String,
54 pub text: String,
55 pub emphasis: Option<String>,
31 56 }
32 57
33 58 #[derive(Debug, Clone, PartialEq, Eq)]
@@ -39,7 +64,23 @@ pub struct CallCard {
39 64 pub started: bool,
40 65 pub participants: Vec<CallParticipant>,
41 66 pub extra_participants: usize,
42 pub recording: Option<RecordingCard>,
67 pub notice: Option<CallNotice>,
68 pub recap: Option<RecapCard>,
69 }
70
71 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
72 pub struct MeetingSlot {
73 pub start: DateTime<Utc>,
74 pub end: DateTime<Utc>,
75 }
76
77 /// What the meeting rows need beyond the messages: the chat topic, the calendar occurrences
78 /// and the recording expiry the Recap tab reads, keyed by the saved recording message id.
79 #[derive(Debug, Clone, Default, PartialEq)]
80 pub struct MeetingInfo {
81 pub title: Option<String>,
82 pub slots: Vec<MeetingSlot>,
83 pub expiry_days: HashMap<String, i64>,
43 84 }
44 85
45 86 pub struct CallNames<'a> {
@@ -56,6 +97,17 @@ impl CallNames<'_> {
56 97 }
57 98 }
58 99
100 pub struct CallClock<'a> {
101 pub offset: FixedOffset,
102 pub today: NaiveDate,
103 pub meeting: &'a MeetingInfo,
104 }
105
106 struct SavedRecording {
107 message_id: String,
108 event: CallEvent,
109 }
110
59 111 /// Which call events of a timeline show as rows: Teams keeps one row per recording start and stop,
60 112 /// hides transcript notices and, for calls (not meetings), the start once the call ended.
61 113 pub struct CallTimeline {
@@ -63,10 +115,17 @@ pub struct CallTimeline {
63 115 finished: HashSet<String>,
64 116 transcripts: HashSet<String>,
65 117 newest_open_start: Option<usize>,
118 started_at: HashMap<String, DateTime<Utc>>,
119 ended_at: HashMap<String, DateTime<Utc>>,
120 saved: HashMap<String, SavedRecording>,
66 121 }
67 122
68 123 impl CallTimeline {
69 124 pub fn new(events: &[Option<CallEvent>]) -> Self {
125 Self::with_records(events, &[])
126 }
127
128 pub fn with_records(events: &[Option<CallEvent>], records: &[&MessageRecord]) -> Self {
70 129 let finished: HashSet<String> = events
71 130 .iter()
72 131 .flatten()
@@ -103,11 +162,42 @@ impl CallTimeline {
103 162 event.phase == CallPhase::Started && !finished.contains(&event.call_id)
104 163 })
105 164 });
165 let mut started_at = HashMap::new();
166 let mut ended_at = HashMap::new();
167 let mut saved = HashMap::new();
168 for (event, record) in events.iter().zip(records) {
169 let Some(event) = event else {
170 continue;
171 };
172 match event.phase {
173 CallPhase::Started => {
174 started_at
175 .entry(event.call_id.clone())
176 .or_insert(record.created_at);
177 }
178 CallPhase::Ended => {
179 ended_at.insert(event.call_id.clone(), record.created_at);
180 }
181 CallPhase::RecordingSaved => {
182 saved.insert(
183 event.call_id.clone(),
184 SavedRecording {
185 message_id: record.message_id.clone(),
186 event: event.clone(),
187 },
188 );
189 }
190 _ => {}
191 }
192 }
106 193 CallTimeline {
107 194 hidden,
108 195 finished,
109 196 transcripts,
110 197 newest_open_start,
198 started_at,
199 ended_at,
200 saved,
111 201 }
112 202 }
113 203
@@ -126,6 +216,94 @@ impl CallTimeline {
126 216 pub fn has_transcript(&self, call_id: &str) -> bool {
127 217 self.transcripts.contains(call_id)
128 218 }
219
220 /// A recording that stops with the meeting end has no one who stopped it; Teams then says
221 /// "Recording stopped." instead of naming the recorder.
222 fn stopped_by_meeting_end(&self, event: &CallEvent, created_at: DateTime<Utc>) -> bool {
223 self.ended_at.get(&event.call_id).is_some_and(|ended_at| {
224 (*ended_at - created_at).num_seconds().abs() <= AUTO_STOP_SECONDS
225 })
226 }
227
228 fn recap(
229 &self,
230 ended: &CallEvent,
231 ended_at: DateTime<Utc>,
232 clock: &CallClock,
233 ) -> Option<RecapCard> {
234 if ended.phase != CallPhase::Ended || ended.call_type != CallType::Meeting {
235 return None;
236 }
237 let saved = self.saved.get(&ended.call_id)?;
238 let started_at = self
239 .started_at
240 .get(&ended.call_id)
241 .copied()
242 .or_else(|| {
243 ended
244 .duration_seconds
245 .map(|seconds| ended_at - chrono::Duration::seconds(seconds as i64))
246 })
247 .unwrap_or(ended_at);
248 let recording = recording_card(
249 &saved.event,
250 &saved.message_id,
251 self.has_transcript(&ended.call_id),
252 clock.meeting,
253 )?;
254 let title = clock
255 .meeting
256 .title
257 .clone()
258 .filter(|title| !title.trim().is_empty())
259 .or_else(|| saved.event.recording.as_ref()?.title())
260 .unwrap_or_else(|| RECAP_FALLBACK_TITLE.to_owned());
261 Some(RecapCard {
262 title,
263 date_line: recap_date_line(started_at, ended_at, clock),
264 recording,
265 })
266 }
267 }
268
269 /// Teams dates the recap card with the scheduled occurrence; without a calendar match the call's
270 /// own start and end stand in.
271 fn recap_date_line(
272 started_at: DateTime<Utc>,
273 ended_at: DateTime<Utc>,
274 clock: &CallClock,
275 ) -> String {
276 let slot = clock
277 .meeting
278 .slots
279 .iter()
280 .filter(|slot| slot.start <= ended_at && slot.end >= started_at)
281 .min_by_key(|slot| (slot.start - started_at).num_seconds().abs())
282 .copied()
283 .unwrap_or(MeetingSlot {
284 start: started_at,
285 end: ended_at,
286 });
287 format!(
288 "{} - {}",
289 slot.start
290 .with_timezone(&clock.offset)
291 .format(RECAP_DATE_FORMAT),
292 slot.end
293 .with_timezone(&clock.offset)
294 .format(RECAP_TIME_FORMAT)
295 )
296 }
297
298 /// Teams writes the weekday in full on these lines ("Thursday 11:45"), unlike message times.
299 fn notice_stamp(time: DateTime<Utc>, clock: &CallClock) -> String {
300 let local = time.with_timezone(&clock.offset);
301 let days_ago = (clock.today - local.date_naive()).num_days();
302 if (2..=WEEKDAY_STAMP_DAYS).contains(&days_ago) {
303 local.format("%A %H:%M").to_string()
304 } else {
305 format::post_time_label(time, clock.today, clock.offset)
306 }
129 307 }
130 308
131 309 fn participants(event: &CallEvent, names: &CallNames) -> Vec<CallParticipant> {
@@ -143,13 +321,15 @@ fn participants(event: &CallEvent, names: &CallNames) -> Vec<CallParticipant> {
143 321 .collect()
144 322 }
145 323
146 fn recording_card(event: &CallEvent, message_id: &str, transcript: bool) -> Option<RecordingCard> {
324 fn recording_card(
325 event: &CallEvent,
326 message_id: &str,
327 transcript: bool,
328 meeting: &MeetingInfo,
329 ) -> Option<RecordingCard> {
147 330 let recording = event.recording.as_ref()?;
148 331 Some(RecordingCard {
149 332 message_id: message_id.to_owned(),
150 title: recording
151 .title()
152 .unwrap_or_else(|| RECORDING_FALLBACK_TITLE.to_owned()),
153 333 duration: event
154 334 .duration_seconds
155 335 .filter(|seconds| *seconds > 0)
@@ -163,9 +343,71 @@ fn recording_card(event: &CallEvent, message_id: &str, transcript: bool) -> Opti
163 343 alt: None,
164 344 }),
165 345 transcript,
346 expires_in_days: meeting.expiry_days.get(message_id).copied(),
166 347 })
167 348 }
168 349
350 fn day_count(days: i64) -> String {
351 if days == 1 {
352 "1 day".to_owned()
353 } else {
354 format!("{days} days")
355 }
356 }
357
358 struct NoticeSource<'a> {
359 event: &'a CallEvent,
360 message_id: &'a str,
361 stopped_by_meeting_end: bool,
362 }
363
364 fn notice_text(source: NoticeSource, names: &CallNames, meeting: &MeetingInfo) -> String {
365 let NoticeSource {
366 event,
367 message_id,
368 stopped_by_meeting_end,
369 } = source;
370 let initiator = || {
371 names.name(
372 event.initiator_id.as_deref(),
373 event.initiator_name.as_deref(),
374 )
375 };
376 match event.phase {
377 CallPhase::Ended => format!("{}:", event.title(false)),
378 CallPhase::RecordingStarted => match initiator() {
379 Some(name) => format!("{name} started recording."),
380 None => event.title(false).to_owned(),
381 },
382 CallPhase::RecordingStopped => match initiator().filter(|_| !stopped_by_meeting_end) {
383 Some(name) => format!("{name} stopped recording."),
384 None => format!("{}.", event.title(false)),
385 },
386 CallPhase::RecordingSaved => {
387 let saved = saved_to(event, names);
388 match meeting.expiry_days.get(message_id) {
389 Some(days) => format!("{saved} and will expire in {}.", day_count(*days)),
390 None => format!("{saved}."),
391 }
392 }
393 _ => event.title(false).to_owned(),
394 }
395 }
396
397 fn saved_to(event: &CallEvent, names: &CallNames) -> String {
398 let organizer_id = event
399 .recording
400 .as_ref()
401 .and_then(|recording| recording.organizer_id.as_deref());
402 if organizer_id.is_some() && organizer_id == names.my_user_id {
403 return "Recording has been saved to your OneDrive".to_owned();
404 }
405 match names.name(organizer_id, None) {
406 Some(owner) => format!("Recording has been saved to {owner}'s OneDrive"),
407 None => "Recording has been saved to OneDrive".to_owned(),
408 }
409 }
410
169 411 fn title(event: &CallEvent, missed: bool, names: &CallNames) -> String {
170 412 match event.phase {
171 413 CallPhase::RecordingStarted => {
@@ -177,30 +419,35 @@ fn title(event: &CallEvent, missed: bool, names: &CallNames) -> String {
177 419 None => event.title(false).to_owned(),
178 420 }
179 421 }
180 CallPhase::RecordingSaved => {
181 let organizer_id = event
182 .recording
183 .as_ref()
184 .and_then(|recording| recording.organizer_id.as_deref());
185 if organizer_id.is_some() && organizer_id == names.my_user_id {
186 return "Recording has been saved to your OneDrive".to_owned();
187 }
188 match names.name(organizer_id, None) {
189 Some(owner) => format!("Recording has been saved to {owner}'s OneDrive"),
190 None => "Recording has been saved to OneDrive".to_owned(),
191 }
192 }
422 CallPhase::RecordingSaved => saved_to(event, names),
193 423 _ => event.title(missed).to_owned(),
194 424 }
195 425 }
196 426
427 /// Teams draws meeting and recording events as one-line notices; 1:1 and group calls keep the card.
428 pub fn is_notice(event: &CallEvent) -> bool {
429 event.call_type == CallType::Meeting || event.is_recording()
430 }
431
432 pub struct CallSource<'a> {
433 pub event: &'a CallEvent,
434 pub message_id: &'a str,
435 pub created_at: DateTime<Utc>,
436 pub time: &'a str,
437 }
438
197 439 pub fn call_card(
198 event: &CallEvent,
199 message_id: &str,
200 time: &str,
440 source: CallSource,
201 441 names: &CallNames,
202 transcript: bool,
442 clock: &CallClock,
443 timeline: &CallTimeline,
203 444 ) -> CallCard {
445 let CallSource {
446 event,
447 message_id,
448 created_at,
449 time,
450 } = source;
204 451 let missed = event.missed(names.my_user_id);
205 452 let detail = match (event.phase, event.duration_seconds) {
206 453 (CallPhase::Ended, Some(seconds)) if !missed => {
@@ -215,12 +462,29 @@ pub fn call_card(
215 462 };
216 463 let extra_participants = people.len().saturating_sub(MAX_AVATARS);
217 464 people.truncate(MAX_AVATARS);
465 let notice = is_notice(event).then(|| CallNotice {
466 stamp: notice_stamp(created_at, clock),
467 text: notice_text(
468 NoticeSource {
469 event,
470 message_id,
471 stopped_by_meeting_end: timeline.stopped_by_meeting_end(event, created_at),
472 },
473 names,
474 clock.meeting,
475 ),
476 emphasis: event
477 .duration_seconds
478 .filter(|_| event.phase == CallPhase::Ended)
479 .map(format_duration),
480 });
218 481 CallCard {
219 482 title: title(event, missed, names),
220 483 detail,
221 484 icon: match (missed, event.phase, event.call_type) {
222 485 (true, _, _) => CallIcon::Missed,
223 (false, CallPhase::RecordingStarted | CallPhase::RecordingSaved, _) => CallIcon::Record,
486 (false, CallPhase::RecordingStarted, _) => CallIcon::Record,
487 (false, CallPhase::RecordingSaved, _) => CallIcon::Saved,
224 488 (false, CallPhase::RecordingStopped | CallPhase::TranscriptStarted, _) => {
225 489 CallIcon::RecordStop
226 490 }
@@ -231,14 +495,14 @@ pub fn call_card(
231 495 started: event.phase == CallPhase::Started,
232 496 participants: people,
233 497 extra_participants,
234 recording: (event.phase == CallPhase::RecordingSaved)
235 .then(|| recording_card(event, message_id, transcript))
236 .flatten(),
498 recap: timeline.recap(event, created_at, clock),
499 notice,
237 500 }
238 501 }
239 502
240 503 #[cfg(test)]
241 504 mod tests {
505 use chrono::TimeZone;
242 506 use teams_core::Recording;
243 507
244 508 use super::*;
@@ -257,7 +521,7 @@ mod tests {
257 521 }
258 522 }
259 523
260 fn fixture_events() -> Vec<Option<CallEvent>> {
524 fn fixture_records() -> Vec<MessageRecord> {
261 525 let path = format!(
262 526 "{}/../core/tests/fixtures/call_events/meeting_chat_recording.json",
263 527 env!("CARGO_MANIFEST_DIR")
@@ -269,7 +533,10 @@ mod tests {
269 533 .unwrap()
270 534 .iter()
271 535 .rev()
272 .map(|message| CallEvent::from_graph(&message["eventDetail"]))
536 .map(|message| {
537 let message: graph::Message = serde_json::from_value(message.clone()).unwrap();
538 teams_core::message_record("meeting-chat", &message).unwrap()
539 })
273 540 .collect()
274 541 }
275 542
@@ -286,93 +553,197 @@ mod tests {
286 553 ])
287 554 }
288 555
289 #[test]
290 fn recorded_meeting_shows_like_teams() {
291 let events = fixture_events();
292 let timeline = CallTimeline::new(&events);
556 fn cards(records: &[MessageRecord], meeting: &MeetingInfo) -> Vec<CallCard> {
557 let events: Vec<Option<CallEvent>> = records.iter().map(teams_core::call_event).collect();
558 let timeline = CallTimeline::with_records(&events, &records.iter().collect::<Vec<_>>());
293 559 let names = names();
294 560 let lookup = CallNames {
295 561 my_user_id: Some("me"),
296 562 names: &names,
297 563 };
298 let titles: Vec<String> = events
564 let clock = CallClock {
565 offset: FixedOffset::east_opt(0).unwrap(),
566 today: NaiveDate::from_ymd_opt(2026, 10, 30).unwrap(),
567 meeting,
568 };
569 events
299 570 .iter()
571 .zip(records)
300 572 .enumerate()
301 573 .filter(|(index, _)| !timeline.hides(*index))
302 .map(|(_, event)| {
303 let event = event.as_ref().unwrap();
574 .map(|(_, (event, record))| {
304 575 call_card(
305 event,
306 "m",
307 "16:15",
576 CallSource {
577 event: event.as_ref().unwrap(),
578 message_id: &record.message_id,
579 created_at: record.created_at,
580 time: "16:15",
581 },
308 582 &lookup,
309 timeline.has_transcript(&event.call_id),
583 &clock,
584 &timeline,
310 585 )
311 .title
312 586 })
313 .collect();
587 .collect()
588 }
589
590 fn notice_line(card: &CallCard) -> String {
591 let notice = card.notice.as_ref().unwrap();
592 match &notice.emphasis {
593 Some(emphasis) => format!("{} {emphasis}", notice.text),
594 None => notice.text.clone(),
595 }
596 }
597
598 #[test]
599 fn recorded_meeting_shows_as_teams_notices() {
600 let shown = cards(&fixture_records(), &MeetingInfo::default());
601 let lines: Vec<String> = shown.iter().map(notice_line).collect();
314 602 assert_eq!(
315 titles,
603 lines,
316 604 [
317 605 "Meeting started",
318 "Sam Recorder started recording",
319 "Recording stopped",
320 "Meeting ended",
321 "Recording has been saved to Vera Organizer's OneDrive",
606 "Sam Recorder started recording.",
607 "Recording stopped.",
608 "Meeting ended: 16m 28s",
609 "Recording has been saved to Vera Organizer's OneDrive.",
322 610 ]
323 611 );
612 let icons: Vec<CallIcon> = shown.iter().map(|card| card.icon).collect();
613 assert_eq!(
614 icons,
615 [
616 CallIcon::Video,
617 CallIcon::Record,
618 CallIcon::RecordStop,
619 CallIcon::Video,
620 CallIcon::Saved,
621 ]
622 );
623 assert!(
624 shown
625 .iter()
626 .all(|card| card.recap.is_none() == (card.title != "Meeting ended"))
627 );
324 628 }
325 629
326 630 #[test]
327 fn saved_recording_becomes_a_card_with_transcript_and_thumbnail() {
328 let events = fixture_events();
329 let timeline = CallTimeline::new(&events);
330 let saved = events.last().unwrap().as_ref().unwrap();
331 let names = HashMap::new();
332 let lookup = CallNames {
333 my_user_id: None,
334 names: &names,
631 fn a_recording_stopped_before_the_end_names_who_stopped_it() {
632 let mut records = fixture_records();
633 for record in records.iter_mut() {
634 if teams_core::call_event(record)
635 .is_some_and(|event| event.phase == CallPhase::RecordingStopped)
636 {
637 record.created_at -= chrono::Duration::minutes(2);
638 }
639 }
640 let shown = cards(&records, &MeetingInfo::default());
641 assert_eq!(notice_line(&shown[2]), "Sam Recorder stopped recording.");
642 }
643
644 #[test]
645 fn ended_meeting_carries_the_recap_card_of_its_recording() {
646 let records = fixture_records();
647 let saved_id = records.last().unwrap().message_id.clone();
648 let meeting = MeetingInfo {
649 title: Some("Weekly sync".to_owned()),
650 slots: Vec::new(),
651 expiry_days: HashMap::from([(saved_id.clone(), 56)]),
335 652 };
336 let card = call_card(
337 saved,
338 "saved-1",
339 "16:16",
340 &lookup,
341 timeline.has_transcript(&saved.call_id),
653 let shown = cards(&records, &meeting);
654 let ended = shown
655 .iter()
656 .find(|card| card.title == "Meeting ended")
657 .unwrap();
658 let recap = ended.recap.as_ref().unwrap();
659 assert_eq!(recap.title, "Weekly sync");
660 assert_eq!(recap.recording.message_id, saved_id);
661 assert_eq!(recap.recording.duration.as_deref(), Some("13m 34s"));
662 assert_eq!(recap.recording.expires_in_days, Some(56));
663 assert!(recap.recording.transcript);
664 assert!(
665 recap
666 .recording
667 .thumbnail
668 .as_ref()
669 .unwrap()
670 .url
671 .contains("/thumbnails/")
672 );
673 assert!(shown.iter().filter(|card| card.recap.is_some()).count() == 1);
674 assert_eq!(
675 notice_line(shown.last().unwrap()),
676 "Recording has been saved to Vera Organizer's OneDrive and will expire in 56 days."
342 677 );
343 assert_eq!(card.title, "Recording has been saved to OneDrive");
344 assert_eq!(card.icon, CallIcon::Record);
345 let recording = card.recording.unwrap();
346 assert_eq!(recording.title, "Weekly team meeting");
347 assert_eq!(recording.duration.as_deref(), Some("13m 34s"));
348 assert!(recording.transcript);
349 assert_eq!(recording.message_id, "saved-1");
350 assert!(recording.thumbnail.unwrap().url.contains("/thumbnails/"));
678 }
679
680 #[test]
681 fn recap_date_prefers_the_calendar_occurrence() {
682 let started_at = Utc.with_ymd_and_hms(2026, 10, 15, 9, 46, 0).unwrap();
683 let ended_at = Utc.with_ymd_and_hms(2026, 10, 15, 9, 55, 0).unwrap();
684 let mut meeting = MeetingInfo::default();
685 let clock = |meeting: &MeetingInfo| {
686 recap_date_line(
687 started_at,
688 ended_at,
689 &CallClock {
690 offset: FixedOffset::east_opt(2 * 3600).unwrap(),
691 today: NaiveDate::from_ymd_opt(2026, 10, 17).unwrap(),
692 meeting,
693 },
694 )
695 };
696 assert_eq!(clock(&meeting), "Thursday, 15 October 2026 11:46 - 11:55");
697 meeting.slots = vec![
698 MeetingSlot {
699 start: Utc.with_ymd_and_hms(2026, 10, 14, 9, 45, 0).unwrap(),
700 end: Utc.with_ymd_and_hms(2026, 10, 14, 10, 0, 0).unwrap(),
701 },
702 MeetingSlot {
703 start: Utc.with_ymd_and_hms(2026, 10, 15, 9, 45, 0).unwrap(),
704 end: Utc.with_ymd_and_hms(2026, 10, 15, 10, 0, 0).unwrap(),
705 },
706 ];
707 assert_eq!(clock(&meeting), "Thursday, 15 October 2026 11:45 - 12:00");
708 }
709
710 #[test]
711 fn notice_stamps_spell_out_the_weekday_like_teams() {
712 let meeting = MeetingInfo::default();
713 let clock = CallClock {
714 offset: FixedOffset::east_opt(0).unwrap(),
715 today: NaiveDate::from_ymd_opt(2026, 10, 17).unwrap(),
716 meeting: &meeting,
717 };
718 let stamp = |day: u32| {
719 notice_stamp(
720 Utc.with_ymd_and_hms(2026, 10, day, 11, 45, 0).unwrap(),
721 &clock,
722 )
723 };
724 assert_eq!(stamp(17), "11:45");
725 assert_eq!(stamp(16), "Yesterday 11:45");
726 assert_eq!(stamp(15), "Thursday 11:45");
351 727 }
352 728
353 729 #[test]
354 730 fn ended_meeting_lists_named_participants_up_to_four() {
355 let events = fixture_events();
356 let ended = events
731 let shown = cards(&fixture_records(), &MeetingInfo::default());
732 let ended = shown
357 733 .iter()
358 .flatten()
359 .find(|event| event.phase == CallPhase::Ended)
734 .find(|card| card.title == "Meeting ended")
360 735 .unwrap();
361 let names = HashMap::new();
362 let lookup = CallNames {
363 my_user_id: None,
364 names: &names,
365 };
366 let card = call_card(ended, "m", "16:15", &lookup, false);
367 assert_eq!(card.detail, "16m 28s \u{b7} 16:15");
368 assert_eq!(card.icon, CallIcon::Video);
369 let shown: Vec<&str> = card
736 assert_eq!(ended.detail, "16m 28s \u{b7} 16:15");
737 let shown_names: Vec<&str> = ended
370 738 .participants
371 739 .iter()
372 740 .map(|person| person.name.as_str())
373 741 .collect();
374 assert_eq!(shown, ["Person 1", "Person 2", "Person 3", "Person 4"]);
375 assert_eq!(card.extra_participants, 20);
742 assert_eq!(
743 shown_names,
744 ["Person 1", "Person 2", "Person 3", "Person 4"]
745 );
746 assert_eq!(ended.extra_participants, 20);
376 747 }
377 748
378 749 #[test]
@@ -395,8 +766,9 @@ mod tests {
395 766 }
396 767
397 768 #[test]
398 fn my_own_recording_is_saved_to_my_onedrive() {
399 let mut saved = event(CallPhase::RecordingSaved, CallType::Meeting, "c");
769 fn calls_keep_their_card_and_my_recording_is_in_my_onedrive() {
770 assert!(!is_notice(&event(CallPhase::Ended, CallType::Call, "c")));
771 let mut saved = event(CallPhase::RecordingSaved, CallType::Call, "c");
400 772 saved.recording = Some(Recording {
401 773 name: None,
402 774 url: Some("https://contoso.example/rec.mp4".to_owned()),
@@ -407,11 +779,17 @@ mod tests {
407 779 my_user_id: Some("me"),
408 780 names: &names,
409 781 };
410 let card = call_card(&saved, "m", "9:00", &lookup, false);
411 assert_eq!(card.title, "Recording has been saved to your OneDrive");
412 let recording = card.recording.unwrap();
413 assert_eq!(recording.title, "Meeting recording");
414 assert_eq!(recording.thumbnail, None);
415 assert_eq!(recording.duration, None);
782 assert_eq!(
783 notice_text(
784 NoticeSource {
785 event: &saved,
786 message_id: "m",
787 stopped_by_meeting_end: false,
788 },
789 &lookup,
790 &MeetingInfo::default()
791 ),
792 "Recording has been saved to your OneDrive."
793 );
416 794 }
417 795 }
@@ -1,9 +1,17 @@
1use std::collections::{HashMap, HashSet};
1use std::collections::{HashMap, HashSet};
2
2
3use chrono::{DateTime, FixedOffset, NaiveDate, Utc};
4use store::MessageRecord;
3use teams_core::{CallEvent, CallPhase, CallType, ImageRef, format_duration};
5use teams_core::{CallEvent, CallPhase, CallType, ImageRef, format_duration};
4
6
7use crate::format;
8
5const MAX_AVATARS: usize = 4;
9const MAX_AVATARS: usize = 4;
6const RECORDING_FALLBACK_TITLE: &str = "Meeting recording";
10const RECAP_FALLBACK_TITLE: &str = "Meeting";
11const RECAP_DATE_FORMAT: &str = "%A, %-d %B %Y %H:%M";
12const RECAP_TIME_FORMAT: &str = "%H:%M";
13const AUTO_STOP_SECONDS: i64 = 5;
14const WEEKDAY_STAMP_DAYS: i64 = 6;
7
15
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum CallIcon {
17pub enum CallIcon {
@@ -12,6 +20,7 @@ pub enum CallIcon {
12 Video,
20 Video,
13 Record,
21 Record,
14 RecordStop,
22 RecordStop,
23 Saved,
15}
24}
16
25
17#[derive(Debug, Clone, PartialEq, Eq)]
26#[derive(Debug, Clone, PartialEq, Eq)]
@@ -23,11 +32,27 @@ pub struct CallParticipant {
23#[derive(Debug, Clone, PartialEq, Eq)]
32#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct RecordingCard {
33pub struct RecordingCard {
25 pub message_id: String,
34 pub message_id: String,
26 pub title: String,
27 pub duration: Option<String>,
35 pub duration: Option<String>,
28 pub url: Option<String>,
36 pub url: Option<String>,
29 pub thumbnail: Option<ImageRef>,
37 pub thumbnail: Option<ImageRef>,
30 pub transcript: bool,
38 pub transcript: bool,
39 pub expires_in_days: Option<i64>,
40}
41
42/// The card Teams puts under the "Meeting ended" line of a meeting with a recording.
43#[derive(Debug, Clone, PartialEq, Eq)]
44pub struct RecapCard {
45 pub title: String,
46 pub date_line: String,
47 pub recording: RecordingCard,
48}
49
50/// A meeting or recording event as Teams draws it: one muted line, icon in the avatar column.
51#[derive(Debug, Clone, PartialEq, Eq)]
52pub struct CallNotice {
53 pub stamp: String,
54 pub text: String,
55 pub emphasis: Option<String>,
31}
56}
32
57
33#[derive(Debug, Clone, PartialEq, Eq)]
58#[derive(Debug, Clone, PartialEq, Eq)]
@@ -39,7 +64,23 @@ pub struct CallCard {
39 pub started: bool,
64 pub started: bool,
40 pub participants: Vec<CallParticipant>,
65 pub participants: Vec<CallParticipant>,
41 pub extra_participants: usize,
66 pub extra_participants: usize,
42 pub recording: Option<RecordingCard>,
67 pub notice: Option<CallNotice>,
68 pub recap: Option<RecapCard>,
69}
70
71#[derive(Debug, Clone, Copy, PartialEq, Eq)]
72pub struct MeetingSlot {
73 pub start: DateTime<Utc>,
74 pub end: DateTime<Utc>,
75}
76
77/// What the meeting rows need beyond the messages: the chat topic, the calendar occurrences
78/// and the recording expiry the Recap tab reads, keyed by the saved recording message id.
79#[derive(Debug, Clone, Default, PartialEq)]
80pub struct MeetingInfo {
81 pub title: Option<String>,
82 pub slots: Vec<MeetingSlot>,
83 pub expiry_days: HashMap<String, i64>,
43}
84}
44
85
45pub struct CallNames<'a> {
86pub struct CallNames<'a> {
@@ -56,6 +97,17 @@ impl CallNames<'_> {
56 }
97 }
57}
98}
58
99
100pub struct CallClock<'a> {
101 pub offset: FixedOffset,
102 pub today: NaiveDate,
103 pub meeting: &'a MeetingInfo,
104}
105
106struct SavedRecording {
107 message_id: String,
108 event: CallEvent,
109}
110
59/// Which call events of a timeline show as rows: Teams keeps one row per recording start and stop,
111/// Which call events of a timeline show as rows: Teams keeps one row per recording start and stop,
60/// hides transcript notices and, for calls (not meetings), the start once the call ended.
112/// hides transcript notices and, for calls (not meetings), the start once the call ended.
61pub struct CallTimeline {
113pub struct CallTimeline {
@@ -63,10 +115,17 @@ pub struct CallTimeline {
63 finished: HashSet<String>,
115 finished: HashSet<String>,
64 transcripts: HashSet<String>,
116 transcripts: HashSet<String>,
65 newest_open_start: Option<usize>,
117 newest_open_start: Option<usize>,
118 started_at: HashMap<String, DateTime<Utc>>,
119 ended_at: HashMap<String, DateTime<Utc>>,
120 saved: HashMap<String, SavedRecording>,
66}
121}
67
122
68impl CallTimeline {
123impl CallTimeline {
69 pub fn new(events: &[Option<CallEvent>]) -> Self {
124 pub fn new(events: &[Option<CallEvent>]) -> Self {
125 Self::with_records(events, &[])
126 }
127
128 pub fn with_records(events: &[Option<CallEvent>], records: &[&MessageRecord]) -> Self {
70 let finished: HashSet<String> = events
129 let finished: HashSet<String> = events
71 .iter()
130 .iter()
72 .flatten()
131 .flatten()
@@ -103,11 +162,42 @@ impl CallTimeline {
103 event.phase == CallPhase::Started && !finished.contains(&event.call_id)
162 event.phase == CallPhase::Started && !finished.contains(&event.call_id)
104 })
163 })
105 });
164 });
165 let mut started_at = HashMap::new();
166 let mut ended_at = HashMap::new();
167 let mut saved = HashMap::new();
168 for (event, record) in events.iter().zip(records) {
169 let Some(event) = event else {
170 continue;
171 };
172 match event.phase {
173 CallPhase::Started => {
174 started_at
175 .entry(event.call_id.clone())
176 .or_insert(record.created_at);
177 }
178 CallPhase::Ended => {
179 ended_at.insert(event.call_id.clone(), record.created_at);
180 }
181 CallPhase::RecordingSaved => {
182 saved.insert(
183 event.call_id.clone(),
184 SavedRecording {
185 message_id: record.message_id.clone(),
186 event: event.clone(),
187 },
188 );
189 }
190 _ => {}
191 }
192 }
106 CallTimeline {
193 CallTimeline {
107 hidden,
194 hidden,
108 finished,
195 finished,
109 transcripts,
196 transcripts,
110 newest_open_start,
197 newest_open_start,
198 started_at,
199 ended_at,
200 saved,
111 }
201 }
112 }
202 }
113
203
@@ -126,6 +216,94 @@ impl CallTimeline {
126 pub fn has_transcript(&self, call_id: &str) -> bool {
216 pub fn has_transcript(&self, call_id: &str) -> bool {
127 self.transcripts.contains(call_id)
217 self.transcripts.contains(call_id)
128 }
218 }
219
220 /// A recording that stops with the meeting end has no one who stopped it; Teams then says
221 /// "Recording stopped." instead of naming the recorder.
222 fn stopped_by_meeting_end(&self, event: &CallEvent, created_at: DateTime<Utc>) -> bool {
223 self.ended_at.get(&event.call_id).is_some_and(|ended_at| {
224 (*ended_at - created_at).num_seconds().abs() <= AUTO_STOP_SECONDS
225 })
226 }
227
228 fn recap(
229 &self,
230 ended: &CallEvent,
231 ended_at: DateTime<Utc>,
232 clock: &CallClock,
233 ) -> Option<RecapCard> {
234 if ended.phase != CallPhase::Ended || ended.call_type != CallType::Meeting {
235 return None;
236 }
237 let saved = self.saved.get(&ended.call_id)?;
238 let started_at = self
239 .started_at
240 .get(&ended.call_id)
241 .copied()
242 .or_else(|| {
243 ended
244 .duration_seconds
245 .map(|seconds| ended_at - chrono::Duration::seconds(seconds as i64))
246 })
247 .unwrap_or(ended_at);
248 let recording = recording_card(
249 &saved.event,
250 &saved.message_id,
251 self.has_transcript(&ended.call_id),
252 clock.meeting,
253 )?;
254 let title = clock
255 .meeting
256 .title
257 .clone()
258 .filter(|title| !title.trim().is_empty())
259 .or_else(|| saved.event.recording.as_ref()?.title())
260 .unwrap_or_else(|| RECAP_FALLBACK_TITLE.to_owned());
261 Some(RecapCard {
262 title,
263 date_line: recap_date_line(started_at, ended_at, clock),
264 recording,
265 })
266 }
267}
268
269/// Teams dates the recap card with the scheduled occurrence; without a calendar match the call's
270/// own start and end stand in.
271fn recap_date_line(
272 started_at: DateTime<Utc>,
273 ended_at: DateTime<Utc>,
274 clock: &CallClock,
275) -> String {
276 let slot = clock
277 .meeting
278 .slots
279 .iter()
280 .filter(|slot| slot.start <= ended_at && slot.end >= started_at)
281 .min_by_key(|slot| (slot.start - started_at).num_seconds().abs())
282 .copied()
283 .unwrap_or(MeetingSlot {
284 start: started_at,
285 end: ended_at,
286 });
287 format!(
288 "{} - {}",
289 slot.start
290 .with_timezone(&clock.offset)
291 .format(RECAP_DATE_FORMAT),
292 slot.end
293 .with_timezone(&clock.offset)
294 .format(RECAP_TIME_FORMAT)
295 )
296}
297
298/// Teams writes the weekday in full on these lines ("Thursday 11:45"), unlike message times.
299fn notice_stamp(time: DateTime<Utc>, clock: &CallClock) -> String {
300 let local = time.with_timezone(&clock.offset);
301 let days_ago = (clock.today - local.date_naive()).num_days();
302 if (2..=WEEKDAY_STAMP_DAYS).contains(&days_ago) {
303 local.format("%A %H:%M").to_string()
304 } else {
305 format::post_time_label(time, clock.today, clock.offset)
306 }
129}
307}
130
308
131fn participants(event: &CallEvent, names: &CallNames) -> Vec<CallParticipant> {
309fn participants(event: &CallEvent, names: &CallNames) -> Vec<CallParticipant> {
@@ -143,13 +321,15 @@ fn participants(event: &CallEvent, names: &CallNames) -> Vec<CallParticipant> {
143 .collect()
321 .collect()
144}
322}
145
323
146fn recording_card(event: &CallEvent, message_id: &str, transcript: bool) -> Option<RecordingCard> {
324fn recording_card(
325 event: &CallEvent,
326 message_id: &str,
327 transcript: bool,
328 meeting: &MeetingInfo,
329) -> Option<RecordingCard> {
147 let recording = event.recording.as_ref()?;
330 let recording = event.recording.as_ref()?;
148 Some(RecordingCard {
331 Some(RecordingCard {
149 message_id: message_id.to_owned(),
332 message_id: message_id.to_owned(),
150 title: recording
151 .title()
152 .unwrap_or_else(|| RECORDING_FALLBACK_TITLE.to_owned()),
153 duration: event
333 duration: event
154 .duration_seconds
334 .duration_seconds
155 .filter(|seconds| *seconds > 0)
335 .filter(|seconds| *seconds > 0)
@@ -163,9 +343,71 @@ fn recording_card(event: &CallEvent, message_id: &str, transcript: bool) -> Opti
163 alt: None,
343 alt: None,
164 }),
344 }),
165 transcript,
345 transcript,
346 expires_in_days: meeting.expiry_days.get(message_id).copied(),
166 })
347 })
167}
348}
168
349
350fn day_count(days: i64) -> String {
351 if days == 1 {
352 "1 day".to_owned()
353 } else {
354 format!("{days} days")
355 }
356}
357
358struct NoticeSource<'a> {
359 event: &'a CallEvent,
360 message_id: &'a str,
361 stopped_by_meeting_end: bool,
362}
363
364fn notice_text(source: NoticeSource, names: &CallNames, meeting: &MeetingInfo) -> String {
365 let NoticeSource {
366 event,
367 message_id,
368 stopped_by_meeting_end,
369 } = source;
370 let initiator = || {
371 names.name(
372 event.initiator_id.as_deref(),
373 event.initiator_name.as_deref(),
374 )
375 };
376 match event.phase {
377 CallPhase::Ended => format!("{}:", event.title(false)),
378 CallPhase::RecordingStarted => match initiator() {
379 Some(name) => format!("{name} started recording."),
380 None => event.title(false).to_owned(),
381 },
382 CallPhase::RecordingStopped => match initiator().filter(|_| !stopped_by_meeting_end) {
383 Some(name) => format!("{name} stopped recording."),
384 None => format!("{}.", event.title(false)),
385 },
386 CallPhase::RecordingSaved => {
387 let saved = saved_to(event, names);
388 match meeting.expiry_days.get(message_id) {
389 Some(days) => format!("{saved} and will expire in {}.", day_count(*days)),
390 None => format!("{saved}."),
391 }
392 }
393 _ => event.title(false).to_owned(),
394 }
395}
396
397fn saved_to(event: &CallEvent, names: &CallNames) -> String {
398 let organizer_id = event
399 .recording
400 .as_ref()
401 .and_then(|recording| recording.organizer_id.as_deref());
402 if organizer_id.is_some() && organizer_id == names.my_user_id {
403 return "Recording has been saved to your OneDrive".to_owned();
404 }
405 match names.name(organizer_id, None) {
406 Some(owner) => format!("Recording has been saved to {owner}'s OneDrive"),
407 None => "Recording has been saved to OneDrive".to_owned(),
408 }
409}
410
169fn title(event: &CallEvent, missed: bool, names: &CallNames) -> String {
411fn title(event: &CallEvent, missed: bool, names: &CallNames) -> String {
170 match event.phase {
412 match event.phase {
171 CallPhase::RecordingStarted => {
413 CallPhase::RecordingStarted => {
@@ -177,30 +419,35 @@ fn title(event: &CallEvent, missed: bool, names: &CallNames) -> String {
177 None => event.title(false).to_owned(),
419 None => event.title(false).to_owned(),
178 }
420 }
179 }
421 }
180 CallPhase::RecordingSaved => {
422 CallPhase::RecordingSaved => saved_to(event, names),
181 let organizer_id = event
182 .recording
183 .as_ref()
184 .and_then(|recording| recording.organizer_id.as_deref());
185 if organizer_id.is_some() && organizer_id == names.my_user_id {
186 return "Recording has been saved to your OneDrive".to_owned();
187 }
188 match names.name(organizer_id, None) {
189 Some(owner) => format!("Recording has been saved to {owner}'s OneDrive"),
190 None => "Recording has been saved to OneDrive".to_owned(),
191 }
192 }
193 _ => event.title(missed).to_owned(),
423 _ => event.title(missed).to_owned(),
194 }
424 }
195}
425}
196
426
427/// Teams draws meeting and recording events as one-line notices; 1:1 and group calls keep the card.
428pub fn is_notice(event: &CallEvent) -> bool {
429 event.call_type == CallType::Meeting || event.is_recording()
430}
431
432pub struct CallSource<'a> {
433 pub event: &'a CallEvent,
434 pub message_id: &'a str,
435 pub created_at: DateTime<Utc>,
436 pub time: &'a str,
437}
438
197pub fn call_card(
439pub fn call_card(
198 event: &CallEvent,
440 source: CallSource,
199 message_id: &str,
200 time: &str,
201 names: &CallNames,
441 names: &CallNames,
202 transcript: bool,
442 clock: &CallClock,
443 timeline: &CallTimeline,
203) -> CallCard {
444) -> CallCard {
445 let CallSource {
446 event,
447 message_id,
448 created_at,
449 time,
450 } = source;
204 let missed = event.missed(names.my_user_id);
451 let missed = event.missed(names.my_user_id);
205 let detail = match (event.phase, event.duration_seconds) {
452 let detail = match (event.phase, event.duration_seconds) {
206 (CallPhase::Ended, Some(seconds)) if !missed => {
453 (CallPhase::Ended, Some(seconds)) if !missed => {
@@ -215,12 +462,29 @@ pub fn call_card(
215 };
462 };
216 let extra_participants = people.len().saturating_sub(MAX_AVATARS);
463 let extra_participants = people.len().saturating_sub(MAX_AVATARS);
217 people.truncate(MAX_AVATARS);
464 people.truncate(MAX_AVATARS);
465 let notice = is_notice(event).then(|| CallNotice {
466 stamp: notice_stamp(created_at, clock),
467 text: notice_text(
468 NoticeSource {
469 event,
470 message_id,
471 stopped_by_meeting_end: timeline.stopped_by_meeting_end(event, created_at),
472 },
473 names,
474 clock.meeting,
475 ),
476 emphasis: event
477 .duration_seconds
478 .filter(|_| event.phase == CallPhase::Ended)
479 .map(format_duration),
480 });
218 CallCard {
481 CallCard {
219 title: title(event, missed, names),
482 title: title(event, missed, names),
220 detail,
483 detail,
221 icon: match (missed, event.phase, event.call_type) {
484 icon: match (missed, event.phase, event.call_type) {
222 (true, _, _) => CallIcon::Missed,
485 (true, _, _) => CallIcon::Missed,
223 (false, CallPhase::RecordingStarted | CallPhase::RecordingSaved, _) => CallIcon::Record,
486 (false, CallPhase::RecordingStarted, _) => CallIcon::Record,
487 (false, CallPhase::RecordingSaved, _) => CallIcon::Saved,
224 (false, CallPhase::RecordingStopped | CallPhase::TranscriptStarted, _) => {
488 (false, CallPhase::RecordingStopped | CallPhase::TranscriptStarted, _) => {
225 CallIcon::RecordStop
489 CallIcon::RecordStop
226 }
490 }
@@ -231,14 +495,14 @@ pub fn call_card(
231 started: event.phase == CallPhase::Started,
495 started: event.phase == CallPhase::Started,
232 participants: people,
496 participants: people,
233 extra_participants,
497 extra_participants,
234 recording: (event.phase == CallPhase::RecordingSaved)
498 recap: timeline.recap(event, created_at, clock),
235 .then(|| recording_card(event, message_id, transcript))
499 notice,
236 .flatten(),
237 }
500 }
238}
501}
239
502
240#[cfg(test)]
503#[cfg(test)]
241mod tests {
504mod tests {
505 use chrono::TimeZone;
242 use teams_core::Recording;
506 use teams_core::Recording;
243
507
244 use super::*;
508 use super::*;
@@ -257,7 +521,7 @@ mod tests {
257 }
521 }
258 }
522 }
259
523
260 fn fixture_events() -> Vec<Option<CallEvent>> {
524 fn fixture_records() -> Vec<MessageRecord> {
261 let path = format!(
525 let path = format!(
262 "{}/../core/tests/fixtures/call_events/meeting_chat_recording.json",
526 "{}/../core/tests/fixtures/call_events/meeting_chat_recording.json",
263 env!("CARGO_MANIFEST_DIR")
527 env!("CARGO_MANIFEST_DIR")
@@ -269,7 +533,10 @@ mod tests {
269 .unwrap()
533 .unwrap()
270 .iter()
534 .iter()
271 .rev()
535 .rev()
272 .map(|message| CallEvent::from_graph(&message["eventDetail"]))
536 .map(|message| {
537 let message: graph::Message = serde_json::from_value(message.clone()).unwrap();
538 teams_core::message_record("meeting-chat", &message).unwrap()
539 })
273 .collect()
540 .collect()
274 }
541 }
275
542
@@ -286,93 +553,197 @@ mod tests {
286 ])
553 ])
287 }
554 }
288
555
289 #[test]
556 fn cards(records: &[MessageRecord], meeting: &MeetingInfo) -> Vec<CallCard> {
290 fn recorded_meeting_shows_like_teams() {
557 let events: Vec<Option<CallEvent>> = records.iter().map(teams_core::call_event).collect();
291 let events = fixture_events();
558 let timeline = CallTimeline::with_records(&events, &records.iter().collect::<Vec<_>>());
292 let timeline = CallTimeline::new(&events);
293 let names = names();
559 let names = names();
294 let lookup = CallNames {
560 let lookup = CallNames {
295 my_user_id: Some("me"),
561 my_user_id: Some("me"),
296 names: &names,
562 names: &names,
297 };
563 };
298 let titles: Vec<String> = events
564 let clock = CallClock {
565 offset: FixedOffset::east_opt(0).unwrap(),
566 today: NaiveDate::from_ymd_opt(2026, 10, 30).unwrap(),
567 meeting,
568 };
569 events
299 .iter()
570 .iter()
571 .zip(records)
300 .enumerate()
572 .enumerate()
301 .filter(|(index, _)| !timeline.hides(*index))
573 .filter(|(index, _)| !timeline.hides(*index))
302 .map(|(_, event)| {
574 .map(|(_, (event, record))| {
303 let event = event.as_ref().unwrap();
304 call_card(
575 call_card(
305 event,
576 CallSource {
306 "m",
577 event: event.as_ref().unwrap(),
307 "16:15",
578 message_id: &record.message_id,
579 created_at: record.created_at,
580 time: "16:15",
581 },
308 &lookup,
582 &lookup,
309 timeline.has_transcript(&event.call_id),
583 &clock,
584 &timeline,
310 )
585 )
311 .title
312 })
586 })
313 .collect();
587 .collect()
588 }
589
590 fn notice_line(card: &CallCard) -> String {
591 let notice = card.notice.as_ref().unwrap();
592 match &notice.emphasis {
593 Some(emphasis) => format!("{} {emphasis}", notice.text),
594 None => notice.text.clone(),
595 }
596 }
597
598 #[test]
599 fn recorded_meeting_shows_as_teams_notices() {
600 let shown = cards(&fixture_records(), &MeetingInfo::default());
601 let lines: Vec<String> = shown.iter().map(notice_line).collect();
314 assert_eq!(
602 assert_eq!(
315 titles,
603 lines,
316 [
604 [
317 "Meeting started",
605 "Meeting started",
318 "Sam Recorder started recording",
606 "Sam Recorder started recording.",
319 "Recording stopped",
607 "Recording stopped.",
320 "Meeting ended",
608 "Meeting ended: 16m 28s",
321 "Recording has been saved to Vera Organizer's OneDrive",
609 "Recording has been saved to Vera Organizer's OneDrive.",
322 ]
610 ]
323 );
611 );
612 let icons: Vec<CallIcon> = shown.iter().map(|card| card.icon).collect();
613 assert_eq!(
614 icons,
615 [
616 CallIcon::Video,
617 CallIcon::Record,
618 CallIcon::RecordStop,
619 CallIcon::Video,
620 CallIcon::Saved,
621 ]
622 );
623 assert!(
624 shown
625 .iter()
626 .all(|card| card.recap.is_none() == (card.title != "Meeting ended"))
627 );
324 }
628 }
325
629
326 #[test]
630 #[test]
327 fn saved_recording_becomes_a_card_with_transcript_and_thumbnail() {
631 fn a_recording_stopped_before_the_end_names_who_stopped_it() {
328 let events = fixture_events();
632 let mut records = fixture_records();
329 let timeline = CallTimeline::new(&events);
633 for record in records.iter_mut() {
330 let saved = events.last().unwrap().as_ref().unwrap();
634 if teams_core::call_event(record)
331 let names = HashMap::new();
635 .is_some_and(|event| event.phase == CallPhase::RecordingStopped)
332 let lookup = CallNames {
636 {
333 my_user_id: None,
637 record.created_at -= chrono::Duration::minutes(2);
334 names: &names,
638 }
639 }
640 let shown = cards(&records, &MeetingInfo::default());
641 assert_eq!(notice_line(&shown[2]), "Sam Recorder stopped recording.");
642 }
643
644 #[test]
645 fn ended_meeting_carries_the_recap_card_of_its_recording() {
646 let records = fixture_records();
647 let saved_id = records.last().unwrap().message_id.clone();
648 let meeting = MeetingInfo {
649 title: Some("Weekly sync".to_owned()),
650 slots: Vec::new(),
651 expiry_days: HashMap::from([(saved_id.clone(), 56)]),
335 };
652 };
336 let card = call_card(
653 let shown = cards(&records, &meeting);
337 saved,
654 let ended = shown
338 "saved-1",
655 .iter()
339 "16:16",
656 .find(|card| card.title == "Meeting ended")
340 &lookup,
657 .unwrap();
341 timeline.has_transcript(&saved.call_id),
658 let recap = ended.recap.as_ref().unwrap();
659 assert_eq!(recap.title, "Weekly sync");
660 assert_eq!(recap.recording.message_id, saved_id);
661 assert_eq!(recap.recording.duration.as_deref(), Some("13m 34s"));
662 assert_eq!(recap.recording.expires_in_days, Some(56));
663 assert!(recap.recording.transcript);
664 assert!(
665 recap
666 .recording
667 .thumbnail
668 .as_ref()
669 .unwrap()
670 .url
671 .contains("/thumbnails/")
672 );
673 assert!(shown.iter().filter(|card| card.recap.is_some()).count() == 1);
674 assert_eq!(
675 notice_line(shown.last().unwrap()),
676 "Recording has been saved to Vera Organizer's OneDrive and will expire in 56 days."
342 );
677 );
343 assert_eq!(card.title, "Recording has been saved to OneDrive");
678 }
344 assert_eq!(card.icon, CallIcon::Record);
679
345 let recording = card.recording.unwrap();
680 #[test]
346 assert_eq!(recording.title, "Weekly team meeting");
681 fn recap_date_prefers_the_calendar_occurrence() {
347 assert_eq!(recording.duration.as_deref(), Some("13m 34s"));
682 let started_at = Utc.with_ymd_and_hms(2026, 10, 15, 9, 46, 0).unwrap();
348 assert!(recording.transcript);
683 let ended_at = Utc.with_ymd_and_hms(2026, 10, 15, 9, 55, 0).unwrap();
349 assert_eq!(recording.message_id, "saved-1");
684 let mut meeting = MeetingInfo::default();
350 assert!(recording.thumbnail.unwrap().url.contains("/thumbnails/"));
685 let clock = |meeting: &MeetingInfo| {
686 recap_date_line(
687 started_at,
688 ended_at,
689 &CallClock {
690 offset: FixedOffset::east_opt(2 * 3600).unwrap(),
691 today: NaiveDate::from_ymd_opt(2026, 10, 17).unwrap(),
692 meeting,
693 },
694 )
695 };
696 assert_eq!(clock(&meeting), "Thursday, 15 October 2026 11:46 - 11:55");
697 meeting.slots = vec![
698 MeetingSlot {
699 start: Utc.with_ymd_and_hms(2026, 10, 14, 9, 45, 0).unwrap(),
700 end: Utc.with_ymd_and_hms(2026, 10, 14, 10, 0, 0).unwrap(),
701 },
702 MeetingSlot {
703 start: Utc.with_ymd_and_hms(2026, 10, 15, 9, 45, 0).unwrap(),
704 end: Utc.with_ymd_and_hms(2026, 10, 15, 10, 0, 0).unwrap(),
705 },
706 ];
707 assert_eq!(clock(&meeting), "Thursday, 15 October 2026 11:45 - 12:00");
708 }
709
710 #[test]
711 fn notice_stamps_spell_out_the_weekday_like_teams() {
712 let meeting = MeetingInfo::default();
713 let clock = CallClock {
714 offset: FixedOffset::east_opt(0).unwrap(),
715 today: NaiveDate::from_ymd_opt(2026, 10, 17).unwrap(),
716 meeting: &meeting,
717 };
718 let stamp = |day: u32| {
719 notice_stamp(
720 Utc.with_ymd_and_hms(2026, 10, day, 11, 45, 0).unwrap(),
721 &clock,
722 )
723 };
724 assert_eq!(stamp(17), "11:45");
725 assert_eq!(stamp(16), "Yesterday 11:45");
726 assert_eq!(stamp(15), "Thursday 11:45");
351 }
727 }
352
728
353 #[test]
729 #[test]
354 fn ended_meeting_lists_named_participants_up_to_four() {
730 fn ended_meeting_lists_named_participants_up_to_four() {
355 let events = fixture_events();
731 let shown = cards(&fixture_records(), &MeetingInfo::default());
356 let ended = events
732 let ended = shown
357 .iter()
733 .iter()
358 .flatten()
734 .find(|card| card.title == "Meeting ended")
359 .find(|event| event.phase == CallPhase::Ended)
360 .unwrap();
735 .unwrap();
361 let names = HashMap::new();
736 assert_eq!(ended.detail, "16m 28s \u{b7} 16:15");
362 let lookup = CallNames {
737 let shown_names: Vec<&str> = ended
363 my_user_id: None,
364 names: &names,
365 };
366 let card = call_card(ended, "m", "16:15", &lookup, false);
367 assert_eq!(card.detail, "16m 28s \u{b7} 16:15");
368 assert_eq!(card.icon, CallIcon::Video);
369 let shown: Vec<&str> = card
370 .participants
738 .participants
371 .iter()
739 .iter()
372 .map(|person| person.name.as_str())
740 .map(|person| person.name.as_str())
373 .collect();
741 .collect();
374 assert_eq!(shown, ["Person 1", "Person 2", "Person 3", "Person 4"]);
742 assert_eq!(
375 assert_eq!(card.extra_participants, 20);
743 shown_names,
744 ["Person 1", "Person 2", "Person 3", "Person 4"]
745 );
746 assert_eq!(ended.extra_participants, 20);
376 }
747 }
377
748
378 #[test]
749 #[test]
@@ -395,8 +766,9 @@ mod tests {
395 }
766 }
396
767
397 #[test]
768 #[test]
398 fn my_own_recording_is_saved_to_my_onedrive() {
769 fn calls_keep_their_card_and_my_recording_is_in_my_onedrive() {
399 let mut saved = event(CallPhase::RecordingSaved, CallType::Meeting, "c");
770 assert!(!is_notice(&event(CallPhase::Ended, CallType::Call, "c")));
771 let mut saved = event(CallPhase::RecordingSaved, CallType::Call, "c");
400 saved.recording = Some(Recording {
772 saved.recording = Some(Recording {
401 name: None,
773 name: None,
402 url: Some("https://contoso.example/rec.mp4".to_owned()),
774 url: Some("https://contoso.example/rec.mp4".to_owned()),
@@ -407,11 +779,17 @@ mod tests {
407 my_user_id: Some("me"),
779 my_user_id: Some("me"),
408 names: &names,
780 names: &names,
409 };
781 };
410 let card = call_card(&saved, "m", "9:00", &lookup, false);
782 assert_eq!(
411 assert_eq!(card.title, "Recording has been saved to your OneDrive");
783 notice_text(
412 let recording = card.recording.unwrap();
784 NoticeSource {
413 assert_eq!(recording.title, "Meeting recording");
785 event: &saved,
414 assert_eq!(recording.thumbnail, None);
786 message_id: "m",
415 assert_eq!(recording.duration, None);
787 stopped_by_meeting_end: false,
788 },
789 &lookup,
790 &MeetingInfo::default()
791 ),
792 "Recording has been saved to your OneDrive."
793 );
416 }
794 }
417}
795}
crates/app-state/src/demo_meetings.rs +36 −37
@@ -158,64 +158,63 @@ fn channel_meeting() -> Vec<MessageRecord> {
158 158 ]
159 159 }
160 160
161 fn standup_line(id: &str, time: DateTime<Utc>, event: CallEvent) -> MessageRecord {
162 record(DEMO_RECAP_CHAT, id, None, time, event)
163 }
164
161 165 fn recorded_standup() -> Vec<MessageRecord> {
162 let start = at(1, 9, 0);
166 let start = at(2, 11, 45);
163 167 let minutes = |count: i64| start + Duration::minutes(count);
164 let name = "Daily standup-1-Meeting Recording.mp4";
168 let name = "Daily standup-20261015_114602-Meeting Recording.mp4";
165 169 let url = format!("{DEMO_RECORDING_URL}/standup-1.mp4");
166 170 let people = [
167 171 (JONAS_ID, "Jonas Ortega"),
168 172 (DEMO_USER_ID, "Dana Demo"),
169 173 (MARA_ID, "Mara Lindqvist"),
170 174 ];
171 let line = |id: &str, offset: i64, event: CallEvent| {
172 record(DEMO_RECAP_CHAT, id, None, minutes(offset), event)
175 let saved_recording = |phase: CallPhase, seconds: Option<u64>, url: Option<&str>| {
176 recording(
177 event(phase, STANDUP_CALL, DEMO_USER_ID, seconds),
178 name,
179 url,
180 MARA_ID,
181 )
173 182 };
174 183 vec![
175 line(
184 standup_line(
176 185 "standup-1-start",
177 0,
186 start,
178 187 event(CallPhase::Started, STANDUP_CALL, JONAS_ID, None),
179 188 ),
180 line(
189 standup_line(
181 190 "standup-1-rec",
182 1,
183 recording(
184 event(CallPhase::RecordingStarted, STANDUP_CALL, JONAS_ID, Some(0)),
185 name,
186 None,
191 minutes(1),
192 saved_recording(CallPhase::RecordingStarted, Some(0), None),
193 ),
194 standup_line(
195 "standup-1-transcript",
196 minutes(1),
197 event(
198 CallPhase::TranscriptStarted,
199 STANDUP_CALL,
187 200 DEMO_USER_ID,
201 None,
188 202 ),
189 203 ),
190 line(
204 standup_line(
191 205 "standup-1-stop",
192 17,
193 recording(
194 event(
195 CallPhase::RecordingStopped,
196 STANDUP_CALL,
197 JONAS_ID,
198 Some(985),
199 ),
200 name,
201 None,
202 DEMO_USER_ID,
203 ),
206 minutes(10),
207 saved_recording(CallPhase::RecordingStopped, Some(531), None),
204 208 ),
205 line(
209 standup_line(
206 210 "standup-1-end",
207 18,
208 ended(STANDUP_CALL, JONAS_ID, 1080, &people),
211 minutes(10) + Duration::seconds(40),
212 ended(STANDUP_CALL, JONAS_ID, 586, &people),
209 213 ),
210 line(
211 "demo-recap-1",
212 19,
213 recording(
214 event(CallPhase::RecordingSaved, STANDUP_CALL, JONAS_ID, Some(985)),
215 name,
216 Some(&url),
217 DEMO_USER_ID,
218 ),
214 standup_line(
215 "demo-recap-0",
216 minutes(10) + Duration::seconds(55),
217 saved_recording(CallPhase::RecordingSaved, Some(531), Some(&url)),
219 218 ),
220 219 ]
221 220 }
@@ -158,64 +158,63 @@ fn channel_meeting() -> Vec<MessageRecord> {
158 ]
158 ]
159}
159}
160
160
161fn standup_line(id: &str, time: DateTime<Utc>, event: CallEvent) -> MessageRecord {
162 record(DEMO_RECAP_CHAT, id, None, time, event)
163}
164
161fn recorded_standup() -> Vec<MessageRecord> {
165fn recorded_standup() -> Vec<MessageRecord> {
162 let start = at(1, 9, 0);
166 let start = at(2, 11, 45);
163 let minutes = |count: i64| start + Duration::minutes(count);
167 let minutes = |count: i64| start + Duration::minutes(count);
164 let name = "Daily standup-1-Meeting Recording.mp4";
168 let name = "Daily standup-20261015_114602-Meeting Recording.mp4";
165 let url = format!("{DEMO_RECORDING_URL}/standup-1.mp4");
169 let url = format!("{DEMO_RECORDING_URL}/standup-1.mp4");
166 let people = [
170 let people = [
167 (JONAS_ID, "Jonas Ortega"),
171 (JONAS_ID, "Jonas Ortega"),
168 (DEMO_USER_ID, "Dana Demo"),
172 (DEMO_USER_ID, "Dana Demo"),
169 (MARA_ID, "Mara Lindqvist"),
173 (MARA_ID, "Mara Lindqvist"),
170 ];
174 ];
171 let line = |id: &str, offset: i64, event: CallEvent| {
175 let saved_recording = |phase: CallPhase, seconds: Option<u64>, url: Option<&str>| {
172 record(DEMO_RECAP_CHAT, id, None, minutes(offset), event)
176 recording(
177 event(phase, STANDUP_CALL, DEMO_USER_ID, seconds),
178 name,
179 url,
180 MARA_ID,
181 )
173 };
182 };
174 vec![
183 vec![
175 line(
184 standup_line(
176 "standup-1-start",
185 "standup-1-start",
177 0,
186 start,
178 event(CallPhase::Started, STANDUP_CALL, JONAS_ID, None),
187 event(CallPhase::Started, STANDUP_CALL, JONAS_ID, None),
179 ),
188 ),
180 line(
189 standup_line(
181 "standup-1-rec",
190 "standup-1-rec",
182 1,
191 minutes(1),
183 recording(
192 saved_recording(CallPhase::RecordingStarted, Some(0), None),
184 event(CallPhase::RecordingStarted, STANDUP_CALL, JONAS_ID, Some(0)),
193 ),
185 name,
194 standup_line(
186 None,
195 "standup-1-transcript",
196 minutes(1),
197 event(
198 CallPhase::TranscriptStarted,
199 STANDUP_CALL,
187 DEMO_USER_ID,
200 DEMO_USER_ID,
201 None,
188 ),
202 ),
189 ),
203 ),
190 line(
204 standup_line(
191 "standup-1-stop",
205 "standup-1-stop",
192 17,
206 minutes(10),
193 recording(
207 saved_recording(CallPhase::RecordingStopped, Some(531), None),
194 event(
195 CallPhase::RecordingStopped,
196 STANDUP_CALL,
197 JONAS_ID,
198 Some(985),
199 ),
200 name,
201 None,
202 DEMO_USER_ID,
203 ),
204 ),
208 ),
205 line(
209 standup_line(
206 "standup-1-end",
210 "standup-1-end",
207 18,
211 minutes(10) + Duration::seconds(40),
208 ended(STANDUP_CALL, JONAS_ID, 1080, &people),
212 ended(STANDUP_CALL, JONAS_ID, 586, &people),
209 ),
213 ),
210 line(
214 standup_line(
211 "demo-recap-1",
215 "demo-recap-0",
212 19,
216 minutes(10) + Duration::seconds(55),
213 recording(
217 saved_recording(CallPhase::RecordingSaved, Some(531), Some(&url)),
214 event(CallPhase::RecordingSaved, STANDUP_CALL, JONAS_ID, Some(985)),
215 name,
216 Some(&url),
217 DEMO_USER_ID,
218 ),
219 ),
218 ),
220 ]
219 ]
221}
220}
crates/app-state/src/lib.rs +1 −0
@@ -34,6 +34,7 @@ pub mod rows;
34 34 pub mod scheduled;
35 35 pub mod scheduled_rows;
36 36 pub mod section_actions;
37 pub mod settings_section;
37 38 pub mod sidebar_model;
38 39 pub mod sound_actions;
39 40 pub mod stored_outgoing;
@@ -34,6 +34,7 @@ pub mod rows;
34pub mod scheduled;
34pub mod scheduled;
35pub mod scheduled_rows;
35pub mod scheduled_rows;
36pub mod section_actions;
36pub mod section_actions;
37pub mod settings_section;
37pub mod sidebar_model;
38pub mod sidebar_model;
38pub mod sound_actions;
39pub mod sound_actions;
39pub mod stored_outgoing;
40pub mod stored_outgoing;
crates/app-state/src/own_status.rs +0 −4
@@ -298,10 +298,6 @@ impl AppState {
298 298 std::mem::take(&mut self.status_message_request)
299 299 }
300 300
301 pub fn open_notification_settings(&mut self, cx: &mut Context<Self>) {
302 cx.emit(AppEvent::NotificationSettings);
303 }
304
305 301 pub fn refresh_own_status(&mut self, cx: &mut Context<Self>) {
306 302 let Some(engine) = self.engine.clone().filter(|_| !self.mode.demo) else {
307 303 return;
@@ -298,10 +298,6 @@ impl AppState {
298 std::mem::take(&mut self.status_message_request)
298 std::mem::take(&mut self.status_message_request)
299 }
299 }
300
300
301 pub fn open_notification_settings(&mut self, cx: &mut Context<Self>) {
302 cx.emit(AppEvent::NotificationSettings);
303 }
304
305 pub fn refresh_own_status(&mut self, cx: &mut Context<Self>) {
301 pub fn refresh_own_status(&mut self, cx: &mut Context<Self>) {
306 let Some(engine) = self.engine.clone().filter(|_| !self.mode.demo) else {
302 let Some(engine) = self.engine.clone().filter(|_| !self.mode.demo) else {
307 return;
303 return;
crates/app-state/src/rows.rs +32 −29
@@ -14,8 +14,11 @@ use teams_core::{
14 14 reactions, readable_text, translated_spans,
15 15 };
16 16
17 pub use crate::call_rows::{CallCard, CallIcon, CallParticipant, RecordingCard};
18 use crate::call_rows::{CallNames, CallTimeline, call_card};
17 pub use crate::call_rows::{
18 CallCard, CallIcon, CallNotice, CallParticipant, MeetingInfo, MeetingSlot, RecapCard,
19 RecordingCard,
20 };
21 use crate::call_rows::{CallClock, CallNames, CallSource, CallTimeline, call_card};
19 22 use crate::card_state::CardOverride;
20 23 use crate::format;
21 24 use crate::reaction_model::{Reactor, UNKNOWN_REACTOR};
@@ -563,6 +566,7 @@ pub struct RowContext {
563 566 pub card_overrides: HashMap<String, CardOverride>,
564 567 pub translation: TranslationContext,
565 568 pub skin_tone: u8,
569 pub meeting: MeetingInfo,
566 570 }
567 571
568 572 fn visible_reactions(record: &MessageRecord, context: &RowContext) -> Vec<ReactionInfo> {
@@ -580,7 +584,7 @@ fn call_row(
580 584 record: &MessageRecord,
581 585 event: &CallEvent,
582 586 context: &RowContext,
583 transcript: bool,
587 timeline: &CallTimeline,
584 588 ) -> MessageRow {
585 589 let my_user_id = context.my_user_id.as_deref();
586 590 let time = clock_label(record.created_at, context.offset);
@@ -633,11 +637,19 @@ fn call_row(
633 637 forwarded: false,
634 638 translation: None,
635 639 call: Some(call_card(
636 event,
637 &record.message_id,
638 &time,
640 CallSource {
641 event,
642 message_id: &record.message_id,
643 created_at: record.created_at,
644 time: &time,
645 },
639 646 &names,
640 transcript,
647 &CallClock {
648 offset: context.offset,
649 today: context.today,
650 meeting: &context.meeting,
651 },
652 timeline,
641 653 )),
642 654 time,
643 655 }
@@ -706,7 +718,8 @@ fn message_row_with(
706 718 quoted: &HashMap<String, String>,
707 719 ) -> MessageRow {
708 720 if let Some(event) = call_event(record) {
709 return call_row(record, &event, context, false);
721 let events = [Some(event.clone())];
722 return call_row(record, &event, context, &CallTimeline::new(&events));
710 723 }
711 724 let local = record.created_at.with_timezone(&context.offset);
712 725 let images = images(record);
@@ -778,7 +791,7 @@ pub fn flat_rows(records: &[MessageRecord], context: &RowContext, has_older: boo
778 791 rows.push(Row::LoadOlder);
779 792 }
780 793 let events: Vec<Option<CallEvent>> = records.iter().map(call_event).collect();
781 let timeline = CallTimeline::new(&events);
794 let timeline = CallTimeline::with_records(&events, &records.iter().collect::<Vec<_>>());
782 795 let mut previous_day: Option<NaiveDate> = None;
783 796 let quoted = quoted_texts(records);
784 797 for (index, (record, event)) in records.iter().zip(&events).enumerate() {
@@ -786,12 +799,7 @@ pub fn flat_rows(records: &[MessageRecord], context: &RowContext, has_older: boo
786 799 continue;
787 800 }
788 801 let mut row = match event {
789 Some(event) => call_row(
790 record,
791 event,
792 context,
793 timeline.has_transcript(&event.call_id),
794 ),
802 Some(event) => call_row(record, event, context, &timeline),
795 803 None => message_row_with(record, context, &quoted),
796 804 };
797 805 if let Some(call) = row.call.as_mut() {
@@ -849,12 +857,7 @@ fn post_message_row(
849 857 timeline: &CallTimeline,
850 858 ) -> MessageRow {
851 859 let mut row = match call_event(record) {
852 Some(event) => call_row(
853 record,
854 &event,
855 context,
856 timeline.has_transcript(&event.call_id),
857 ),
860 Some(event) => call_row(record, &event, context, timeline),
858 861 None => message_row(record, context),
859 862 };
860 863 row.day_header = None;
@@ -885,7 +888,7 @@ fn meeting_root_row(
885 888 ..ended_event
886 889 };
887 890 summary.call_type = started.call_type;
888 let mut row = call_row(ended_record, &summary, context, false);
891 let mut row = call_row(ended_record, &summary, context, timeline);
889 892 row.key = root.message_id.clone();
890 893 row.created_at = root.created_at;
891 894 row.reply_root = None;
@@ -1291,6 +1294,7 @@ mod tests {
1291 1294 card_overrides: HashMap::new(),
1292 1295 translation: TranslationContext::default(),
1293 1296 skin_tone: 0,
1297 meeting: MeetingInfo::default(),
1294 1298 }
1295 1299 }
1296 1300
@@ -2116,13 +2120,12 @@ mod tests {
2116 2120 let post = feed_post(&rows[0]);
2117 2121 assert_eq!(post.replies.len(), 1);
2118 2122 assert_eq!(post.hidden_reply_count, 0);
2119 let recording = post.replies[0]
2120 .call
2121 .as_ref()
2122 .and_then(|call| call.recording.as_ref())
2123 .unwrap();
2124 assert_eq!(recording.title, "Weekly team meeting");
2125 assert!(recording.transcript);
2123 let saved = post.replies[0].call.as_ref().unwrap();
2124 assert_eq!(saved.icon, CallIcon::Saved);
2125 assert_eq!(
2126 saved.notice.as_ref().unwrap().text,
2127 "Recording has been saved to OneDrive."
2128 );
2126 2129 let thread = thread_rows(&records, &root_id, &call_context());
2127 2130 let calls = thread
2128 2131 .iter()
@@ -14,8 +14,11 @@ use teams_core::{
14 reactions, readable_text, translated_spans,
14 reactions, readable_text, translated_spans,
15};
15};
16
16
17pub use crate::call_rows::{CallCard, CallIcon, CallParticipant, RecordingCard};
17pub use crate::call_rows::{
18use crate::call_rows::{CallNames, CallTimeline, call_card};
18 CallCard, CallIcon, CallNotice, CallParticipant, MeetingInfo, MeetingSlot, RecapCard,
19 RecordingCard,
20};
21use crate::call_rows::{CallClock, CallNames, CallSource, CallTimeline, call_card};
19use crate::card_state::CardOverride;
22use crate::card_state::CardOverride;
20use crate::format;
23use crate::format;
21use crate::reaction_model::{Reactor, UNKNOWN_REACTOR};
24use crate::reaction_model::{Reactor, UNKNOWN_REACTOR};
@@ -563,6 +566,7 @@ pub struct RowContext {
563 pub card_overrides: HashMap<String, CardOverride>,
566 pub card_overrides: HashMap<String, CardOverride>,
564 pub translation: TranslationContext,
567 pub translation: TranslationContext,
565 pub skin_tone: u8,
568 pub skin_tone: u8,
569 pub meeting: MeetingInfo,
566}
570}
567
571
568fn visible_reactions(record: &MessageRecord, context: &RowContext) -> Vec<ReactionInfo> {
572fn visible_reactions(record: &MessageRecord, context: &RowContext) -> Vec<ReactionInfo> {
@@ -580,7 +584,7 @@ fn call_row(
580 record: &MessageRecord,
584 record: &MessageRecord,
581 event: &CallEvent,
585 event: &CallEvent,
582 context: &RowContext,
586 context: &RowContext,
583 transcript: bool,
587 timeline: &CallTimeline,
584) -> MessageRow {
588) -> MessageRow {
585 let my_user_id = context.my_user_id.as_deref();
589 let my_user_id = context.my_user_id.as_deref();
586 let time = clock_label(record.created_at, context.offset);
590 let time = clock_label(record.created_at, context.offset);
@@ -633,11 +637,19 @@ fn call_row(
633 forwarded: false,
637 forwarded: false,
634 translation: None,
638 translation: None,
635 call: Some(call_card(
639 call: Some(call_card(
636 event,
640 CallSource {
637 &record.message_id,
641 event,
638 &time,
642 message_id: &record.message_id,
643 created_at: record.created_at,
644 time: &time,
645 },
639 &names,
646 &names,
640 transcript,
647 &CallClock {
648 offset: context.offset,
649 today: context.today,
650 meeting: &context.meeting,
651 },
652 timeline,
641 )),
653 )),
642 time,
654 time,
643 }
655 }
@@ -706,7 +718,8 @@ fn message_row_with(
706 quoted: &HashMap<String, String>,
718 quoted: &HashMap<String, String>,
707) -> MessageRow {
719) -> MessageRow {
708 if let Some(event) = call_event(record) {
720 if let Some(event) = call_event(record) {
709 return call_row(record, &event, context, false);
721 let events = [Some(event.clone())];
722 return call_row(record, &event, context, &CallTimeline::new(&events));
710 }
723 }
711 let local = record.created_at.with_timezone(&context.offset);
724 let local = record.created_at.with_timezone(&context.offset);
712 let images = images(record);
725 let images = images(record);
@@ -778,7 +791,7 @@ pub fn flat_rows(records: &[MessageRecord], context: &RowContext, has_older: boo
778 rows.push(Row::LoadOlder);
791 rows.push(Row::LoadOlder);
779 }
792 }
780 let events: Vec<Option<CallEvent>> = records.iter().map(call_event).collect();
793 let events: Vec<Option<CallEvent>> = records.iter().map(call_event).collect();
781 let timeline = CallTimeline::new(&events);
794 let timeline = CallTimeline::with_records(&events, &records.iter().collect::<Vec<_>>());
782 let mut previous_day: Option<NaiveDate> = None;
795 let mut previous_day: Option<NaiveDate> = None;
783 let quoted = quoted_texts(records);
796 let quoted = quoted_texts(records);
784 for (index, (record, event)) in records.iter().zip(&events).enumerate() {
797 for (index, (record, event)) in records.iter().zip(&events).enumerate() {
@@ -786,12 +799,7 @@ pub fn flat_rows(records: &[MessageRecord], context: &RowContext, has_older: boo
786 continue;
799 continue;
787 }
800 }
788 let mut row = match event {
801 let mut row = match event {
789 Some(event) => call_row(
802 Some(event) => call_row(record, event, context, &timeline),
790 record,
791 event,
792 context,
793 timeline.has_transcript(&event.call_id),
794 ),
795 None => message_row_with(record, context, &quoted),
803 None => message_row_with(record, context, &quoted),
796 };
804 };
797 if let Some(call) = row.call.as_mut() {
805 if let Some(call) = row.call.as_mut() {
@@ -849,12 +857,7 @@ fn post_message_row(
849 timeline: &CallTimeline,
857 timeline: &CallTimeline,
850) -> MessageRow {
858) -> MessageRow {
851 let mut row = match call_event(record) {
859 let mut row = match call_event(record) {
852 Some(event) => call_row(
860 Some(event) => call_row(record, &event, context, timeline),
853 record,
854 &event,
855 context,
856 timeline.has_transcript(&event.call_id),
857 ),
858 None => message_row(record, context),
861 None => message_row(record, context),
859 };
862 };
860 row.day_header = None;
863 row.day_header = None;
@@ -885,7 +888,7 @@ fn meeting_root_row(
885 ..ended_event
888 ..ended_event
886 };
889 };
887 summary.call_type = started.call_type;
890 summary.call_type = started.call_type;
888 let mut row = call_row(ended_record, &summary, context, false);
891 let mut row = call_row(ended_record, &summary, context, timeline);
889 row.key = root.message_id.clone();
892 row.key = root.message_id.clone();
890 row.created_at = root.created_at;
893 row.created_at = root.created_at;
891 row.reply_root = None;
894 row.reply_root = None;
@@ -1291,6 +1294,7 @@ mod tests {
1291 card_overrides: HashMap::new(),
1294 card_overrides: HashMap::new(),
1292 translation: TranslationContext::default(),
1295 translation: TranslationContext::default(),
1293 skin_tone: 0,
1296 skin_tone: 0,
1297 meeting: MeetingInfo::default(),
1294 }
1298 }
1295 }
1299 }
1296
1300
@@ -2116,13 +2120,12 @@ mod tests {
2116 let post = feed_post(&rows[0]);
2120 let post = feed_post(&rows[0]);
2117 assert_eq!(post.replies.len(), 1);
2121 assert_eq!(post.replies.len(), 1);
2118 assert_eq!(post.hidden_reply_count, 0);
2122 assert_eq!(post.hidden_reply_count, 0);
2119 let recording = post.replies[0]
2123 let saved = post.replies[0].call.as_ref().unwrap();
2120 .call
2124 assert_eq!(saved.icon, CallIcon::Saved);
2121 .as_ref()
2125 assert_eq!(
2122 .and_then(|call| call.recording.as_ref())
2126 saved.notice.as_ref().unwrap().text,
2123 .unwrap();
2127 "Recording has been saved to OneDrive."
2124 assert_eq!(recording.title, "Weekly team meeting");
2128 );
2125 assert!(recording.transcript);
2126 let thread = thread_rows(&records, &root_id, &call_context());
2129 let thread = thread_rows(&records, &root_id, &call_context());
2127 let calls = thread
2130 let calls = thread
2128 .iter()
2131 .iter()
crates/app-state/src/settings_section.rs added +21 −0
@@ -0,0 +1,21 @@
1 use gpui_kit::Context;
2
3 use crate::app_state::{AppEvent, AppState};
4
5 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
6 pub enum SettingsSection {
7 General,
8 Notifications,
9 Chats,
10 Calls,
11 Devices,
12 Agents,
13 Mcp,
14 About,
15 }
16
17 impl AppState {
18 pub fn open_settings(&mut self, section: SettingsSection, cx: &mut Context<Self>) {
19 cx.emit(AppEvent::Settings(section));
20 }
21 }
@@ -0,0 +1,21 @@
1use gpui_kit::Context;
2
3use crate::app_state::{AppEvent, AppState};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum SettingsSection {
7 General,
8 Notifications,
9 Chats,
10 Calls,
11 Devices,
12 Agents,
13 Mcp,
14 About,
15}
16
17impl AppState {
18 pub fn open_settings(&mut self, section: SettingsSection, cx: &mut Context<Self>) {
19 cx.emit(AppEvent::Settings(section));
20 }
21}
crates/app/assets/symbols/description.svg deleted +0 −1
@@ -1 +0,0 @@
1 <svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M320-240h320v-80H320v80Zm0-160h320v-80H320v80ZM240-80q-33 0-56.5-23.5T160-160v-640q0-33 23.5-56.5T240-880h320l240 240v480q0 33-23.5 56.5T720-80H240Zm280-520v-200H240v640h480v-440H520ZM240-800v200-200 640-640Z"/></svg>
@@ -1 +0,0 @@
1<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M320-240h320v-80H320v80Zm0-160h320v-80H320v80ZM240-80q-33 0-56.5-23.5T160-160v-640q0-33 23.5-56.5T240-880h320l240 240v480q0 33-23.5 56.5T720-80H240Zm280-520v-200H240v640h480v-440H520ZM240-800v200-200 640-640Z"/></svg>
crates/app/assets/symbols/fluent_clock.svg added +1 −0
@@ -0,0 +1 @@
1 <svg width="12" height="12" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg"><path d="M6 1a5 5 0 1 1 0 10A5 5 0 0 1 6 1Zm0 1a4 4 0 1 0 0 8 4 4 0 0 0 0-8Zm-.5 1.5a.5.5 0 0 1 .5.41V6h1.5a.5.5 0 0 1 .09 1H5.5a.5.5 0 0 1-.5-.41V4c0-.28.22-.5.5-.5Z"/></svg>
@@ -0,0 +1 @@
1<svg width="12" height="12" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg"><path d="M6 1a5 5 0 1 1 0 10A5 5 0 0 1 6 1Zm0 1a4 4 0 1 0 0 8 4 4 0 0 0 0-8Zm-.5 1.5a.5.5 0 0 1 .5.41V6h1.5a.5.5 0 0 1 .09 1H5.5a.5.5 0 0 1-.5-.41V4c0-.28.22-.5.5-.5Z"/></svg>
crates/app/assets/symbols/fluent_cloud_arrow_up.svg added +1 −0
@@ -0,0 +1 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20"><path d="M10 2c2.82 0 4.41 1.92 4.65 4.25h.07a3.33 3.33 0 0 1 3.27 3.66c-.32-.4-.7-.76-1.12-1.07a2.3 2.3 0 0 0-2.150-1.6h-.07a1 1 0 0 1-1-.9C13.45 4.33 12.11 3 10 3S6.55 4.32 6.35 6.35a1 1 0 0 1-1 .9h-.07A2.33 2.33 0 0 0 3 9.62 2.33 2.33 0 0 0 5.28 12h2.67c-.09.32-.15.66-.18 1H5.28A3.33 3.33 0 0 1 2 9.62c0-1.8 1.37-3.27 3.1-3.37h.25C5.6 3.9 7.18 2 10 2Zm3.5 7a4.5 4.5 0 1 1 0 9 4.5 4.5 0 0 1 0-9Zm1.6 4.9a.56.56 0 1 0 .8-.8l-2-2a.56.56 0 0 0-.8 0l-2 2a.56.56 0 1 0 .8.8l1.1-1.1v2.7a.5.5 0 0 0 1 0v-2.7l1.1 1.1Z"/></svg>
@@ -0,0 +1 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20"><path d="M10 2c2.82 0 4.41 1.92 4.65 4.25h.07a3.33 3.33 0 0 1 3.27 3.66c-.32-.4-.7-.76-1.12-1.07a2.3 2.3 0 0 0-2.150-1.6h-.07a1 1 0 0 1-1-.9C13.45 4.33 12.11 3 10 3S6.55 4.32 6.35 6.35a1 1 0 0 1-1 .9h-.07A2.33 2.33 0 0 0 3 9.62 2.33 2.33 0 0 0 5.28 12h2.67c-.09.32-.15.66-.18 1H5.28A3.33 3.33 0 0 1 2 9.62c0-1.8 1.37-3.27 3.1-3.37h.25C5.6 3.9 7.18 2 10 2Zm3.5 7a4.5 4.5 0 1 1 0 9 4.5 4.5 0 0 1 0-9Zm1.6 4.9a.56.56 0 1 0 .8-.8l-2-2a.56.56 0 0 0-.8 0l-2 2a.56.56 0 1 0 .8.8l1.1-1.1v2.7a.5.5 0 0 0 1 0v-2.7l1.1 1.1Z"/></svg>
crates/app/assets/symbols/fluent_document_text.svg added +1 −0
@@ -0,0 +1 @@
1 <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M6.5 10a.5.5 0 0 0 0 1h7a.5.5 0 0 0 0-1h-7Zm0 2a.5.5 0 0 0 0 1h7a.5.5 0 0 0 0-1h-7Zm0 2a.5.5 0 0 0 0 1h7a.5.5 0 0 0 0-1h-7ZM4 4c0-1.1.9-2 2-2h4.59c.4 0 .78.16 1.06.44l3.91 3.91c.28.28.44.67.44 1.06V16a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4Zm2-1a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V8h-3.5A1.5 1.5 0 0 1 10 6.5V3H6Zm5.5 4h3.3L11 3.2v3.3c0 .28.22.5.5.5Z"/></svg>
@@ -0,0 +1 @@
1<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M6.5 10a.5.5 0 0 0 0 1h7a.5.5 0 0 0 0-1h-7Zm0 2a.5.5 0 0 0 0 1h7a.5.5 0 0 0 0-1h-7Zm0 2a.5.5 0 0 0 0 1h7a.5.5 0 0 0 0-1h-7ZM4 4c0-1.1.9-2 2-2h4.59c.4 0 .78.16 1.06.44l3.91 3.91c.28.28.44.67.44 1.06V16a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4Zm2-1a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V8h-3.5A1.5 1.5 0 0 1 10 6.5V3H6Zm5.5 4h3.3L11 3.2v3.3c0 .28.22.5.5.5Z"/></svg>
crates/app/assets/symbols/fluent_record.svg added +1 −0
@@ -0,0 +1 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20"><path d="M10 14.5a4.5 4.5 0 1 0 0-9 4.5 4.5 0 0 0 0 9ZM10 2a8 8 0 1 0 0 16 8 8 0 0 0 0-16Zm-7 8a7 7 0 1 1 14 0 7 7 0 0 1-14 0Z"/></svg>
@@ -0,0 +1 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20"><path d="M10 14.5a4.5 4.5 0 1 0 0-9 4.5 4.5 0 0 0 0 9ZM10 2a8 8 0 1 0 0 16 8 8 0 0 0 0-16Zm-7 8a7 7 0 1 1 14 0 7 7 0 0 1-14 0Z"/></svg>
crates/app/assets/symbols/fluent_record_stop.svg added +1 −0
@@ -0,0 +1 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20"><path d="M10 3a7 7 0 1 0 0 14 7 7 0 0 0 0-14Zm-8 7a8 8 0 1 1 16 0 8 8 0 0 1-16 0Zm5-2a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v4a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1V8Z"/></svg>
@@ -0,0 +1 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20"><path d="M10 3a7 7 0 1 0 0 14 7 7 0 0 0 0-14Zm-8 7a8 8 0 1 1 16 0 8 8 0 0 1-16 0Zm5-2a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v4a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1V8Z"/></svg>
crates/app/assets/symbols/fluent_share.svg added +1 −0
@@ -0,0 +1 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20"><path d="m13.33 12.84 4.5-4.42.05-.07a.59.59 0 0 0-.05-.77l-4.5-4.42-.06-.05c-.36-.27-.9-.01-.9.47V5.7l-.22.01C8.6 6.01 6.5 8.26 6 12.35c-.06.53.54.85.93.5a9.64 9.64 0 0 1 4.450-2.38c.24-.06.5-.1.74-.12l.26-.02v2.17c.06.46.61.67.95.34Zm-1.1-6.12 1.15-.08V4.61L16.82 8l-3.44 3.39V9.23l-1.36.12c-1.7.19-3.32.87-4.83 2 .3-1.33.8-2.34 1.47-3.06a5.2 5.2 0 0 1 3.57-1.57ZM5.5 4A2.5 2.5 0 0 0 3 6.5v8A2.5 2.5 0 0 0 5.5 17h8a2.5 2.5 0 0 0 2.5-2.5v-1a.5.5 0 0 0-1 0v1c0 .83-.67 1.5-1.5 1.5h-8A1.5 1.5 0 0 1 4 14.5v-8C4 5.67 4.67 5 5.5 5h3a.5.5 0 0 0 0-1h-3Z"/></svg>
@@ -0,0 +1 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20"><path d="m13.33 12.84 4.5-4.42.05-.07a.59.59 0 0 0-.05-.77l-4.5-4.42-.06-.05c-.36-.27-.9-.01-.9.47V5.7l-.22.01C8.6 6.01 6.5 8.26 6 12.35c-.06.53.54.85.93.5a9.64 9.64 0 0 1 4.450-2.38c.24-.06.5-.1.74-.12l.26-.02v2.17c.06.46.61.67.95.34Zm-1.1-6.12 1.15-.08V4.61L16.82 8l-3.44 3.39V9.23l-1.36.12c-1.7.19-3.32.87-4.83 2 .3-1.33.8-2.34 1.47-3.06a5.2 5.2 0 0 1 3.57-1.57ZM5.5 4A2.5 2.5 0 0 0 3 6.5v8A2.5 2.5 0 0 0 5.5 17h8a2.5 2.5 0 0 0 2.5-2.5v-1a.5.5 0 0 0-1 0v1c0 .83-.67 1.5-1.5 1.5h-8A1.5 1.5 0 0 1 4 14.5v-8C4 5.67 4.67 5 5.5 5h3a.5.5 0 0 0 0-1h-3Z"/></svg>
crates/app/assets/symbols/fluent_video.svg added +1 −0
@@ -0,0 +1 @@
1 <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20"><path d="M5 4a3 3 0 0 0-3 3v6a3 3 0 0 0 3 3h5a3 3 0 0 0 3-3v-.32l3.04 2.1c.83.57 1.96-.03 1.960-1.03v-7.5c0-1-1.13-1.6-1.96-1.03L13 7.32V7a3 3 0 0 0-3-3H5Zm8 4.54 3.6-2.5c.17-.1.4.01.4.21v7.5c0 .2-.23.32-.4.2L13 11.46V8.540ZM3 7c0-1.1.9-2 2-2h5a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Z"/></svg>
@@ -0,0 +1 @@
1<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20"><path d="M5 4a3 3 0 0 0-3 3v6a3 3 0 0 0 3 3h5a3 3 0 0 0 3-3v-.32l3.04 2.1c.83.57 1.96-.03 1.960-1.03v-7.5c0-1-1.13-1.6-1.96-1.03L13 7.32V7a3 3 0 0 0-3-3H5Zm8 4.54 3.6-2.5c.17-.1.4.01.4.21v7.5c0 .2-.23.32-.4.2L13 11.46V8.540ZM3 7c0-1.1.9-2 2-2h5a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7Z"/></svg>
crates/app/assets/symbols/play_arrow.svg deleted +0 −1
@@ -1 +0,0 @@
1 <svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M320-200v-560l440 280-440 280Z"/></svg>
@@ -1 +0,0 @@
1<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M320-200v-560l440 280-440 280Z"/></svg>
crates/app/assets/symbols/radio_button_checked.svg deleted +0 −1
@@ -1 +0,0 @@
1 <svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M480-280q83 0 141.5-58.5T680-480q0-83-58.5-141.5T480-680q-83 0-141.5 58.5T280-480q0 83 58.5 141.5T480-280Zm0 200q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Z"/></svg>
@@ -1 +0,0 @@
1<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M480-280q83 0 141.5-58.5T680-480q0-83-58.5-141.5T480-680q-83 0-141.5 58.5T280-480q0 83 58.5 141.5T480-280Zm0 200q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Z"/></svg>
crates/app/assets/symbols/stop_circle.svg deleted +0 −1
@@ -1 +0,0 @@
1 <svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M320-320h320v-320H320v320ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Z"/></svg>
@@ -1 +0,0 @@
1<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24"><path d="M320-320h320v-320H320v320ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Z"/></svg>
crates/app/src/agents/settings_forms.rs +1 −1
@@ -11,7 +11,7 @@ use super::settings_controls::{
11 11 };
12 12 use super::settings_problems::{agent_problem, command_problem, placeholder_problem};
13 13 use super::settings_section::{AgentsSettings, Probe};
14 use crate::notify::switch;
14 use crate::settings::switch;
15 15 use crate::theme;
16 16 use crate::views::widgets::icon;
17 17
@@ -11,7 +11,7 @@ use super::settings_controls::{
11};
11};
12use super::settings_problems::{agent_problem, command_problem, placeholder_problem};
12use super::settings_problems::{agent_problem, command_problem, placeholder_problem};
13use super::settings_section::{AgentsSettings, Probe};
13use super::settings_section::{AgentsSettings, Probe};
14use crate::notify::switch;
14use crate::settings::switch;
15use crate::theme;
15use crate::theme;
16use crate::views::widgets::icon;
16use crate::views::widgets::icon;
17
17
crates/app/src/agents/settings_section.rs +1 −1
@@ -518,7 +518,7 @@ fn list_row(
518 518 .items_center()
519 519 .rounded(px(8.))
520 520 .cursor_pointer()
521 .hover(|row| row.bg(theme::row_hover()))
521 .hover(|row| row.bg(theme::popup_hover()))
522 522 .children(leading)
523 523 .child(
524 524 v_flex()
@@ -518,7 +518,7 @@ fn list_row(
518 .items_center()
518 .items_center()
519 .rounded(px(8.))
519 .rounded(px(8.))
520 .cursor_pointer()
520 .cursor_pointer()
521 .hover(|row| row.bg(theme::row_hover()))
521 .hover(|row| row.bg(theme::popup_hover()))
522 .children(leading)
522 .children(leading)
523 .child(
523 .child(
524 v_flex()
524 v_flex()
crates/app/src/layout_guard.rs +57 −0
@@ -169,6 +169,8 @@ mod frames {
169 169 use gpui_kit::Entity;
170 170
171 171 use crate::app_state::{AppHandle, AppState, Mode, Selection};
172 use crate::settings::metrics;
173 use crate::settings_section::SettingsSection;
172 174 use crate::call::{ActiveCall, CallModel, ConsultCall};
173 175 use crate::demo;
174 176 use crate::user_activity::UserInput;
@@ -245,6 +247,23 @@ mod frames {
245 247 PROPOSAL_BUTTONS,
246 248 REACTION_PILL,
247 249 ];
250 const SETTINGS_TAGS: &[&str] = &[
251 "settings",
252 "settings/nav",
253 "settings/main",
254 "settings/main/header",
255 "settings/main/body",
256 ];
257 const SETTINGS_SECTIONS: [SettingsSection; 8] = [
258 SettingsSection::General,
259 SettingsSection::Notifications,
260 SettingsSection::Chats,
261 SettingsSection::Calls,
262 SettingsSection::Devices,
263 SettingsSection::Agents,
264 SettingsSection::Mcp,
265 SettingsSection::About,
266 ];
248 267 const SIZES: [(f32, f32); 3] = [(640., 480.), (1280., 800.), (1920., 1080.)];
249 268 const TOLERANCE: f32 = 0.5;
250 269 const KNOWN_VIOLATIONS: &[&str] = &[];
@@ -393,6 +412,7 @@ mod frames {
393 412 &PEOPLE_PANEL,
394 413 ])
395 414 .chain(&AGENT_TAGS)
415 .chain(SETTINGS_TAGS)
396 416 .filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))
397 417 .collect()
398 418 }
@@ -809,6 +829,43 @@ mod frames {
809 829 }
810 830 }
811 831
832 #[gpui_kit::test]
833 fn settings_dialog_keeps_its_inset_at_every_size(cx: &mut TestAppContext) {
834 let (handle, state) = mount_with(cx, true);
835 let mut visual = VisualTestContext::from_window(handle, cx);
836 for (width, height) in SIZES.into_iter().chain([(960., 640.)]) {
837 visual.simulate_resize(size(px(width), px(height)));
838 let window = Bounds {
839 origin: point(px(0.), px(0.)),
840 size: size(px(width), px(height)),
841 };
842 let inset = metrics(width, height).inset;
843 for section in SETTINGS_SECTIONS {
844 visual.update(|_, cx| {
845 state.update(cx, |state, cx| state.open_settings(section, cx))
846 });
847 let tags = collect(&mut visual, Some(SETTINGS_TAGS[0]));
848 let found: Vec<String> = violations(&tags, window, SETTINGS_TAGS)
849 .into_iter()
850 .filter(|(key, _)| key.starts_with("settings"))
851 .map(|(key, message)| format!("{section:?}@{width}x{height}:{key}: {message}"))
852 .collect();
853 assert!(found.is_empty(), "{}", found.join("\n"));
854 let dialog = visual.debug_bounds(SETTINGS_TAGS[0]).expect("settings dialog");
855 let edges = [
856 f32::from(dialog.left()),
857 f32::from(dialog.top()),
858 width - f32::from(dialog.right()),
859 height - f32::from(dialog.bottom()),
860 ];
861 assert!(
862 edges.iter().all(|edge| (edge - inset).abs() <= TOLERANCE),
863 "{section:?}@{width}x{height}: dialog edges {edges:?}, expected {inset}"
864 );
865 }
866 }
867 }
868
812 869 #[gpui_kit::test]
813 870 fn agent_proposals_stay_inside_the_main_island(cx: &mut TestAppContext) {
814 871 let (handle, state) = mount_with(cx, true);
@@ -169,6 +169,8 @@ mod frames {
169 use gpui_kit::Entity;
169 use gpui_kit::Entity;
170
170
171 use crate::app_state::{AppHandle, AppState, Mode, Selection};
171 use crate::app_state::{AppHandle, AppState, Mode, Selection};
172 use crate::settings::metrics;
173 use crate::settings_section::SettingsSection;
172 use crate::call::{ActiveCall, CallModel, ConsultCall};
174 use crate::call::{ActiveCall, CallModel, ConsultCall};
173 use crate::demo;
175 use crate::demo;
174 use crate::user_activity::UserInput;
176 use crate::user_activity::UserInput;
@@ -245,6 +247,23 @@ mod frames {
245 PROPOSAL_BUTTONS,
247 PROPOSAL_BUTTONS,
246 REACTION_PILL,
248 REACTION_PILL,
247 ];
249 ];
250 const SETTINGS_TAGS: &[&str] = &[
251 "settings",
252 "settings/nav",
253 "settings/main",
254 "settings/main/header",
255 "settings/main/body",
256 ];
257 const SETTINGS_SECTIONS: [SettingsSection; 8] = [
258 SettingsSection::General,
259 SettingsSection::Notifications,
260 SettingsSection::Chats,
261 SettingsSection::Calls,
262 SettingsSection::Devices,
263 SettingsSection::Agents,
264 SettingsSection::Mcp,
265 SettingsSection::About,
266 ];
248 const SIZES: [(f32, f32); 3] = [(640., 480.), (1280., 800.), (1920., 1080.)];
267 const SIZES: [(f32, f32); 3] = [(640., 480.), (1280., 800.), (1920., 1080.)];
249 const TOLERANCE: f32 = 0.5;
268 const TOLERANCE: f32 = 0.5;
250 const KNOWN_VIOLATIONS: &[&str] = &[];
269 const KNOWN_VIOLATIONS: &[&str] = &[];
@@ -393,6 +412,7 @@ mod frames {
393 &PEOPLE_PANEL,
412 &PEOPLE_PANEL,
394 ])
413 ])
395 .chain(&AGENT_TAGS)
414 .chain(&AGENT_TAGS)
415 .chain(SETTINGS_TAGS)
396 .filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))
416 .filter_map(|path| visual.debug_bounds(path).map(|bounds| (*path, bounds)))
397 .collect()
417 .collect()
398 }
418 }
@@ -809,6 +829,43 @@ mod frames {
809 }
829 }
810 }
830 }
811
831
832 #[gpui_kit::test]
833 fn settings_dialog_keeps_its_inset_at_every_size(cx: &mut TestAppContext) {
834 let (handle, state) = mount_with(cx, true);
835 let mut visual = VisualTestContext::from_window(handle, cx);
836 for (width, height) in SIZES.into_iter().chain([(960., 640.)]) {
837 visual.simulate_resize(size(px(width), px(height)));
838 let window = Bounds {
839 origin: point(px(0.), px(0.)),
840 size: size(px(width), px(height)),
841 };
842 let inset = metrics(width, height).inset;
843 for section in SETTINGS_SECTIONS {
844 visual.update(|_, cx| {
845 state.update(cx, |state, cx| state.open_settings(section, cx))
846 });
847 let tags = collect(&mut visual, Some(SETTINGS_TAGS[0]));
848 let found: Vec<String> = violations(&tags, window, SETTINGS_TAGS)
849 .into_iter()
850 .filter(|(key, _)| key.starts_with("settings"))
851 .map(|(key, message)| format!("{section:?}@{width}x{height}:{key}: {message}"))
852 .collect();
853 assert!(found.is_empty(), "{}", found.join("\n"));
854 let dialog = visual.debug_bounds(SETTINGS_TAGS[0]).expect("settings dialog");
855 let edges = [
856 f32::from(dialog.left()),
857 f32::from(dialog.top()),
858 width - f32::from(dialog.right()),
859 height - f32::from(dialog.bottom()),
860 ];
861 assert!(
862 edges.iter().all(|edge| (edge - inset).abs() <= TOLERANCE),
863 "{section:?}@{width}x{height}: dialog edges {edges:?}, expected {inset}"
864 );
865 }
866 }
867 }
868
812 #[gpui_kit::test]
869 #[gpui_kit::test]
813 fn agent_proposals_stay_inside_the_main_island(cx: &mut TestAppContext) {
870 fn agent_proposals_stay_inside_the_main_island(cx: &mut TestAppContext) {
814 let (handle, state) = mount_with(cx, true);
871 let (handle, state) = mount_with(cx, true);
crates/app/src/main.rs +1 −0
@@ -8,6 +8,7 @@ pub mod call;
8 8 #[cfg(test)]
9 9 mod layout_guard;
10 10 pub mod notify;
11 mod settings;
11 12 mod views;
12 13
13 14 pub use state::*;
@@ -8,6 +8,7 @@ pub mod call;
8#[cfg(test)]
8#[cfg(test)]
9mod layout_guard;
9mod layout_guard;
10pub mod notify;
10pub mod notify;
11mod settings;
11mod views;
12mod views;
12
13
13pub use state::*;
14pub use state::*;
crates/app/src/notify/center.rs +7 −64
@@ -18,7 +18,6 @@ use super::rules::{
18 18 use super::settings;
19 19 use super::sound_cache::{self, SoundHandle};
20 20 use super::sounds::{CallTone, Ringtone};
21 use super::settings_view::{Section, SettingsView};
22 21 use super::stack::{
23 22 AgentToast, FADE_IN, FAST_FADE, ReplyState, SENT_DURATION, SLOW_FADE, ToastModel, ToastStack,
24 23 };
@@ -31,6 +30,7 @@ use crate::app_state::{AppEvent, AppState, selection_for};
31 30 use crate::call::DemoScene;
32 31 use crate::data::{self, Directory, PresenceKind};
33 32 use crate::runtime;
33 use crate::settings_section::SettingsSection;
34 34 use crate::single_instance;
35 35
36 36 const TICK: Duration = Duration::from_millis(33);
@@ -86,8 +86,6 @@ pub struct NotificationCenter {
86 86 pill: Option<OpenWindow>,
87 87 pill_opening: bool,
88 88 hover_hold: bool,
89 settings_window: Option<AnyWindowHandle>,
90 settings_opening: bool,
91 89 unread_mentions: HashSet<String>,
92 90 tray: Option<Tray>,
93 91 shown_badge: Option<Badge>,
@@ -142,8 +140,6 @@ impl NotificationCenter {
142 140 pill: None,
143 141 pill_opening: false,
144 142 hover_hold: false,
145 settings_window: None,
146 settings_opening: false,
147 143 unread_mentions: HashSet::new(),
148 144 tray,
149 145 shown_badge: None,
@@ -877,7 +873,12 @@ impl NotificationCenter {
877 873 TrayCommand::ToggleDoNotDisturb => self.update_settings(cx, |settings| {
878 874 settings.do_not_disturb = !settings.do_not_disturb
879 875 }),
880 TrayCommand::Settings => self.open_settings(cx),
876 TrayCommand::Settings => {
877 self.raise_main_window(cx);
878 self.app.update(cx, |state, cx| {
879 state.open_settings(SettingsSection::General, cx)
880 });
881 }
881 882 TrayCommand::Quit => cx.quit(),
882 883 }
883 884 }
@@ -1076,64 +1077,6 @@ impl NotificationCenter {
1076 1077 }
1077 1078 }
1078 1079
1079 pub fn open_settings(&mut self, cx: &mut Context<Self>) {
1080 self.show_settings(Section::Notifications, false, cx);
1081 }
1082
1083 pub fn open_agent_settings(&mut self, cx: &mut Context<Self>) {
1084 self.show_settings(Section::Agents, true, cx);
1085 }
1086
1087 fn show_settings(
1088 &mut self,
1089 section: Section,
1090 switch_open_window: bool,
1091 cx: &mut Context<Self>,
1092 ) {
1093 if let Some(handle) = self.settings_window {
1094 let shown = handle.update(cx, |view, window, cx| {
1095 window.activate_window();
1096 if switch_open_window && let Ok(view) = view.downcast::<SettingsView>() {
1097 view.update(cx, |view, cx| view.select_section(section, cx));
1098 }
1099 });
1100 if shown.is_ok() {
1101 return;
1102 }
1103 self.settings_window = None;
1104 }
1105 if self.settings_opening {
1106 return;
1107 }
1108 self.settings_opening = true;
1109 let center = cx.entity();
1110 let options = WindowOptions {
1111 window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
1112 None,
1113 size(px(SettingsView::WIDTH), px(SettingsView::HEIGHT)),
1114 cx,
1115 ))),
1116 titlebar: Some(TitlebarOptions {
1117 title: Some("Settings".into()),
1118 ..Default::default()
1119 }),
1120 is_resizable: false,
1121 is_minimizable: false,
1122 ..Default::default()
1123 };
1124 // open_window draws once right away, and SettingsView reads this entity while rendering.
1125 cx.defer(move |cx| {
1126 let view_center = center.clone();
1127 let opened = gpui_kit::open_window(options, cx, move |window, cx| {
1128 cx.new(|cx| SettingsView::new(view_center, section, window, cx))
1129 });
1130 center.update(cx, |this, _| {
1131 this.settings_opening = false;
1132 this.settings_window = opened.ok().map(|(handle, _)| handle);
1133 });
1134 });
1135 }
1136
1137 1080 pub fn send_test_notification(&mut self, cx: &mut Context<Self>) {
1138 1081 let incoming = Incoming {
1139 1082 conversation_id: "test-notification".to_owned(),
@@ -18,7 +18,6 @@ use super::rules::{
18use super::settings;
18use super::settings;
19use super::sound_cache::{self, SoundHandle};
19use super::sound_cache::{self, SoundHandle};
20use super::sounds::{CallTone, Ringtone};
20use super::sounds::{CallTone, Ringtone};
21use super::settings_view::{Section, SettingsView};
22use super::stack::{
21use super::stack::{
23 AgentToast, FADE_IN, FAST_FADE, ReplyState, SENT_DURATION, SLOW_FADE, ToastModel, ToastStack,
22 AgentToast, FADE_IN, FAST_FADE, ReplyState, SENT_DURATION, SLOW_FADE, ToastModel, ToastStack,
24};
23};
@@ -31,6 +30,7 @@ use crate::app_state::{AppEvent, AppState, selection_for};
31use crate::call::DemoScene;
30use crate::call::DemoScene;
32use crate::data::{self, Directory, PresenceKind};
31use crate::data::{self, Directory, PresenceKind};
33use crate::runtime;
32use crate::runtime;
33use crate::settings_section::SettingsSection;
34use crate::single_instance;
34use crate::single_instance;
35
35
36const TICK: Duration = Duration::from_millis(33);
36const TICK: Duration = Duration::from_millis(33);
@@ -86,8 +86,6 @@ pub struct NotificationCenter {
86 pill: Option<OpenWindow>,
86 pill: Option<OpenWindow>,
87 pill_opening: bool,
87 pill_opening: bool,
88 hover_hold: bool,
88 hover_hold: bool,
89 settings_window: Option<AnyWindowHandle>,
90 settings_opening: bool,
91 unread_mentions: HashSet<String>,
89 unread_mentions: HashSet<String>,
92 tray: Option<Tray>,
90 tray: Option<Tray>,
93 shown_badge: Option<Badge>,
91 shown_badge: Option<Badge>,
@@ -142,8 +140,6 @@ impl NotificationCenter {
142 pill: None,
140 pill: None,
143 pill_opening: false,
141 pill_opening: false,
144 hover_hold: false,
142 hover_hold: false,
145 settings_window: None,
146 settings_opening: false,
147 unread_mentions: HashSet::new(),
143 unread_mentions: HashSet::new(),
148 tray,
144 tray,
149 shown_badge: None,
145 shown_badge: None,
@@ -877,7 +873,12 @@ impl NotificationCenter {
877 TrayCommand::ToggleDoNotDisturb => self.update_settings(cx, |settings| {
873 TrayCommand::ToggleDoNotDisturb => self.update_settings(cx, |settings| {
878 settings.do_not_disturb = !settings.do_not_disturb
874 settings.do_not_disturb = !settings.do_not_disturb
879 }),
875 }),
880 TrayCommand::Settings => self.open_settings(cx),
876 TrayCommand::Settings => {
877 self.raise_main_window(cx);
878 self.app.update(cx, |state, cx| {
879 state.open_settings(SettingsSection::General, cx)
880 });
881 }
881 TrayCommand::Quit => cx.quit(),
882 TrayCommand::Quit => cx.quit(),
882 }
883 }
883 }
884 }
@@ -1076,64 +1077,6 @@ impl NotificationCenter {
1076 }
1077 }
1077 }
1078 }
1078
1079
1079 pub fn open_settings(&mut self, cx: &mut Context<Self>) {
1080 self.show_settings(Section::Notifications, false, cx);
1081 }
1082
1083 pub fn open_agent_settings(&mut self, cx: &mut Context<Self>) {
1084 self.show_settings(Section::Agents, true, cx);
1085 }
1086
1087 fn show_settings(
1088 &mut self,
1089 section: Section,
1090 switch_open_window: bool,
1091 cx: &mut Context<Self>,
1092 ) {
1093 if let Some(handle) = self.settings_window {
1094 let shown = handle.update(cx, |view, window, cx| {
1095 window.activate_window();
1096 if switch_open_window && let Ok(view) = view.downcast::<SettingsView>() {
1097 view.update(cx, |view, cx| view.select_section(section, cx));
1098 }
1099 });
1100 if shown.is_ok() {
1101 return;
1102 }
1103 self.settings_window = None;
1104 }
1105 if self.settings_opening {
1106 return;
1107 }
1108 self.settings_opening = true;
1109 let center = cx.entity();
1110 let options = WindowOptions {
1111 window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
1112 None,
1113 size(px(SettingsView::WIDTH), px(SettingsView::HEIGHT)),
1114 cx,
1115 ))),
1116 titlebar: Some(TitlebarOptions {
1117 title: Some("Settings".into()),
1118 ..Default::default()
1119 }),
1120 is_resizable: false,
1121 is_minimizable: false,
1122 ..Default::default()
1123 };
1124 // open_window draws once right away, and SettingsView reads this entity while rendering.
1125 cx.defer(move |cx| {
1126 let view_center = center.clone();
1127 let opened = gpui_kit::open_window(options, cx, move |window, cx| {
1128 cx.new(|cx| SettingsView::new(view_center, section, window, cx))
1129 });
1130 center.update(cx, |this, _| {
1131 this.settings_opening = false;
1132 this.settings_window = opened.ok().map(|(handle, _)| handle);
1133 });
1134 });
1135 }
1136
1137 pub fn send_test_notification(&mut self, cx: &mut Context<Self>) {
1080 pub fn send_test_notification(&mut self, cx: &mut Context<Self>) {
1138 let incoming = Incoming {
1081 let incoming = Incoming {
1139 conversation_id: "test-notification".to_owned(),
1082 conversation_id: "test-notification".to_owned(),
crates/app/src/notify/mod.rs +0 −3
@@ -2,10 +2,7 @@ mod agent_toast;
2 2 mod center;
3 3 mod meeting_view;
4 4 mod ring_view;
5 mod settings_mcp;
6 mod settings_view;
7 5 mod toast;
8 6
9 7 pub use state::notify::*;
10 8 pub use center::NotificationCenter;
11 pub(crate) use settings_view::switch;
@@ -2,10 +2,7 @@ mod agent_toast;
2mod center;
2mod center;
3mod meeting_view;
3mod meeting_view;
4mod ring_view;
4mod ring_view;
5mod settings_mcp;
6mod settings_view;
7mod toast;
5mod toast;
8
6
9pub use state::notify::*;
7pub use state::notify::*;
10pub use center::NotificationCenter;
8pub use center::NotificationCenter;
11pub(crate) use settings_view::switch;
crates/app/src/notify/settings_view.rs deleted +0 −1002
@@ -1,1002 +0,0 @@
1 use std::time::{Duration, Instant};
2
3 use calling::camera::{DEFAULT_CAMERA_LABEL, list_cameras};
4 use calling::{CameraEffects, DeviceChoice, DeviceEntry, MicSettings, NoiseSuppression, camera_entries};
5 use gpui_kit::assets::IconName;
6 use gpui_kit::component::{
7 button::Button,
8 h_flex,
9 menu::{DropdownMenu as _, PopupMenuItem},
10 v_flex,
11 };
12 use gpui_kit::base::Disableable as _;
13 use gpui_kit::prelude::FluentBuilder as _;
14 use gpui_kit::*;
15
16 use super::center::NotificationCenter;
17 use super::sounds::{AlertSound, Ringtone, RingtoneCallType};
18 use super::rules::Settings;
19 use super::settings_mcp::McpView;
20 use crate::agents::AgentsSettings;
21 use crate::app_state::AppState;
22 use crate::call::{BackgroundPick, CameraPreview, preview_backgrounds};
23 use crate::theme;
24
25 const FPS_TICK: Duration = Duration::from_millis(500);
26 const SELECT_WIDTH: f32 = 170.;
27 const SOUND_SELECT_WIDTH: f32 = 124.;
28 const PREVIEW_WIDTH: f32 = 380.;
29 const PREVIEW_HEIGHT: f32 = 214.;
30 const PREVIEW_RADIUS: f32 = 10.;
31 const SOFT_FOCUS_LEVELS: [(&str, u8); 3] = [("Low", 25), ("Medium", 50), ("High", 75)];
32 const CAMERA_IN_USE: &str = "Camera is in use by the call";
33
34 fn camera_in_call(state: &AppState) -> bool {
35 state.call.is_some()
36 }
37
38 #[derive(Clone, Copy, PartialEq, Eq)]
39 pub(super) enum Section {
40 Notifications,
41 Calls,
42 Devices,
43 Agents,
44 Mcp,
45 }
46
47 impl Section {
48 const ALL: [Section; 5] = [
49 Section::Notifications,
50 Section::Calls,
51 Section::Devices,
52 Section::Agents,
53 Section::Mcp,
54 ];
55
56 fn label(self) -> &'static str {
57 match self {
58 Section::Notifications => "Notifications",
59 Section::Calls => "Calls",
60 Section::Devices => "Devices",
61 Section::Agents => "Agents",
62 Section::Mcp => "MCP",
63 }
64 }
65 }
66
67 type Accessor = fn(&mut Settings) -> &mut bool;
68
69 struct Row {
70 title: &'static str,
71 detail: &'static str,
72 field: Accessor,
73 }
74
75 const ROWS: [Row; 5] = [
76 Row {
77 title: "Mentions only",
78 detail: "Direct messages and @mentions",
79 field: |settings| &mut settings.mentions_only,
80 },
81 Row {
82 title: "Show preview",
83 detail: "Off: only \"New message\"",
84 field: |settings| &mut settings.preview,
85 },
86 Row {
87 title: "Flash taskbar",
88 detail: "On new messages, until you open the window",
89 field: |settings| &mut settings.flash,
90 },
91 Row {
92 title: "Mute notifications during calls and meetings",
93 detail: "No message toasts while a call is active",
94 field: |settings| &mut settings.mute_in_calls,
95 },
96 Row {
97 title: "Minimize to tray on close",
98 detail: "The title bar X hides the window",
99 field: |settings| &mut settings.close_to_tray,
100 },
101 ];
102
103 const NOTIFICATION_SOUND_ROW: Row = Row {
104 title: "Play sounds with notifications",
105 detail: "",
106 field: |settings| &mut settings.sounds.notification_sound,
107 };
108
109 const URGENT_SOUND_ROW: Row = Row {
110 title: "Play sounds with urgent and priority contact notifications",
111 detail: "",
112 field: |settings| &mut settings.sounds.urgent_sound,
113 };
114
115 const CALL_SOUND_ROWS: [Row; 2] = [
116 Row {
117 title: "Play sounds with incoming calls, requests to join, and meeting start notifications",
118 detail: "",
119 field: |settings| &mut settings.sounds.call_and_meeting_sound,
120 },
121 Row {
122 title: "Play sounds when I'm busy or in a meeting",
123 detail: "",
124 field: |settings| &mut settings.sounds.sound_when_busy,
125 },
126 ];
127
128 type SoundAccessor = fn(&mut Settings) -> &mut AlertSound;
129
130 pub struct SettingsView {
131 center: Entity<NotificationCenter>,
132 section: Section,
133 mcp: Entity<McpView>,
134 agents: Option<Entity<AgentsSettings>>,
135 preview: CameraPreview,
136 cameras: Vec<DeviceEntry>,
137 cameras_requested: bool,
138 camera: DeviceChoice,
139 background: BackgroundPick,
140 preview_blocked: bool,
141 _subscription: Subscription,
142 _app_subscription: Subscription,
143 _release: Subscription,
144 }
145
146 impl SettingsView {
147 pub const WIDTH: f32 = 420.;
148 pub const HEIGHT: f32 = 680.;
149
150 pub fn new(
151 center: Entity<NotificationCenter>,
152 section: Section,
153 window: &mut Window,
154 cx: &mut Context<Self>,
155 ) -> Self {
156 let subscription = cx.observe(&center, |_, _, cx| cx.notify());
157 let app = center.read(cx).app().clone();
158 let app_subscription = cx.observe(&app, |view, _, cx| view.sync_preview_block(cx));
159 let release = cx.on_release(|view, cx| view.preview.stop(cx));
160 let (preview, mut updates) = CameraPreview::new();
161 let mcp = cx.new(|cx| McpView::new(app.clone(), window, cx));
162 let state = app.read(cx);
163 let camera = state.call_camera.clone();
164 preview.set_effects(state.call_effects);
165 let preview_blocked = camera_in_call(state);
166 let background = Some(state.call_background.clone())
167 .filter(|pick| {
168 preview_backgrounds(&state.call_backgrounds)
169 .iter()
170 .any(|(known, _)| known == pick)
171 })
172 .unwrap_or_default();
173 cx.spawn(async move |this, cx| {
174 while updates.recv().await.is_some() {
175 if this.update(cx, |view, cx| view.take_frames(cx)).is_err() {
176 return;
177 }
178 }
179 })
180 .detach();
181 cx.spawn(async move |this, cx| {
182 loop {
183 cx.background_executor().timer(FPS_TICK).await;
184 if this.update(cx, |view, cx| view.tick(cx)).is_err() {
185 break;
186 }
187 }
188 })
189 .detach();
190 let agents =
191 crate::agents::runs_handle(cx).map(|runs| cx.new(|cx| AgentsSettings::new(runs, cx)));
192 SettingsView {
193 center,
194 section,
195 mcp,
196 agents,
197 preview,
198 cameras: camera_entries(&[]),
199 cameras_requested: false,
200 camera,
201 background,
202 preview_blocked,
203 _subscription: subscription,
204 _app_subscription: app_subscription,
205 _release: release,
206 }
207 }
208
209 fn take_frames(&mut self, cx: &mut Context<Self>) {
210 self.preview.take_frames(cx);
211 cx.notify();
212 }
213
214 fn tick(&mut self, cx: &mut Context<Self>) {
215 if self.section == Section::Devices {
216 self.preview.tick(Instant::now());
217 cx.notify();
218 }
219 }
220
221 pub(super) fn select_section(&mut self, section: Section, cx: &mut Context<Self>) {
222 if self.section == section {
223 return;
224 }
225 self.section = section;
226 match section {
227 Section::Devices => {
228 self.load_cameras(cx);
229 self.apply_background(cx);
230 self.preview
231 .set_effects(self.center.read(cx).app().read(cx).call_effects);
232 self.preview_blocked = camera_in_call(self.center.read(cx).app().read(cx));
233 self.start_preview();
234 }
235 Section::Notifications | Section::Calls | Section::Agents | Section::Mcp => {
236 self.preview.stop(cx)
237 }
238 }
239 cx.notify();
240 }
241
242 fn load_cameras(&mut self, cx: &mut Context<Self>) {
243 if std::mem::replace(&mut self.cameras_requested, true) {
244 return;
245 }
246 cx.spawn(async move |this, cx| {
247 let cameras = cx
248 .background_executor()
249 .spawn(async { list_cameras() })
250 .await;
251 this.update(cx, |view, cx| {
252 view.cameras = camera_entries(&cameras);
253 cx.notify();
254 })
255 .ok();
256 })
257 .detach();
258 }
259
260 fn start_preview(&mut self) {
261 if !self.preview_blocked {
262 self.preview.start(&self.camera);
263 }
264 }
265
266 fn sync_preview_block(&mut self, cx: &mut Context<Self>) {
267 let blocked = camera_in_call(self.center.read(cx).app().read(cx));
268 if blocked == self.preview_blocked {
269 return;
270 }
271 self.preview_blocked = blocked;
272 if blocked {
273 self.preview.stop(cx);
274 } else if self.section == Section::Devices {
275 self.start_preview();
276 }
277 cx.notify();
278 }
279
280 fn select_camera(&mut self, camera: DeviceChoice, cx: &mut Context<Self>) {
281 self.camera = camera.clone();
282 let app = self.center.read(cx).app().clone();
283 app.update(cx, |state, cx| state.select_call_camera(camera, cx));
284 self.start_preview();
285 cx.notify();
286 }
287
288 fn set_mic(&mut self, settings: MicSettings, cx: &mut Context<Self>) {
289 let app = self.center.read(cx).app().clone();
290 app.update(cx, |state, cx| state.set_call_mic(settings, cx));
291 cx.notify();
292 }
293
294 fn set_report_enabled(&mut self, on: bool, cx: &mut Context<Self>) {
295 let app = self.center.read(cx).app().clone();
296 app.update(cx, |state, cx| state.set_call_report_enabled(on, cx));
297 cx.notify();
298 }
299
300 fn change_effects(&mut self, change: fn(&mut CameraEffects), cx: &mut Context<Self>) {
301 let app = self.center.read(cx).app().clone();
302 let mut effects = app.read(cx).call_effects;
303 change(&mut effects);
304 self.preview.set_effects(effects);
305 app.update(cx, |state, cx| state.set_call_effects(effects, cx));
306 cx.notify();
307 }
308
309 fn effect_row(
310 &self,
311 id: &'static str,
312 title: &'static str,
313 on: bool,
314 change: fn(&mut CameraEffects),
315 cx: &mut Context<Self>,
316 ) -> Stateful<Div> {
317 let view = cx.entity();
318 h_flex()
319 .id(id)
320 .w_full()
321 .px(px(20.))
322 .py(px(6.))
323 .gap(px(12.))
324 .items_center()
325 .cursor_pointer()
326 .hover(|row| row.bg(theme::row_hover()))
327 .on_click(move |_, _, cx| view.update(cx, |view, cx| view.change_effects(change, cx)))
328 .child(
329 div()
330 .flex_1()
331 .text_size(px(14.))
332 .font_weight(FontWeight::SEMIBOLD)
333 .text_color(theme::text())
334 .child(title),
335 )
336 .child(switch(on))
337 }
338
339 fn strength_row(&self, strength: u8, cx: &mut Context<Self>) -> Stateful<Div> {
340 let levels = SOFT_FOCUS_LEVELS.map(|(label, level)| {
341 let view = cx.entity();
342 let app = self.center.read(cx).app().clone();
343 button(label)
344 .when(strength == level, |button| {
345 button.bg(theme::accent()).text_color(theme::on_accent())
346 })
347 .on_click(move |_, _, cx| {
348 app.update(cx, |state, cx| {
349 let effects = CameraEffects {
350 soft_focus_strength: level,
351 ..state.call_effects
352 };
353 state.set_call_effects(effects, cx);
354 view.update(cx, |view, cx| {
355 view.preview.set_effects(effects);
356 cx.notify();
357 });
358 })
359 })
360 });
361 h_flex()
362 .id("effect-soft-focus-strength")
363 .w_full()
364 .px(px(20.))
365 .py(px(6.))
366 .gap(px(8.))
367 .items_center()
368 .child(
369 div()
370 .flex_1()
371 .text_size(px(12.))
372 .text_color(theme::text_muted())
373 .child("Soft focus strength"),
374 )
375 .children(levels)
376 }
377
378 fn select_background(&mut self, pick: BackgroundPick, cx: &mut Context<Self>) {
379 self.background = pick.clone();
380 let app = self.center.read(cx).app().clone();
381 app.update(cx, |state, cx| state.set_call_background(pick, cx));
382 self.apply_background(cx);
383 cx.notify();
384 }
385
386 fn apply_background(&self, cx: &App) {
387 let state = self.center.read(cx).app().read(cx);
388 if let Some(choice) = state.call_backgrounds.choice_for(&self.background) {
389 self.preview.set_background(choice);
390 }
391 }
392 }
393
394 pub(crate) fn switch(on: bool) -> Div {
395 div()
396 .w(px(36.))
397 .h(px(20.))
398 .flex_none()
399 .rounded_full()
400 .relative()
401 .bg(if on {
402 theme::accent()
403 } else {
404 theme::border_strong()
405 })
406 .child(
407 div()
408 .absolute()
409 .top(px(2.))
410 .left(px(if on { 18. } else { 2. }))
411 .size(px(16.))
412 .rounded_full()
413 .bg(theme::text()),
414 )
415 }
416
417 fn button(label: &'static str) -> Stateful<Div> {
418 button_with_id(label, label)
419 }
420
421 fn button_with_id(id: &'static str, label: &'static str) -> Stateful<Div> {
422 div()
423 .id(id)
424 .h(px(32.))
425 .px(px(14.))
426 .flex()
427 .items_center()
428 .rounded(px(8.))
429 .border_1()
430 .border_color(theme::border_strong())
431 .cursor_pointer()
432 .text_size(px(13.))
433 .font_weight(FontWeight::SEMIBOLD)
434 .text_color(theme::text())
435 .hover(|button| button.bg(theme::row_hover()))
436 .child(label)
437 }
438
439 fn titled(title: &'static str, detail: impl Into<SharedString>) -> Div {
440 titled_with(title, detail, theme::text_muted())
441 }
442
443 pub(super) fn titled_with(
444 title: &'static str,
445 detail: impl Into<SharedString>,
446 detail_color: Hsla,
447 ) -> Div {
448 v_flex()
449 .flex_1()
450 .min_w(px(0.))
451 .child(
452 div()
453 .text_size(px(14.))
454 .font_weight(FontWeight::SEMIBOLD)
455 .text_color(theme::text())
456 .child(title),
457 )
458 .map(|column| {
459 let detail = detail.into();
460 if detail.is_empty() {
461 return column;
462 }
463 column.child(
464 div()
465 .text_size(px(12.))
466 .text_color(detail_color)
467 .child(detail),
468 )
469 })
470 }
471
472 pub(super) fn control_row(
473 title: &'static str,
474 detail: impl Into<SharedString>,
475 control: impl IntoElement,
476 ) -> Div {
477 h_flex()
478 .w_full()
479 .px(px(20.))
480 .py(px(10.))
481 .gap(px(12.))
482 .items_center()
483 .child(titled(title, detail))
484 .child(control)
485 }
486
487 fn section_tab(section: Section, active: bool, view: Entity<SettingsView>) -> Stateful<Div> {
488 div()
489 .id(section.label())
490 .h(px(32.))
491 .px(px(14.))
492 .flex()
493 .items_center()
494 .rounded(px(8.))
495 .cursor_pointer()
496 .text_size(px(13.))
497 .font_weight(FontWeight::SEMIBOLD)
498 .text_color(if active {
499 theme::on_accent()
500 } else {
501 theme::text()
502 })
503 .when(active, |tab| tab.bg(theme::accent()))
504 .when(!active, |tab| tab.hover(|tab| tab.bg(theme::row_hover())))
505 .child(section.label())
506 .on_click(move |_, _, cx| view.update(cx, |view, cx| view.select_section(section, cx)))
507 }
508
509 fn heading(title: &'static str) -> Div {
510 div()
511 .w_full()
512 .px(px(20.))
513 .pt(px(16.))
514 .pb(px(4.))
515 .text_size(px(12.))
516 .font_weight(FontWeight::SEMIBOLD)
517 .text_color(theme::text_muted())
518 .child(title)
519 }
520
521 fn picker(
522 id: &'static str,
523 label: &'static str,
524 disabled: bool,
525 menu_items: impl Fn() -> Vec<(&'static str, bool, Box<dyn Fn(&mut App)>)> + 'static,
526 ) -> impl IntoElement {
527 Button::new(id)
528 .outline()
529 .w(px(SOUND_SELECT_WIDTH))
530 .label(label)
531 .icon(IconName::ChevronDown)
532 .disabled(disabled)
533 .dropdown_menu(move |menu, _, _| {
534 menu_items()
535 .into_iter()
536 .fold(menu, |menu, (label, checked, choose)| {
537 menu.item(
538 PopupMenuItem::new(label)
539 .checked(checked)
540 .on_click(move |_, _, cx| choose(cx)),
541 )
542 })
543 })
544 }
545
546 impl SettingsView {
547 fn switch_row(&self, row: &Row, on: bool) -> Stateful<Div> {
548 let center = self.center.clone();
549 let field = row.field;
550 h_flex()
551 .id(row.title)
552 .w_full()
553 .px(px(20.))
554 .py(px(10.))
555 .gap(px(12.))
556 .items_center()
557 .cursor_pointer()
558 .hover(|row| row.bg(theme::row_hover()))
559 .on_click(move |_, _, cx| {
560 center.update(cx, |center, cx| {
561 center.update_settings(cx, |settings| {
562 let value = field(settings);
563 *value = !*value;
564 })
565 });
566 })
567 .child(titled(row.title, row.detail))
568 .child(switch(on))
569 }
570
571 fn alert_sound_row(
572 &self,
573 (id, preview_id): (&'static str, &'static str),
574 title: &'static str,
575 options: &'static [AlertSound],
576 current: AlertSound,
577 enabled: bool,
578 field: SoundAccessor,
579 ) -> Div {
580 let center = self.center.clone();
581 let preview_center = self.center.clone();
582 let choices = move || {
583 options
584 .iter()
585 .map(|sound| {
586 let (center, sound) = (center.clone(), *sound);
587 let choose: Box<dyn Fn(&mut App)> = Box::new(move |cx| {
588 center.update(cx, |center, cx| {
589 center.update_settings(cx, |settings| *field(settings) = sound);
590 center.preview_sound(sound.file_name(), cx);
591 })
592 });
593 (sound.label(), sound == current, choose)
594 })
595 .collect()
596 };
597 control_row(
598 title,
599 "",
600 h_flex()
601 .gap(px(8.))
602 .items_center()
603 .child(picker(id, current.label(), !enabled, choices))
604 .child(button_with_id(preview_id, "Preview").on_click(
605 move |_, _, cx| {
606 preview_center
607 .update(cx, |center, cx| center.preview_sound(current.file_name(), cx))
608 },
609 )),
610 )
611 }
612
613 fn ringtone_row(&self, call_type: RingtoneCallType, current: Ringtone) -> Div {
614 let center = self.center.clone();
615 let preview_center = self.center.clone();
616 let choices = move || {
617 Ringtone::ALL
618 .iter()
619 .map(|ringtone| {
620 let (center, ringtone) = (center.clone(), *ringtone);
621 let choose: Box<dyn Fn(&mut App)> = Box::new(move |cx| {
622 center.update(cx, |center, cx| {
623 center.update_settings(cx, |settings| {
624 settings.sounds.ringtones.set(call_type, ringtone)
625 });
626 center.preview_sound(ringtone.file_name(), cx);
627 })
628 });
629 (ringtone.label(), ringtone == current, choose)
630 })
631 .collect()
632 };
633 let (id, preview_id) = ringtone_ids(call_type);
634 control_row(
635 call_type.label(),
636 "",
637 h_flex()
638 .gap(px(8.))
639 .items_center()
640 .child(picker(id, current.label(), false, choices))
641 .child(button_with_id(preview_id, "Preview").on_click(
642 move |_, _, cx| {
643 preview_center.update(cx, |center, cx| {
644 center.preview_sound(current.file_name(), cx)
645 })
646 },
647 )),
648 )
649 }
650
651 fn calls_section(&self, cx: &App) -> Div {
652 let ringtones = self.center.read(cx).settings().sounds.ringtones;
653 let rows = RingtoneCallType::ALL
654 .into_iter()
655 .filter(|call_type| {
656 *call_type == RingtoneCallType::Regular
657 || ringtones.get(*call_type) != Ringtone::Ring
658 })
659 .map(|call_type| self.ringtone_row(call_type, ringtones.get(call_type)));
660 v_flex()
661 .w_full()
662 .pt(px(8.))
663 .child(heading("Choose a ringtone"))
664 .children(rows)
665 }
666
667 fn devices_section(&self, cx: &mut Context<Self>) -> Div {
668 let view = cx.entity();
669 let camera_label = self
670 .cameras
671 .iter()
672 .find(|entry| entry.choice == self.camera)
673 .map_or(DEFAULT_CAMERA_LABEL.to_owned(), |entry| entry.label.clone());
674 let cameras = self.cameras.clone();
675 let current_camera = self.camera.clone();
676 let camera_view = view.clone();
677 let backgrounds =
678 preview_backgrounds(&self.center.read(cx).app().read(cx).call_backgrounds);
679 let background_label = backgrounds
680 .iter()
681 .find(|(pick, _)| *pick == self.background)
682 .map_or("None".to_owned(), |(_, label)| label.clone());
683 let current_background = self.background.clone();
684 let mic = self.center.read(cx).app().read(cx).call_mic;
685 let noise_view = view.clone();
686 let music_view = view.clone();
687 let report_view = view.clone();
688 let report_on = self.center.read(cx).app().read(cx).call_report_enabled;
689 let effects = self.center.read(cx).app().read(cx).call_effects;
690 let image = self.preview.image(Instant::now());
691 let status = if self.preview_blocked {
692 CAMERA_IN_USE.to_owned()
693 } else {
694 self.preview.failure().map_or_else(
695 || {
696 self.preview
697 .fps()
698 .map_or("Starting camera...".to_owned(), |fps| {
699 format!("{fps:.0} fps")
700 })
701 },
702 |reason| format!("Camera could not start: {reason}"),
703 )
704 };
705 v_flex()
706 .w_full()
707 .child(control_row(
708 "Camera",
709 "Preview stays on this computer",
710 Button::new("camera-select")
711 .outline()
712 .w(px(SELECT_WIDTH))
713 .label(camera_label)
714 .icon(IconName::ChevronDown)
715 .dropdown_menu(move |menu, _, _| {
716 cameras.iter().fold(menu, |menu, entry| {
717 let (view, choice) = (camera_view.clone(), entry.choice.clone());
718 menu.item(
719 PopupMenuItem::new(entry.label.clone())
720 .checked(entry.choice == current_camera)
721 .on_click(move |_, _, cx| {
722 view.update(cx, |view, cx| {
723 view.select_camera(choice.clone(), cx)
724 })
725 }),
726 )
727 })
728 }),
729 ))
730 .child(control_row(
731 "Background",
732 "Blur or a picture behind you",
733 Button::new("background-select")
734 .outline()
735 .w(px(SELECT_WIDTH))
736 .label(background_label)
737 .icon(IconName::ChevronDown)
738 .dropdown_menu(move |menu, _, _| {
739 backgrounds.iter().fold(menu, |menu, (pick, label)| {
740 let (view, pick) = (view.clone(), pick.clone());
741 menu.item(
742 PopupMenuItem::new(label.clone())
743 .checked(pick == current_background)
744 .on_click(move |_, _, cx| {
745 view.update(cx, |view, cx| {
746 view.select_background(pick.clone(), cx)
747 })
748 }),
749 )
750 })
751 }),
752 ))
753 .child(control_row(
754 "Noise suppression",
755 if mic.music_mode {
756 "Off while music mode is on"
757 } else {
758 "Echo, hum and background noise"
759 },
760 Button::new("noise-suppression-select")
761 .outline()
762 .w(px(SELECT_WIDTH))
763 .label(mic.noise_suppression.label())
764 .icon(IconName::ChevronDown)
765 .disabled(mic.music_mode)
766 .dropdown_menu(move |menu, _, _| {
767 NoiseSuppression::ALL.iter().fold(menu, |menu, level| {
768 let (view, level) = (noise_view.clone(), *level);
769 menu.item(
770 PopupMenuItem::new(level.label())
771 .checked(level == mic.noise_suppression)
772 .on_click(move |_, _, cx| {
773 view.update(cx, |view, cx| {
774 view.set_mic(
775 MicSettings {
776 noise_suppression: level,
777 ..mic
778 },
779 cx,
780 )
781 })
782 }),
783 )
784 })
785 }),
786 ))
787 .child(
788 control_row(
789 "Music mode",
790 "Keeps echo cancellation, turns off the rest",
791 switch(mic.music_mode),
792 )
793 .id("music-mode-row")
794 .cursor_pointer()
795 .hover(|row| row.bg(theme::row_hover()))
796 .on_click(move |_, _, cx| {
797 music_view.update(cx, |view, cx| {
798 view.set_mic(
799 MicSettings {
800 music_mode: !mic.music_mode,
801 ..mic
802 },
803 cx,
804 )
805 })
806 }),
807 )
808 .child(
809 control_row(
810 "Save a test report after each call",
811 "Pseudonymized, stays on this computer",
812 switch(report_on),
813 )
814 .id("call-report-row")
815 .cursor_pointer()
816 .hover(|row| row.bg(theme::row_hover()))
817 .on_click(move |_, _, cx| {
818 report_view.update(cx, |view, cx| view.set_report_enabled(!report_on, cx))
819 }),
820 )
821 .child(
822 v_flex()
823 .w_full()
824 .px(px(20.))
825 .pt(px(8.))
826 .gap(px(8.))
827 .child(
828 div()
829 .w(px(PREVIEW_WIDTH))
830 .h(px(PREVIEW_HEIGHT))
831 .flex()
832 .items_center()
833 .justify_center()
834 .overflow_hidden()
835 .rounded(px(PREVIEW_RADIUS))
836 .bg(theme::surface())
837 .children(image.map(|image| {
838 img(ImageSource::Render(image))
839 .size_full()
840 .object_fit(ObjectFit::Cover)
841 .rounded(px(PREVIEW_RADIUS))
842 })),
843 )
844 .child(
845 div()
846 .text_size(px(12.))
847 .text_color(theme::text_muted())
848 .child(status),
849 ),
850 )
851 .child(
852 v_flex()
853 .id("camera-effects")
854 .w_full()
855 .pt(px(8.))
856 .child(self.effect_row(
857 "effect-mirror",
858 "Mirror my video",
859 effects.mirror,
860 |effects| effects.mirror = !effects.mirror,
861 cx,
862 ))
863 .child(self.effect_row(
864 "effect-framing",
865 "Auto framing",
866 effects.auto_framing,
867 |effects| effects.auto_framing = !effects.auto_framing,
868 cx,
869 ))
870 .child(self.effect_row(
871 "effect-brightness",
872 "Adjust brightness",
873 effects.adjust_brightness,
874 |effects| effects.adjust_brightness = !effects.adjust_brightness,
875 cx,
876 ))
877 .child(self.effect_row(
878 "effect-soft-focus",
879 "Soft focus",
880 effects.soft_focus,
881 |effects| effects.soft_focus = !effects.soft_focus,
882 cx,
883 ))
884 .when(effects.soft_focus, |column| {
885 column.child(self.strength_row(effects.soft_focus_strength, cx))
886 }),
887 )
888 }
889 }
890
891 impl Render for SettingsView {
892 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
893 let view = cx.entity();
894 let tabs = h_flex().w_full().px(px(20.)).gap(px(8.)).children(
895 Section::ALL.map(|section| section_tab(section, section == self.section, view.clone())),
896 );
897 let body = match self.section {
898 Section::Notifications => div()
899 .id("notifications-scroll")
900 .flex_1()
901 .min_h(px(0.))
902 .overflow_y_scroll()
903 .child(self.notifications_section(cx))
904 .into_any_element(),
905 Section::Calls => self.calls_section(cx).into_any_element(),
906 Section::Devices => div()
907 .id("devices-scroll")
908 .flex_1()
909 .min_h(px(0.))
910 .overflow_y_scroll()
911 .child(self.devices_section(cx))
912 .into_any_element(),
913 Section::Agents => div()
914 .id("agents-scroll")
915 .flex_1()
916 .min_h(px(0.))
917 .overflow_y_scroll()
918 .children(self.agents.clone())
919 .into_any_element(),
920 Section::Mcp => self.mcp.clone().into_any_element(),
921 };
922 v_flex()
923 .size_full()
924 .bg(theme::background())
925 .pt(px(12.))
926 .child(tabs)
927 .child(body)
928 }
929 }
930
931 impl SettingsView {
932 fn notifications_section(&self, cx: &App) -> Div {
933 let mut current = self.center.read(cx).settings().clone();
934 let corner = current.corner;
935 let sounds = current.sounds.clone();
936 let rows: Vec<Stateful<Div>> = ROWS
937 .iter()
938 .map(|row| {
939 let on = *(row.field)(&mut current);
940 self.switch_row(row, on)
941 })
942 .collect();
943 let call_sound_rows: Vec<Stateful<Div>> = CALL_SOUND_ROWS
944 .iter()
945 .map(|row| {
946 let on = *(row.field)(&mut current);
947 self.switch_row(row, on)
948 })
949 .collect();
950 let position_center = self.center.clone();
951 let test_center = self.center.clone();
952 v_flex()
953 .w_full()
954 .pt(px(8.))
955 .children(rows)
956 .child(control_row(
957 "Position",
958 "Corner of the main screen",
959 button(corner.label()).on_click(move |_, _, cx| {
960 position_center.update(cx, |center, cx| {
961 center.update_settings(cx, |settings| {
962 settings.corner = settings.corner.next()
963 })
964 });
965 }),
966 ))
967 .child(heading("Sound"))
968 .child(self.switch_row(&NOTIFICATION_SOUND_ROW, sounds.notification_sound))
969 .child(self.alert_sound_row(
970 ("notification-sound", "notification-sound-preview"),
971 "Notification sound",
972 &AlertSound::NORMAL,
973 sounds.notification_sound_type,
974 sounds.notification_sound,
975 |settings| &mut settings.sounds.notification_sound_type,
976 ))
977 .child(self.switch_row(&URGENT_SOUND_ROW, sounds.urgent_sound))
978 .child(self.alert_sound_row(
979 ("urgent-sound", "urgent-sound-preview"),
980 "Urgent sound",
981 &AlertSound::URGENT,
982 sounds.urgent_sound_type,
983 sounds.urgent_sound,
984 |settings| &mut settings.sounds.urgent_sound_type,
985 ))
986 .children(call_sound_rows)
987 .child(h_flex().w_full().px(px(20.)).py(px(12.)).child(
988 button("Send test notification").on_click(move |_, _, cx| {
989 test_center.update(cx, |center, cx| center.send_test_notification(cx));
990 }),
991 ))
992 }
993 }
994
995 fn ringtone_ids(call_type: RingtoneCallType) -> (&'static str, &'static str) {
996 match call_type {
997 RingtoneCallType::Regular => ("ringtone-regular", "ringtone-regular-preview"),
998 RingtoneCallType::CallGroup => ("ringtone-call-group", "ringtone-call-group-preview"),
999 RingtoneCallType::CallQueue => ("ringtone-call-queue", "ringtone-call-queue-preview"),
1000 RingtoneCallType::Delegate => ("ringtone-delegate", "ringtone-delegate-preview"),
1001 }
1002 }
@@ -1,1002 +0,0 @@
1use std::time::{Duration, Instant};
2
3use calling::camera::{DEFAULT_CAMERA_LABEL, list_cameras};
4use calling::{CameraEffects, DeviceChoice, DeviceEntry, MicSettings, NoiseSuppression, camera_entries};
5use gpui_kit::assets::IconName;
6use gpui_kit::component::{
7 button::Button,
8 h_flex,
9 menu::{DropdownMenu as _, PopupMenuItem},
10 v_flex,
11};
12use gpui_kit::base::Disableable as _;
13use gpui_kit::prelude::FluentBuilder as _;
14use gpui_kit::*;
15
16use super::center::NotificationCenter;
17use super::sounds::{AlertSound, Ringtone, RingtoneCallType};
18use super::rules::Settings;
19use super::settings_mcp::McpView;
20use crate::agents::AgentsSettings;
21use crate::app_state::AppState;
22use crate::call::{BackgroundPick, CameraPreview, preview_backgrounds};
23use crate::theme;
24
25const FPS_TICK: Duration = Duration::from_millis(500);
26const SELECT_WIDTH: f32 = 170.;
27const SOUND_SELECT_WIDTH: f32 = 124.;
28const PREVIEW_WIDTH: f32 = 380.;
29const PREVIEW_HEIGHT: f32 = 214.;
30const PREVIEW_RADIUS: f32 = 10.;
31const SOFT_FOCUS_LEVELS: [(&str, u8); 3] = [("Low", 25), ("Medium", 50), ("High", 75)];
32const CAMERA_IN_USE: &str = "Camera is in use by the call";
33
34fn camera_in_call(state: &AppState) -> bool {
35 state.call.is_some()
36}
37
38#[derive(Clone, Copy, PartialEq, Eq)]
39pub(super) enum Section {
40 Notifications,
41 Calls,
42 Devices,
43 Agents,
44 Mcp,
45}
46
47impl Section {
48 const ALL: [Section; 5] = [
49 Section::Notifications,
50 Section::Calls,
51 Section::Devices,
52 Section::Agents,
53 Section::Mcp,
54 ];
55
56 fn label(self) -> &'static str {
57 match self {
58 Section::Notifications => "Notifications",
59 Section::Calls => "Calls",
60 Section::Devices => "Devices",
61 Section::Agents => "Agents",
62 Section::Mcp => "MCP",
63 }
64 }
65}
66
67type Accessor = fn(&mut Settings) -> &mut bool;
68
69struct Row {
70 title: &'static str,
71 detail: &'static str,
72 field: Accessor,
73}
74
75const ROWS: [Row; 5] = [
76 Row {
77 title: "Mentions only",
78 detail: "Direct messages and @mentions",
79 field: |settings| &mut settings.mentions_only,
80 },
81 Row {
82 title: "Show preview",
83 detail: "Off: only \"New message\"",
84 field: |settings| &mut settings.preview,
85 },
86 Row {
87 title: "Flash taskbar",
88 detail: "On new messages, until you open the window",
89 field: |settings| &mut settings.flash,
90 },
91 Row {
92 title: "Mute notifications during calls and meetings",
93 detail: "No message toasts while a call is active",
94 field: |settings| &mut settings.mute_in_calls,
95 },
96 Row {
97 title: "Minimize to tray on close",
98 detail: "The title bar X hides the window",
99 field: |settings| &mut settings.close_to_tray,
100 },
101];
102
103const NOTIFICATION_SOUND_ROW: Row = Row {
104 title: "Play sounds with notifications",
105 detail: "",
106 field: |settings| &mut settings.sounds.notification_sound,
107};
108
109const URGENT_SOUND_ROW: Row = Row {
110 title: "Play sounds with urgent and priority contact notifications",
111 detail: "",
112 field: |settings| &mut settings.sounds.urgent_sound,
113};
114
115const CALL_SOUND_ROWS: [Row; 2] = [
116 Row {
117 title: "Play sounds with incoming calls, requests to join, and meeting start notifications",
118 detail: "",
119 field: |settings| &mut settings.sounds.call_and_meeting_sound,
120 },
121 Row {
122 title: "Play sounds when I'm busy or in a meeting",
123 detail: "",
124 field: |settings| &mut settings.sounds.sound_when_busy,
125 },
126];
127
128type SoundAccessor = fn(&mut Settings) -> &mut AlertSound;
129
130pub struct SettingsView {
131 center: Entity<NotificationCenter>,
132 section: Section,
133 mcp: Entity<McpView>,
134 agents: Option<Entity<AgentsSettings>>,
135 preview: CameraPreview,
136 cameras: Vec<DeviceEntry>,
137 cameras_requested: bool,
138 camera: DeviceChoice,
139 background: BackgroundPick,
140 preview_blocked: bool,
141 _subscription: Subscription,
142 _app_subscription: Subscription,
143 _release: Subscription,
144}
145
146impl SettingsView {
147 pub const WIDTH: f32 = 420.;
148 pub const HEIGHT: f32 = 680.;
149
150 pub fn new(
151 center: Entity<NotificationCenter>,
152 section: Section,
153 window: &mut Window,
154 cx: &mut Context<Self>,
155 ) -> Self {
156 let subscription = cx.observe(&center, |_, _, cx| cx.notify());
157 let app = center.read(cx).app().clone();
158 let app_subscription = cx.observe(&app, |view, _, cx| view.sync_preview_block(cx));
159 let release = cx.on_release(|view, cx| view.preview.stop(cx));
160 let (preview, mut updates) = CameraPreview::new();
161 let mcp = cx.new(|cx| McpView::new(app.clone(), window, cx));
162 let state = app.read(cx);
163 let camera = state.call_camera.clone();
164 preview.set_effects(state.call_effects);
165 let preview_blocked = camera_in_call(state);
166 let background = Some(state.call_background.clone())
167 .filter(|pick| {
168 preview_backgrounds(&state.call_backgrounds)
169 .iter()
170 .any(|(known, _)| known == pick)
171 })
172 .unwrap_or_default();
173 cx.spawn(async move |this, cx| {
174 while updates.recv().await.is_some() {
175 if this.update(cx, |view, cx| view.take_frames(cx)).is_err() {
176 return;
177 }
178 }
179 })
180 .detach();
181 cx.spawn(async move |this, cx| {
182 loop {
183 cx.background_executor().timer(FPS_TICK).await;
184 if this.update(cx, |view, cx| view.tick(cx)).is_err() {
185 break;
186 }
187 }
188 })
189 .detach();
190 let agents =
191 crate::agents::runs_handle(cx).map(|runs| cx.new(|cx| AgentsSettings::new(runs, cx)));
192 SettingsView {
193 center,
194 section,
195 mcp,
196 agents,
197 preview,
198 cameras: camera_entries(&[]),
199 cameras_requested: false,
200 camera,
201 background,
202 preview_blocked,
203 _subscription: subscription,
204 _app_subscription: app_subscription,
205 _release: release,
206 }
207 }
208
209 fn take_frames(&mut self, cx: &mut Context<Self>) {
210 self.preview.take_frames(cx);
211 cx.notify();
212 }
213
214 fn tick(&mut self, cx: &mut Context<Self>) {
215 if self.section == Section::Devices {
216 self.preview.tick(Instant::now());
217 cx.notify();
218 }
219 }
220
221 pub(super) fn select_section(&mut self, section: Section, cx: &mut Context<Self>) {
222 if self.section == section {
223 return;
224 }
225 self.section = section;
226 match section {
227 Section::Devices => {
228 self.load_cameras(cx);
229 self.apply_background(cx);
230 self.preview
231 .set_effects(self.center.read(cx).app().read(cx).call_effects);
232 self.preview_blocked = camera_in_call(self.center.read(cx).app().read(cx));
233 self.start_preview();
234 }
235 Section::Notifications | Section::Calls | Section::Agents | Section::Mcp => {
236 self.preview.stop(cx)
237 }
238 }
239 cx.notify();
240 }
241
242 fn load_cameras(&mut self, cx: &mut Context<Self>) {
243 if std::mem::replace(&mut self.cameras_requested, true) {
244 return;
245 }
246 cx.spawn(async move |this, cx| {
247 let cameras = cx
248 .background_executor()
249 .spawn(async { list_cameras() })
250 .await;
251 this.update(cx, |view, cx| {
252 view.cameras = camera_entries(&cameras);
253 cx.notify();
254 })
255 .ok();
256 })
257 .detach();
258 }
259
260 fn start_preview(&mut self) {
261 if !self.preview_blocked {
262 self.preview.start(&self.camera);
263 }
264 }
265
266 fn sync_preview_block(&mut self, cx: &mut Context<Self>) {
267 let blocked = camera_in_call(self.center.read(cx).app().read(cx));
268 if blocked == self.preview_blocked {
269 return;
270 }
271 self.preview_blocked = blocked;
272 if blocked {
273 self.preview.stop(cx);
274 } else if self.section == Section::Devices {
275 self.start_preview();
276 }
277 cx.notify();
278 }
279
280 fn select_camera(&mut self, camera: DeviceChoice, cx: &mut Context<Self>) {
281 self.camera = camera.clone();
282 let app = self.center.read(cx).app().clone();
283 app.update(cx, |state, cx| state.select_call_camera(camera, cx));
284 self.start_preview();
285 cx.notify();
286 }
287
288 fn set_mic(&mut self, settings: MicSettings, cx: &mut Context<Self>) {
289 let app = self.center.read(cx).app().clone();
290 app.update(cx, |state, cx| state.set_call_mic(settings, cx));
291 cx.notify();
292 }
293
294 fn set_report_enabled(&mut self, on: bool, cx: &mut Context<Self>) {
295 let app = self.center.read(cx).app().clone();
296 app.update(cx, |state, cx| state.set_call_report_enabled(on, cx));
297 cx.notify();
298 }
299
300 fn change_effects(&mut self, change: fn(&mut CameraEffects), cx: &mut Context<Self>) {
301 let app = self.center.read(cx).app().clone();
302 let mut effects = app.read(cx).call_effects;
303 change(&mut effects);
304 self.preview.set_effects(effects);
305 app.update(cx, |state, cx| state.set_call_effects(effects, cx));
306 cx.notify();
307 }
308
309 fn effect_row(
310 &self,
311 id: &'static str,
312 title: &'static str,
313 on: bool,
314 change: fn(&mut CameraEffects),
315 cx: &mut Context<Self>,
316 ) -> Stateful<Div> {
317 let view = cx.entity();
318 h_flex()
319 .id(id)
320 .w_full()
321 .px(px(20.))
322 .py(px(6.))
323 .gap(px(12.))
324 .items_center()
325 .cursor_pointer()
326 .hover(|row| row.bg(theme::row_hover()))
327 .on_click(move |_, _, cx| view.update(cx, |view, cx| view.change_effects(change, cx)))
328 .child(
329 div()
330 .flex_1()
331 .text_size(px(14.))
332 .font_weight(FontWeight::SEMIBOLD)
333 .text_color(theme::text())
334 .child(title),
335 )
336 .child(switch(on))
337 }
338
339 fn strength_row(&self, strength: u8, cx: &mut Context<Self>) -> Stateful<Div> {
340 let levels = SOFT_FOCUS_LEVELS.map(|(label, level)| {
341 let view = cx.entity();
342 let app = self.center.read(cx).app().clone();
343 button(label)
344 .when(strength == level, |button| {
345 button.bg(theme::accent()).text_color(theme::on_accent())
346 })
347 .on_click(move |_, _, cx| {
348 app.update(cx, |state, cx| {
349 let effects = CameraEffects {
350 soft_focus_strength: level,
351 ..state.call_effects
352 };
353 state.set_call_effects(effects, cx);
354 view.update(cx, |view, cx| {
355 view.preview.set_effects(effects);
356 cx.notify();
357 });
358 })
359 })
360 });
361 h_flex()
362 .id("effect-soft-focus-strength")
363 .w_full()
364 .px(px(20.))
365 .py(px(6.))
366 .gap(px(8.))
367 .items_center()
368 .child(
369 div()
370 .flex_1()
371 .text_size(px(12.))
372 .text_color(theme::text_muted())
373 .child("Soft focus strength"),
374 )
375 .children(levels)
376 }
377
378 fn select_background(&mut self, pick: BackgroundPick, cx: &mut Context<Self>) {
379 self.background = pick.clone();
380 let app = self.center.read(cx).app().clone();
381 app.update(cx, |state, cx| state.set_call_background(pick, cx));
382 self.apply_background(cx);
383 cx.notify();
384 }
385
386 fn apply_background(&self, cx: &App) {
387 let state = self.center.read(cx).app().read(cx);
388 if let Some(choice) = state.call_backgrounds.choice_for(&self.background) {
389 self.preview.set_background(choice);
390 }
391 }
392}
393
394pub(crate) fn switch(on: bool) -> Div {
395 div()
396 .w(px(36.))
397 .h(px(20.))
398 .flex_none()
399 .rounded_full()
400 .relative()
401 .bg(if on {
402 theme::accent()
403 } else {
404 theme::border_strong()
405 })
406 .child(
407 div()
408 .absolute()
409 .top(px(2.))
410 .left(px(if on { 18. } else { 2. }))
411 .size(px(16.))
412 .rounded_full()
413 .bg(theme::text()),
414 )
415}
416
417fn button(label: &'static str) -> Stateful<Div> {
418 button_with_id(label, label)
419}
420
421fn button_with_id(id: &'static str, label: &'static str) -> Stateful<Div> {
422 div()
423 .id(id)
424 .h(px(32.))
425 .px(px(14.))
426 .flex()
427 .items_center()
428 .rounded(px(8.))
429 .border_1()
430 .border_color(theme::border_strong())
431 .cursor_pointer()
432 .text_size(px(13.))
433 .font_weight(FontWeight::SEMIBOLD)
434 .text_color(theme::text())
435 .hover(|button| button.bg(theme::row_hover()))
436 .child(label)
437}
438
439fn titled(title: &'static str, detail: impl Into<SharedString>) -> Div {
440 titled_with(title, detail, theme::text_muted())
441}
442
443pub(super) fn titled_with(
444 title: &'static str,
445 detail: impl Into<SharedString>,
446 detail_color: Hsla,
447) -> Div {
448 v_flex()
449 .flex_1()
450 .min_w(px(0.))
451 .child(
452 div()
453 .text_size(px(14.))
454 .font_weight(FontWeight::SEMIBOLD)
455 .text_color(theme::text())
456 .child(title),
457 )
458 .map(|column| {
459 let detail = detail.into();
460 if detail.is_empty() {
461 return column;
462 }
463 column.child(
464 div()
465 .text_size(px(12.))
466 .text_color(detail_color)
467 .child(detail),
468 )
469 })
470}
471
472pub(super) fn control_row(
473 title: &'static str,
474 detail: impl Into<SharedString>,
475 control: impl IntoElement,
476) -> Div {
477 h_flex()
478 .w_full()
479 .px(px(20.))
480 .py(px(10.))
481 .gap(px(12.))
482 .items_center()
483 .child(titled(title, detail))
484 .child(control)
485}
486
487fn section_tab(section: Section, active: bool, view: Entity<SettingsView>) -> Stateful<Div> {
488 div()
489 .id(section.label())
490 .h(px(32.))
491 .px(px(14.))
492 .flex()
493 .items_center()
494 .rounded(px(8.))
495 .cursor_pointer()
496 .text_size(px(13.))
497 .font_weight(FontWeight::SEMIBOLD)
498 .text_color(if active {
499 theme::on_accent()
500 } else {
501 theme::text()
502 })
503 .when(active, |tab| tab.bg(theme::accent()))
504 .when(!active, |tab| tab.hover(|tab| tab.bg(theme::row_hover())))
505 .child(section.label())
506 .on_click(move |_, _, cx| view.update(cx, |view, cx| view.select_section(section, cx)))
507}
508
509fn heading(title: &'static str) -> Div {
510 div()
511 .w_full()
512 .px(px(20.))
513 .pt(px(16.))
514 .pb(px(4.))
515 .text_size(px(12.))
516 .font_weight(FontWeight::SEMIBOLD)
517 .text_color(theme::text_muted())
518 .child(title)
519}
520
521fn picker(
522 id: &'static str,
523 label: &'static str,
524 disabled: bool,
525 menu_items: impl Fn() -> Vec<(&'static str, bool, Box<dyn Fn(&mut App)>)> + 'static,
526) -> impl IntoElement {
527 Button::new(id)
528 .outline()
529 .w(px(SOUND_SELECT_WIDTH))
530 .label(label)
531 .icon(IconName::ChevronDown)
532 .disabled(disabled)
533 .dropdown_menu(move |menu, _, _| {
534 menu_items()
535 .into_iter()
536 .fold(menu, |menu, (label, checked, choose)| {
537 menu.item(
538 PopupMenuItem::new(label)
539 .checked(checked)
540 .on_click(move |_, _, cx| choose(cx)),
541 )
542 })
543 })
544}
545
546impl SettingsView {
547 fn switch_row(&self, row: &Row, on: bool) -> Stateful<Div> {
548 let center = self.center.clone();
549 let field = row.field;
550 h_flex()
551 .id(row.title)
552 .w_full()
553 .px(px(20.))
554 .py(px(10.))
555 .gap(px(12.))
556 .items_center()
557 .cursor_pointer()
558 .hover(|row| row.bg(theme::row_hover()))
559 .on_click(move |_, _, cx| {
560 center.update(cx, |center, cx| {
561 center.update_settings(cx, |settings| {
562 let value = field(settings);
563 *value = !*value;
564 })
565 });
566 })
567 .child(titled(row.title, row.detail))
568 .child(switch(on))
569 }
570
571 fn alert_sound_row(
572 &self,
573 (id, preview_id): (&'static str, &'static str),
574 title: &'static str,
575 options: &'static [AlertSound],
576 current: AlertSound,
577 enabled: bool,
578 field: SoundAccessor,
579 ) -> Div {
580 let center = self.center.clone();
581 let preview_center = self.center.clone();
582 let choices = move || {
583 options
584 .iter()
585 .map(|sound| {
586 let (center, sound) = (center.clone(), *sound);
587 let choose: Box<dyn Fn(&mut App)> = Box::new(move |cx| {
588 center.update(cx, |center, cx| {
589 center.update_settings(cx, |settings| *field(settings) = sound);
590 center.preview_sound(sound.file_name(), cx);
591 })
592 });
593 (sound.label(), sound == current, choose)
594 })
595 .collect()
596 };
597 control_row(
598 title,
599 "",
600 h_flex()
601 .gap(px(8.))
602 .items_center()
603 .child(picker(id, current.label(), !enabled, choices))
604 .child(button_with_id(preview_id, "Preview").on_click(
605 move |_, _, cx| {
606 preview_center
607 .update(cx, |center, cx| center.preview_sound(current.file_name(), cx))
608 },
609 )),
610 )
611 }
612
613 fn ringtone_row(&self, call_type: RingtoneCallType, current: Ringtone) -> Div {
614 let center = self.center.clone();
615 let preview_center = self.center.clone();
616 let choices = move || {
617 Ringtone::ALL
618 .iter()
619 .map(|ringtone| {
620 let (center, ringtone) = (center.clone(), *ringtone);
621 let choose: Box<dyn Fn(&mut App)> = Box::new(move |cx| {
622 center.update(cx, |center, cx| {
623 center.update_settings(cx, |settings| {
624 settings.sounds.ringtones.set(call_type, ringtone)
625 });
626 center.preview_sound(ringtone.file_name(), cx);
627 })
628 });
629 (ringtone.label(), ringtone == current, choose)
630 })
631 .collect()
632 };
633 let (id, preview_id) = ringtone_ids(call_type);
634 control_row(
635 call_type.label(),
636 "",
637 h_flex()
638 .gap(px(8.))
639 .items_center()
640 .child(picker(id, current.label(), false, choices))
641 .child(button_with_id(preview_id, "Preview").on_click(
642 move |_, _, cx| {
643 preview_center.update(cx, |center, cx| {
644 center.preview_sound(current.file_name(), cx)
645 })
646 },
647 )),
648 )
649 }
650
651 fn calls_section(&self, cx: &App) -> Div {
652 let ringtones = self.center.read(cx).settings().sounds.ringtones;
653 let rows = RingtoneCallType::ALL
654 .into_iter()
655 .filter(|call_type| {
656 *call_type == RingtoneCallType::Regular
657 || ringtones.get(*call_type) != Ringtone::Ring
658 })
659 .map(|call_type| self.ringtone_row(call_type, ringtones.get(call_type)));
660 v_flex()
661 .w_full()
662 .pt(px(8.))
663 .child(heading("Choose a ringtone"))
664 .children(rows)
665 }
666
667 fn devices_section(&self, cx: &mut Context<Self>) -> Div {
668 let view = cx.entity();
669 let camera_label = self
670 .cameras
671 .iter()
672 .find(|entry| entry.choice == self.camera)
673 .map_or(DEFAULT_CAMERA_LABEL.to_owned(), |entry| entry.label.clone());
674 let cameras = self.cameras.clone();
675 let current_camera = self.camera.clone();
676 let camera_view = view.clone();
677 let backgrounds =
678 preview_backgrounds(&self.center.read(cx).app().read(cx).call_backgrounds);
679 let background_label = backgrounds
680 .iter()
681 .find(|(pick, _)| *pick == self.background)
682 .map_or("None".to_owned(), |(_, label)| label.clone());
683 let current_background = self.background.clone();
684 let mic = self.center.read(cx).app().read(cx).call_mic;
685 let noise_view = view.clone();
686 let music_view = view.clone();
687 let report_view = view.clone();
688 let report_on = self.center.read(cx).app().read(cx).call_report_enabled;
689 let effects = self.center.read(cx).app().read(cx).call_effects;
690 let image = self.preview.image(Instant::now());
691 let status = if self.preview_blocked {
692 CAMERA_IN_USE.to_owned()
693 } else {
694 self.preview.failure().map_or_else(
695 || {
696 self.preview
697 .fps()
698 .map_or("Starting camera...".to_owned(), |fps| {
699 format!("{fps:.0} fps")
700 })
701 },
702 |reason| format!("Camera could not start: {reason}"),
703 )
704 };
705 v_flex()
706 .w_full()
707 .child(control_row(
708 "Camera",
709 "Preview stays on this computer",
710 Button::new("camera-select")
711 .outline()
712 .w(px(SELECT_WIDTH))
713 .label(camera_label)
714 .icon(IconName::ChevronDown)
715 .dropdown_menu(move |menu, _, _| {
716 cameras.iter().fold(menu, |menu, entry| {
717 let (view, choice) = (camera_view.clone(), entry.choice.clone());
718 menu.item(
719 PopupMenuItem::new(entry.label.clone())
720 .checked(entry.choice == current_camera)
721 .on_click(move |_, _, cx| {
722 view.update(cx, |view, cx| {
723 view.select_camera(choice.clone(), cx)
724 })
725 }),
726 )
727 })
728 }),
729 ))
730 .child(control_row(
731 "Background",
732 "Blur or a picture behind you",
733 Button::new("background-select")
734 .outline()
735 .w(px(SELECT_WIDTH))
736 .label(background_label)
737 .icon(IconName::ChevronDown)
738 .dropdown_menu(move |menu, _, _| {
739 backgrounds.iter().fold(menu, |menu, (pick, label)| {
740 let (view, pick) = (view.clone(), pick.clone());
741 menu.item(
742 PopupMenuItem::new(label.clone())
743 .checked(pick == current_background)
744 .on_click(move |_, _, cx| {
745 view.update(cx, |view, cx| {
746 view.select_background(pick.clone(), cx)
747 })
748 }),
749 )
750 })
751 }),
752 ))
753 .child(control_row(
754 "Noise suppression",
755 if mic.music_mode {
756 "Off while music mode is on"
757 } else {
758 "Echo, hum and background noise"
759 },
760 Button::new("noise-suppression-select")
761 .outline()
762 .w(px(SELECT_WIDTH))
763 .label(mic.noise_suppression.label())
764 .icon(IconName::ChevronDown)
765 .disabled(mic.music_mode)
766 .dropdown_menu(move |menu, _, _| {
767 NoiseSuppression::ALL.iter().fold(menu, |menu, level| {
768 let (view, level) = (noise_view.clone(), *level);
769 menu.item(
770 PopupMenuItem::new(level.label())
771 .checked(level == mic.noise_suppression)
772 .on_click(move |_, _, cx| {
773 view.update(cx, |view, cx| {
774 view.set_mic(
775 MicSettings {
776 noise_suppression: level,
777 ..mic
778 },
779 cx,
780 )
781 })
782 }),
783 )
784 })
785 }),
786 ))
787 .child(
788 control_row(
789 "Music mode",
790 "Keeps echo cancellation, turns off the rest",
791 switch(mic.music_mode),
792 )
793 .id("music-mode-row")
794 .cursor_pointer()
795 .hover(|row| row.bg(theme::row_hover()))
796 .on_click(move |_, _, cx| {
797 music_view.update(cx, |view, cx| {
798 view.set_mic(
799 MicSettings {
800 music_mode: !mic.music_mode,
801 ..mic
802 },
803 cx,
804 )
805 })
806 }),
807 )
808 .child(
809 control_row(
810 "Save a test report after each call",
811 "Pseudonymized, stays on this computer",
812 switch(report_on),
813 )
814 .id("call-report-row")
815 .cursor_pointer()
816 .hover(|row| row.bg(theme::row_hover()))
817 .on_click(move |_, _, cx| {
818 report_view.update(cx, |view, cx| view.set_report_enabled(!report_on, cx))
819 }),
820 )
821 .child(
822 v_flex()
823 .w_full()
824 .px(px(20.))
825 .pt(px(8.))
826 .gap(px(8.))
827 .child(
828 div()
829 .w(px(PREVIEW_WIDTH))
830 .h(px(PREVIEW_HEIGHT))
831 .flex()
832 .items_center()
833 .justify_center()
834 .overflow_hidden()
835 .rounded(px(PREVIEW_RADIUS))
836 .bg(theme::surface())
837 .children(image.map(|image| {
838 img(ImageSource::Render(image))
839 .size_full()
840 .object_fit(ObjectFit::Cover)
841 .rounded(px(PREVIEW_RADIUS))
842 })),
843 )
844 .child(
845 div()
846 .text_size(px(12.))
847 .text_color(theme::text_muted())
848 .child(status),
849 ),
850 )
851 .child(
852 v_flex()
853 .id("camera-effects")
854 .w_full()
855 .pt(px(8.))
856 .child(self.effect_row(
857 "effect-mirror",
858 "Mirror my video",
859 effects.mirror,
860 |effects| effects.mirror = !effects.mirror,
861 cx,
862 ))
863 .child(self.effect_row(
864 "effect-framing",
865 "Auto framing",
866 effects.auto_framing,
867 |effects| effects.auto_framing = !effects.auto_framing,
868 cx,
869 ))
870 .child(self.effect_row(
871 "effect-brightness",
872 "Adjust brightness",
873 effects.adjust_brightness,
874 |effects| effects.adjust_brightness = !effects.adjust_brightness,
875 cx,
876 ))
877 .child(self.effect_row(
878 "effect-soft-focus",
879 "Soft focus",
880 effects.soft_focus,
881 |effects| effects.soft_focus = !effects.soft_focus,
882 cx,
883 ))
884 .when(effects.soft_focus, |column| {
885 column.child(self.strength_row(effects.soft_focus_strength, cx))
886 }),
887 )
888 }
889}
890
891impl Render for SettingsView {
892 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
893 let view = cx.entity();
894 let tabs = h_flex().w_full().px(px(20.)).gap(px(8.)).children(
895 Section::ALL.map(|section| section_tab(section, section == self.section, view.clone())),
896 );
897 let body = match self.section {
898 Section::Notifications => div()
899 .id("notifications-scroll")
900 .flex_1()
901 .min_h(px(0.))
902 .overflow_y_scroll()
903 .child(self.notifications_section(cx))
904 .into_any_element(),
905 Section::Calls => self.calls_section(cx).into_any_element(),
906 Section::Devices => div()
907 .id("devices-scroll")
908 .flex_1()
909 .min_h(px(0.))
910 .overflow_y_scroll()
911 .child(self.devices_section(cx))
912 .into_any_element(),
913 Section::Agents => div()
914 .id("agents-scroll")
915 .flex_1()
916 .min_h(px(0.))
917 .overflow_y_scroll()
918 .children(self.agents.clone())
919 .into_any_element(),
920 Section::Mcp => self.mcp.clone().into_any_element(),
921 };
922 v_flex()
923 .size_full()
924 .bg(theme::background())
925 .pt(px(12.))
926 .child(tabs)
927 .child(body)
928 }
929}
930
931impl SettingsView {
932 fn notifications_section(&self, cx: &App) -> Div {
933 let mut current = self.center.read(cx).settings().clone();
934 let corner = current.corner;
935 let sounds = current.sounds.clone();
936 let rows: Vec<Stateful<Div>> = ROWS
937 .iter()
938 .map(|row| {
939 let on = *(row.field)(&mut current);
940 self.switch_row(row, on)
941 })
942 .collect();
943 let call_sound_rows: Vec<Stateful<Div>> = CALL_SOUND_ROWS
944 .iter()
945 .map(|row| {
946 let on = *(row.field)(&mut current);
947 self.switch_row(row, on)
948 })
949 .collect();
950 let position_center = self.center.clone();
951 let test_center = self.center.clone();
952 v_flex()
953 .w_full()
954 .pt(px(8.))
955 .children(rows)
956 .child(control_row(
957 "Position",
958 "Corner of the main screen",
959 button(corner.label()).on_click(move |_, _, cx| {
960 position_center.update(cx, |center, cx| {
961 center.update_settings(cx, |settings| {
962 settings.corner = settings.corner.next()
963 })
964 });
965 }),
966 ))
967 .child(heading("Sound"))
968 .child(self.switch_row(&NOTIFICATION_SOUND_ROW, sounds.notification_sound))
969 .child(self.alert_sound_row(
970 ("notification-sound", "notification-sound-preview"),
971 "Notification sound",
972 &AlertSound::NORMAL,
973 sounds.notification_sound_type,
974 sounds.notification_sound,
975 |settings| &mut settings.sounds.notification_sound_type,
976 ))
977 .child(self.switch_row(&URGENT_SOUND_ROW, sounds.urgent_sound))
978 .child(self.alert_sound_row(
979 ("urgent-sound", "urgent-sound-preview"),
980 "Urgent sound",
981 &AlertSound::URGENT,
982 sounds.urgent_sound_type,
983 sounds.urgent_sound,
984 |settings| &mut settings.sounds.urgent_sound_type,
985 ))
986 .children(call_sound_rows)
987 .child(h_flex().w_full().px(px(20.)).py(px(12.)).child(
988 button("Send test notification").on_click(move |_, _, cx| {
989 test_center.update(cx, |center, cx| center.send_test_notification(cx));
990 }),
991 ))
992 }
993}
994
995fn ringtone_ids(call_type: RingtoneCallType) -> (&'static str, &'static str) {
996 match call_type {
997 RingtoneCallType::Regular => ("ringtone-regular", "ringtone-regular-preview"),
998 RingtoneCallType::CallGroup => ("ringtone-call-group", "ringtone-call-group-preview"),
999 RingtoneCallType::CallQueue => ("ringtone-call-queue", "ringtone-call-queue-preview"),
1000 RingtoneCallType::Delegate => ("ringtone-delegate", "ringtone-delegate-preview"),
1001 }
1002}
crates/app/src/settings/about.rs added +25 −0
@@ -0,0 +1,25 @@
1 use gpui_kit::component::v_flex;
2 use gpui_kit::*;
3
4 use super::rows::{caption, control_row, text_button};
5 use crate::{format, updater};
6
7 pub fn render() -> Div {
8 let build_id = updater::running_version();
9 let copied = build_id.to_owned();
10 v_flex()
11 .w_full()
12 .child(caption("RUSTY TEAMS"))
13 .child(control_row(
14 "Version",
15 format::short_version(build_id, env!("CARGO_PKG_VERSION")),
16 div(),
17 ))
18 .child(control_row(
19 "Build",
20 build_id.to_owned(),
21 text_button("settings-copy-build", "Copy").on_click(move |_, _, cx| {
22 cx.write_to_clipboard(ClipboardItem::new_string(copied.clone()))
23 }),
24 ))
25 }
@@ -0,0 +1,25 @@
1use gpui_kit::component::v_flex;
2use gpui_kit::*;
3
4use super::rows::{caption, control_row, text_button};
5use crate::{format, updater};
6
7pub fn render() -> Div {
8 let build_id = updater::running_version();
9 let copied = build_id.to_owned();
10 v_flex()
11 .w_full()
12 .child(caption("RUSTY TEAMS"))
13 .child(control_row(
14 "Version",
15 format::short_version(build_id, env!("CARGO_PKG_VERSION")),
16 div(),
17 ))
18 .child(control_row(
19 "Build",
20 build_id.to_owned(),
21 text_button("settings-copy-build", "Copy").on_click(move |_, _, cx| {
22 cx.write_to_clipboard(ClipboardItem::new_string(copied.clone()))
23 }),
24 ))
25}
crates/app/src/settings/calls.rs added +64 −0
@@ -0,0 +1,64 @@
1 use gpui_kit::component::{h_flex, v_flex};
2 use gpui_kit::*;
3
4 use super::rows::{Choice, caption, control_row, select, text_button};
5 use crate::notify::NotificationCenter;
6 use crate::notify::sounds::{Ringtone, RingtoneCallType};
7
8 pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {
9 let ringtones = center.read(cx).settings().sounds.ringtones;
10 let rows = RingtoneCallType::ALL
11 .into_iter()
12 .filter(|call_type| {
13 *call_type == RingtoneCallType::Regular || ringtones.get(*call_type) != Ringtone::Ring
14 })
15 .map(|call_type| ringtone_row(center, call_type, ringtones.get(call_type)));
16 v_flex().w_full().child(caption("RINGTONES")).children(rows)
17 }
18
19 fn ringtone_row(
20 center: &Entity<NotificationCenter>,
21 call_type: RingtoneCallType,
22 current: Ringtone,
23 ) -> Div {
24 let choices = Ringtone::ALL
25 .iter()
26 .map(|ringtone| {
27 let (center, ringtone) = (center.clone(), *ringtone);
28 Choice::new(ringtone.label(), ringtone == current, move |cx| {
29 center.update(cx, |center, cx| {
30 center.update_settings(cx, |settings| {
31 settings.sounds.ringtones.set(call_type, ringtone)
32 });
33 center.preview_sound(ringtone.file_name(), cx);
34 })
35 })
36 })
37 .collect();
38 let (id, preview_id) = ringtone_ids(call_type);
39 let preview_center = center.clone();
40 control_row(
41 call_type.label(),
42 "",
43 h_flex()
44 .gap(px(8.))
45 .items_center()
46 .child(select(id, current.label(), false, choices))
47 .child(
48 text_button(preview_id, "Preview").on_click(move |_, _, cx| {
49 preview_center.update(cx, |center, cx| {
50 center.preview_sound(current.file_name(), cx)
51 })
52 }),
53 ),
54 )
55 }
56
57 fn ringtone_ids(call_type: RingtoneCallType) -> (&'static str, &'static str) {
58 match call_type {
59 RingtoneCallType::Regular => ("ringtone-regular", "ringtone-regular-preview"),
60 RingtoneCallType::CallGroup => ("ringtone-call-group", "ringtone-call-group-preview"),
61 RingtoneCallType::CallQueue => ("ringtone-call-queue", "ringtone-call-queue-preview"),
62 RingtoneCallType::Delegate => ("ringtone-delegate", "ringtone-delegate-preview"),
63 }
64 }
@@ -0,0 +1,64 @@
1use gpui_kit::component::{h_flex, v_flex};
2use gpui_kit::*;
3
4use super::rows::{Choice, caption, control_row, select, text_button};
5use crate::notify::NotificationCenter;
6use crate::notify::sounds::{Ringtone, RingtoneCallType};
7
8pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {
9 let ringtones = center.read(cx).settings().sounds.ringtones;
10 let rows = RingtoneCallType::ALL
11 .into_iter()
12 .filter(|call_type| {
13 *call_type == RingtoneCallType::Regular || ringtones.get(*call_type) != Ringtone::Ring
14 })
15 .map(|call_type| ringtone_row(center, call_type, ringtones.get(call_type)));
16 v_flex().w_full().child(caption("RINGTONES")).children(rows)
17}
18
19fn ringtone_row(
20 center: &Entity<NotificationCenter>,
21 call_type: RingtoneCallType,
22 current: Ringtone,
23) -> Div {
24 let choices = Ringtone::ALL
25 .iter()
26 .map(|ringtone| {
27 let (center, ringtone) = (center.clone(), *ringtone);
28 Choice::new(ringtone.label(), ringtone == current, move |cx| {
29 center.update(cx, |center, cx| {
30 center.update_settings(cx, |settings| {
31 settings.sounds.ringtones.set(call_type, ringtone)
32 });
33 center.preview_sound(ringtone.file_name(), cx);
34 })
35 })
36 })
37 .collect();
38 let (id, preview_id) = ringtone_ids(call_type);
39 let preview_center = center.clone();
40 control_row(
41 call_type.label(),
42 "",
43 h_flex()
44 .gap(px(8.))
45 .items_center()
46 .child(select(id, current.label(), false, choices))
47 .child(
48 text_button(preview_id, "Preview").on_click(move |_, _, cx| {
49 preview_center.update(cx, |center, cx| {
50 center.preview_sound(current.file_name(), cx)
51 })
52 }),
53 ),
54 )
55}
56
57fn ringtone_ids(call_type: RingtoneCallType) -> (&'static str, &'static str) {
58 match call_type {
59 RingtoneCallType::Regular => ("ringtone-regular", "ringtone-regular-preview"),
60 RingtoneCallType::CallGroup => ("ringtone-call-group", "ringtone-call-group-preview"),
61 RingtoneCallType::CallQueue => ("ringtone-call-queue", "ringtone-call-queue-preview"),
62 RingtoneCallType::Delegate => ("ringtone-delegate", "ringtone-delegate-preview"),
63 }
64}
crates/app/src/settings/chats.rs added +30 −0
@@ -0,0 +1,30 @@
1 use gpui_kit::component::v_flex;
2 use gpui_kit::*;
3 use teams_core::ChatSection;
4
5 use super::rows::{caption, toggle_row};
6 use crate::app_state::AppState;
7 use crate::theme;
8
9 pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
10 let enabled = app
11 .read(cx)
12 .directory
13 .section_settings
14 .enabled(ChatSection::Muted);
15 let toggle_app = app.clone();
16 v_flex().w_full().child(caption("CHAT LIST")).child(
17 toggle_row(
18 "settings-muted-section",
19 "Show muted items in their own section",
20 "Read from your Teams account",
21 theme::text_muted(),
22 enabled,
23 )
24 .on_click(move |_, _, cx| {
25 toggle_app.update(cx, |state, cx| {
26 state.set_chat_section(ChatSection::Muted, !enabled, cx)
27 })
28 }),
29 )
30 }
@@ -0,0 +1,30 @@
1use gpui_kit::component::v_flex;
2use gpui_kit::*;
3use teams_core::ChatSection;
4
5use super::rows::{caption, toggle_row};
6use crate::app_state::AppState;
7use crate::theme;
8
9pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
10 let enabled = app
11 .read(cx)
12 .directory
13 .section_settings
14 .enabled(ChatSection::Muted);
15 let toggle_app = app.clone();
16 v_flex().w_full().child(caption("CHAT LIST")).child(
17 toggle_row(
18 "settings-muted-section",
19 "Show muted items in their own section",
20 "Read from your Teams account",
21 theme::text_muted(),
22 enabled,
23 )
24 .on_click(move |_, _, cx| {
25 toggle_app.update(cx, |state, cx| {
26 state.set_chat_section(ChatSection::Muted, !enabled, cx)
27 })
28 }),
29 )
30}
crates/app/src/settings/devices.rs added +525 −0
@@ -0,0 +1,525 @@
1 use std::time::{Duration, Instant};
2
3 use calling::camera::{DEFAULT_CAMERA_LABEL, list_cameras};
4 use calling::devices::{DeviceLists, list_devices, shared_factory};
5 use calling::{
6 CameraEffects, DeviceChoice, DeviceEntry, MicSettings, NoiseSuppression, camera_entries,
7 };
8 use gpui_kit::component::{h_flex, v_flex};
9 use gpui_kit::prelude::FluentBuilder as _;
10 use gpui_kit::*;
11
12 use super::rows::{Choice, caption, control_row, row, select, text_button, toggle_row};
13 use crate::app_state::AppState;
14 use crate::call::{BackgroundPick, CameraPreview, preview_backgrounds};
15 use crate::theme;
16 use crate::views::prejoin_view::demo_devices;
17
18 const FPS_TICK: Duration = Duration::from_millis(500);
19 const PREVIEW_WIDTH: f32 = 288.;
20 const PREVIEW_HEIGHT: f32 = 162.;
21 const PREVIEW_RADIUS: f32 = 10.;
22 const SOFT_FOCUS_LEVELS: [(&str, u8); 3] = [("Low", 25), ("Medium", 50), ("High", 75)];
23 const CAMERA_IN_USE: &str = "Camera is in use by the call";
24 const DEFAULT_DEVICE_LABEL: &str = "Default device";
25
26 struct Effect {
27 id: &'static str,
28 title: &'static str,
29 read: fn(&CameraEffects) -> bool,
30 flip: fn(&mut CameraEffects),
31 }
32
33 const EFFECTS: [Effect; 4] = [
34 Effect {
35 id: "effect-mirror",
36 title: "Mirror my video",
37 read: |effects| effects.mirror,
38 flip: |effects| effects.mirror = !effects.mirror,
39 },
40 Effect {
41 id: "effect-framing",
42 title: "Auto framing",
43 read: |effects| effects.auto_framing,
44 flip: |effects| effects.auto_framing = !effects.auto_framing,
45 },
46 Effect {
47 id: "effect-brightness",
48 title: "Adjust brightness",
49 read: |effects| effects.adjust_brightness,
50 flip: |effects| effects.adjust_brightness = !effects.adjust_brightness,
51 },
52 Effect {
53 id: "effect-soft-focus",
54 title: "Soft focus",
55 read: |effects| effects.soft_focus,
56 flip: |effects| effects.soft_focus = !effects.soft_focus,
57 },
58 ];
59
60 fn camera_in_call(state: &AppState) -> bool {
61 state.call.is_some()
62 }
63
64 fn label_of(entries: &[DeviceEntry], choice: &DeviceChoice, fallback: &str) -> String {
65 entries
66 .iter()
67 .find(|entry| &entry.choice == choice)
68 .map_or_else(|| fallback.to_owned(), |entry| entry.label.clone())
69 }
70
71 pub struct DevicesView {
72 app: Entity<AppState>,
73 preview: CameraPreview,
74 cameras: Vec<DeviceEntry>,
75 audio_devices: DeviceLists,
76 camera: DeviceChoice,
77 background: BackgroundPick,
78 preview_blocked: bool,
79 _app_subscription: Subscription,
80 _release: Subscription,
81 }
82
83 impl DevicesView {
84 pub fn new(app: Entity<AppState>, cx: &mut Context<Self>) -> Self {
85 let app_subscription = cx.observe(&app, |view, _, cx| view.sync_preview_block(cx));
86 let release = cx.on_release(|view, cx| view.preview.stop(cx));
87 let (preview, mut updates) = CameraPreview::new();
88 let state = app.read(cx);
89 let demo = state.mode.demo;
90 let camera = state.call_camera.clone();
91 preview.set_effects(state.call_effects);
92 let preview_blocked = camera_in_call(state);
93 let background = Some(state.call_background.clone())
94 .filter(|pick| {
95 preview_backgrounds(&state.call_backgrounds)
96 .iter()
97 .any(|(known, _)| known == pick)
98 })
99 .unwrap_or_default();
100 cx.spawn(async move |this, cx| {
101 while updates.recv().await.is_some() {
102 if this.update(cx, |view, cx| view.take_frames(cx)).is_err() {
103 return;
104 }
105 }
106 })
107 .detach();
108 cx.spawn(async move |this, cx| {
109 loop {
110 cx.background_executor().timer(FPS_TICK).await;
111 let ticked = this.update(cx, |view, cx| {
112 view.preview.tick(Instant::now());
113 cx.notify();
114 });
115 if ticked.is_err() {
116 break;
117 }
118 }
119 })
120 .detach();
121 let mut view = DevicesView {
122 app,
123 preview,
124 cameras: camera_entries(&[]),
125 audio_devices: if demo {
126 demo_devices()
127 } else {
128 DeviceLists::default()
129 },
130 camera,
131 background,
132 preview_blocked,
133 _app_subscription: app_subscription,
134 _release: release,
135 };
136 view.load_devices(demo, cx);
137 view.apply_background(cx);
138 view.start_preview();
139 view
140 }
141
142 fn take_frames(&mut self, cx: &mut Context<Self>) {
143 self.preview.take_frames(cx);
144 cx.notify();
145 }
146
147 fn load_devices(&mut self, demo: bool, cx: &mut Context<Self>) {
148 cx.spawn(async move |this, cx| {
149 let (cameras, audio_devices) = cx
150 .background_executor()
151 .spawn(async move {
152 let audio_devices = (!demo).then(|| list_devices(&shared_factory()));
153 (list_cameras(), audio_devices)
154 })
155 .await;
156 this.update(cx, |view, cx| {
157 view.cameras = camera_entries(&cameras);
158 if let Some(audio_devices) = audio_devices {
159 view.audio_devices = audio_devices;
160 }
161 cx.notify();
162 })
163 .ok();
164 })
165 .detach();
166 }
167
168 fn start_preview(&mut self) {
169 if !self.preview_blocked {
170 self.preview.start(&self.camera);
171 }
172 }
173
174 fn sync_preview_block(&mut self, cx: &mut Context<Self>) {
175 let blocked = camera_in_call(self.app.read(cx));
176 if blocked == self.preview_blocked {
177 return;
178 }
179 self.preview_blocked = blocked;
180 if blocked {
181 self.preview.stop(cx);
182 } else {
183 self.start_preview();
184 }
185 cx.notify();
186 }
187
188 fn select_camera(&mut self, camera: DeviceChoice, cx: &mut Context<Self>) {
189 self.camera = camera.clone();
190 self.app
191 .update(cx, |state, cx| state.select_call_camera(camera, cx));
192 self.start_preview();
193 cx.notify();
194 }
195
196 fn select_background(&mut self, pick: BackgroundPick, cx: &mut Context<Self>) {
197 self.background = pick.clone();
198 self.app
199 .update(cx, |state, cx| state.set_call_background(pick, cx));
200 self.apply_background(cx);
201 cx.notify();
202 }
203
204 fn apply_background(&self, cx: &App) {
205 let state = self.app.read(cx);
206 if let Some(choice) = state.call_backgrounds.choice_for(&self.background) {
207 self.preview.set_background(choice);
208 }
209 }
210
211 fn set_mic(&mut self, settings: MicSettings, cx: &mut Context<Self>) {
212 self.app
213 .update(cx, |state, cx| state.set_call_mic(settings, cx));
214 cx.notify();
215 }
216
217 fn set_effects(&mut self, effects: CameraEffects, cx: &mut Context<Self>) {
218 self.preview.set_effects(effects);
219 self.app
220 .update(cx, |state, cx| state.set_call_effects(effects, cx));
221 cx.notify();
222 }
223
224 fn preview_status(&self) -> String {
225 if self.preview_blocked {
226 return CAMERA_IN_USE.to_owned();
227 }
228 match self.preview.failure() {
229 Some(reason) => format!("Camera could not start: {reason}"),
230 None => self
231 .preview
232 .fps()
233 .map_or("Starting camera...".to_owned(), |fps| {
234 format!("{fps:.0} fps")
235 }),
236 }
237 }
238
239 fn audio_rows(&self, cx: &mut Context<Self>) -> Vec<AnyElement> {
240 let view = cx.entity();
241 let state = self.app.read(cx);
242 let (input, output, mic) = (
243 state.call_input.clone(),
244 state.call_output.clone(),
245 state.call_mic,
246 );
247 let device_choices = |entries: Vec<DeviceEntry>, current: &DeviceChoice, output: bool| {
248 entries
249 .into_iter()
250 .map(|entry| {
251 let (app, choice) = (self.app.clone(), entry.choice.clone());
252 Choice::new(entry.label, &entry.choice == current, move |cx| {
253 let choice = choice.clone();
254 app.update(cx, |state, cx| {
255 if output {
256 state.select_call_output(choice, cx)
257 } else {
258 state.select_call_input(choice, cx)
259 }
260 })
261 })
262 })
263 .collect::<Vec<_>>()
264 };
265 let (outputs, inputs) = (
266 self.audio_devices.output_entries(),
267 self.audio_devices.input_entries(),
268 );
269 let speaker_label = label_of(&outputs, &output, DEFAULT_DEVICE_LABEL);
270 let microphone_label = label_of(&inputs, &input, DEFAULT_DEVICE_LABEL);
271 let noise_choices = NoiseSuppression::ALL
272 .iter()
273 .map(|level| {
274 let (view, level) = (view.clone(), *level);
275 Choice::new(level.label(), level == mic.noise_suppression, move |cx| {
276 view.update(cx, |view, cx| {
277 view.set_mic(
278 MicSettings {
279 noise_suppression: level,
280 ..mic
281 },
282 cx,
283 )
284 })
285 })
286 })
287 .collect();
288 let music_view = view.clone();
289 let call_app = self.app.clone();
290 vec![
291 control_row(
292 "Speaker",
293 "",
294 select(
295 "settings-speaker",
296 speaker_label,
297 false,
298 device_choices(outputs, &output, true),
299 ),
300 )
301 .into_any_element(),
302 control_row(
303 "Microphone",
304 "",
305 select(
306 "settings-microphone",
307 microphone_label,
308 false,
309 device_choices(inputs, &input, false),
310 ),
311 )
312 .into_any_element(),
313 control_row(
314 "Noise suppression",
315 if mic.music_mode {
316 "Off while music mode is on"
317 } else {
318 "Echo, hum and background noise"
319 },
320 select(
321 "noise-suppression-select",
322 mic.noise_suppression.label(),
323 mic.music_mode,
324 noise_choices,
325 ),
326 )
327 .into_any_element(),
328 toggle_row(
329 "music-mode-row",
330 "Music mode",
331 "Keeps echo cancellation, turns off the rest",
332 theme::text_muted(),
333 mic.music_mode,
334 )
335 .on_click(move |_, _, cx| {
336 music_view.update(cx, |view, cx| {
337 view.set_mic(
338 MicSettings {
339 music_mode: !mic.music_mode,
340 ..mic
341 },
342 cx,
343 )
344 })
345 })
346 .into_any_element(),
347 control_row(
348 "Make a test call",
349 "Echo bot, checks your speaker and microphone",
350 text_button("settings-test-call", "Make a test call").on_click(move |_, _, cx| {
351 call_app.update(cx, |state, cx| state.start_test_call(cx))
352 }),
353 )
354 .into_any_element(),
355 ]
356 }
357
358 fn camera_block(&self, cx: &mut Context<Self>) -> Div {
359 let view = cx.entity();
360 let camera_label = label_of(&self.cameras, &self.camera, DEFAULT_CAMERA_LABEL);
361 let camera_choices = self
362 .cameras
363 .iter()
364 .map(|entry| {
365 let (view, choice) = (view.clone(), entry.choice.clone());
366 Choice::new(
367 entry.label.clone(),
368 entry.choice == self.camera,
369 move |cx| view.update(cx, |view, cx| view.select_camera(choice.clone(), cx)),
370 )
371 })
372 .collect();
373 let backgrounds = preview_backgrounds(&self.app.read(cx).call_backgrounds);
374 let background_label = backgrounds
375 .iter()
376 .find(|(pick, _)| *pick == self.background)
377 .map_or("None".to_owned(), |(_, label)| label.clone());
378 let background_choices = backgrounds
379 .into_iter()
380 .map(|(pick, label)| {
381 let view = view.clone();
382 let checked = pick == self.background;
383 Choice::new(label, checked, move |cx| {
384 view.update(cx, |view, cx| view.select_background(pick.clone(), cx))
385 })
386 })
387 .collect();
388 let image = self.preview.image(Instant::now());
389 v_flex()
390 .w_full()
391 .child(
392 row()
393 .items_start()
394 .flex_wrap()
395 .child(
396 div()
397 .w(px(PREVIEW_WIDTH))
398 .h(px(PREVIEW_HEIGHT))
399 .flex_none()
400 .flex()
401 .items_center()
402 .justify_center()
403 .overflow_hidden()
404 .rounded(px(PREVIEW_RADIUS))
405 .bg(theme::surface())
406 .children(image.map(|image| {
407 img(ImageSource::Render(image))
408 .size_full()
409 .object_fit(ObjectFit::Cover)
410 .rounded(px(PREVIEW_RADIUS))
411 })),
412 )
413 .child(
414 v_flex()
415 .gap(px(12.))
416 .child(device_label("Camera"))
417 .child(select("camera-select", camera_label, false, camera_choices))
418 .child(device_label("Background"))
419 .child(select(
420 "background-select",
421 background_label,
422 false,
423 background_choices,
424 )),
425 ),
426 )
427 .child(
428 div()
429 .px(px(super::rows::ROW_INSET))
430 .text_size(px(12.))
431 .text_color(theme::text_muted())
432 .child(self.preview_status()),
433 )
434 }
435
436 fn effect_rows(&self, cx: &mut Context<Self>) -> Vec<AnyElement> {
437 let effects = self.app.read(cx).call_effects;
438 let mut rows: Vec<AnyElement> = EFFECTS
439 .iter()
440 .map(|effect| {
441 let view = cx.entity();
442 let flip = effect.flip;
443 toggle_row(
444 effect.id,
445 effect.title,
446 "",
447 theme::text_muted(),
448 (effect.read)(&effects),
449 )
450 .on_click(move |_, _, cx| {
451 view.update(cx, |view, cx| {
452 let mut changed = view.app.read(cx).call_effects;
453 flip(&mut changed);
454 view.set_effects(changed, cx)
455 })
456 })
457 .into_any_element()
458 })
459 .collect();
460 if effects.soft_focus {
461 rows.push(self.strength_row(effects, cx).into_any_element());
462 }
463 rows
464 }
465
466 fn strength_row(&self, effects: CameraEffects, cx: &mut Context<Self>) -> Div {
467 let levels = SOFT_FOCUS_LEVELS.map(|(label, level)| {
468 let view = cx.entity();
469 text_button(label, label)
470 .when(effects.soft_focus_strength == level, |button| {
471 button.bg(theme::accent()).text_color(theme::on_accent())
472 })
473 .on_click(move |_, _, cx| {
474 view.update(cx, |view, cx| {
475 let changed = CameraEffects {
476 soft_focus_strength: level,
477 ..view.app.read(cx).call_effects
478 };
479 view.set_effects(changed, cx)
480 })
481 })
482 });
483 control_row(
484 "Soft focus strength",
485 "",
486 h_flex().gap(px(8.)).children(levels),
487 )
488 }
489 }
490
491 fn device_label(text: &'static str) -> Div {
492 div()
493 .text_size(px(12.))
494 .text_color(theme::text_muted())
495 .child(text)
496 }
497
498 impl Render for DevicesView {
499 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
500 let report_on = self.app.read(cx).call_report_enabled;
501 let report_app = self.app.clone();
502 v_flex()
503 .w_full()
504 .child(caption("AUDIO DEVICES"))
505 .children(self.audio_rows(cx))
506 .child(caption("CAMERA"))
507 .child(self.camera_block(cx))
508 .children(self.effect_rows(cx))
509 .child(caption("DIAGNOSTICS"))
510 .child(
511 toggle_row(
512 "call-report-row",
513 "Save a test report after each call",
514 "Pseudonymized, stays on this computer",
515 theme::text_muted(),
516 report_on,
517 )
518 .on_click(move |_, _, cx| {
519 report_app.update(cx, |state, cx| {
520 state.set_call_report_enabled(!report_on, cx)
521 })
522 }),
523 )
524 }
525 }
@@ -0,0 +1,525 @@
1use std::time::{Duration, Instant};
2
3use calling::camera::{DEFAULT_CAMERA_LABEL, list_cameras};
4use calling::devices::{DeviceLists, list_devices, shared_factory};
5use calling::{
6 CameraEffects, DeviceChoice, DeviceEntry, MicSettings, NoiseSuppression, camera_entries,
7};
8use gpui_kit::component::{h_flex, v_flex};
9use gpui_kit::prelude::FluentBuilder as _;
10use gpui_kit::*;
11
12use super::rows::{Choice, caption, control_row, row, select, text_button, toggle_row};
13use crate::app_state::AppState;
14use crate::call::{BackgroundPick, CameraPreview, preview_backgrounds};
15use crate::theme;
16use crate::views::prejoin_view::demo_devices;
17
18const FPS_TICK: Duration = Duration::from_millis(500);
19const PREVIEW_WIDTH: f32 = 288.;
20const PREVIEW_HEIGHT: f32 = 162.;
21const PREVIEW_RADIUS: f32 = 10.;
22const SOFT_FOCUS_LEVELS: [(&str, u8); 3] = [("Low", 25), ("Medium", 50), ("High", 75)];
23const CAMERA_IN_USE: &str = "Camera is in use by the call";
24const DEFAULT_DEVICE_LABEL: &str = "Default device";
25
26struct Effect {
27 id: &'static str,
28 title: &'static str,
29 read: fn(&CameraEffects) -> bool,
30 flip: fn(&mut CameraEffects),
31}
32
33const EFFECTS: [Effect; 4] = [
34 Effect {
35 id: "effect-mirror",
36 title: "Mirror my video",
37 read: |effects| effects.mirror,
38 flip: |effects| effects.mirror = !effects.mirror,
39 },
40 Effect {
41 id: "effect-framing",
42 title: "Auto framing",
43 read: |effects| effects.auto_framing,
44 flip: |effects| effects.auto_framing = !effects.auto_framing,
45 },
46 Effect {
47 id: "effect-brightness",
48 title: "Adjust brightness",
49 read: |effects| effects.adjust_brightness,
50 flip: |effects| effects.adjust_brightness = !effects.adjust_brightness,
51 },
52 Effect {
53 id: "effect-soft-focus",
54 title: "Soft focus",
55 read: |effects| effects.soft_focus,
56 flip: |effects| effects.soft_focus = !effects.soft_focus,
57 },
58];
59
60fn camera_in_call(state: &AppState) -> bool {
61 state.call.is_some()
62}
63
64fn label_of(entries: &[DeviceEntry], choice: &DeviceChoice, fallback: &str) -> String {
65 entries
66 .iter()
67 .find(|entry| &entry.choice == choice)
68 .map_or_else(|| fallback.to_owned(), |entry| entry.label.clone())
69}
70
71pub struct DevicesView {
72 app: Entity<AppState>,
73 preview: CameraPreview,
74 cameras: Vec<DeviceEntry>,
75 audio_devices: DeviceLists,
76 camera: DeviceChoice,
77 background: BackgroundPick,
78 preview_blocked: bool,
79 _app_subscription: Subscription,
80 _release: Subscription,
81}
82
83impl DevicesView {
84 pub fn new(app: Entity<AppState>, cx: &mut Context<Self>) -> Self {
85 let app_subscription = cx.observe(&app, |view, _, cx| view.sync_preview_block(cx));
86 let release = cx.on_release(|view, cx| view.preview.stop(cx));
87 let (preview, mut updates) = CameraPreview::new();
88 let state = app.read(cx);
89 let demo = state.mode.demo;
90 let camera = state.call_camera.clone();
91 preview.set_effects(state.call_effects);
92 let preview_blocked = camera_in_call(state);
93 let background = Some(state.call_background.clone())
94 .filter(|pick| {
95 preview_backgrounds(&state.call_backgrounds)
96 .iter()
97 .any(|(known, _)| known == pick)
98 })
99 .unwrap_or_default();
100 cx.spawn(async move |this, cx| {
101 while updates.recv().await.is_some() {
102 if this.update(cx, |view, cx| view.take_frames(cx)).is_err() {
103 return;
104 }
105 }
106 })
107 .detach();
108 cx.spawn(async move |this, cx| {
109 loop {
110 cx.background_executor().timer(FPS_TICK).await;
111 let ticked = this.update(cx, |view, cx| {
112 view.preview.tick(Instant::now());
113 cx.notify();
114 });
115 if ticked.is_err() {
116 break;
117 }
118 }
119 })
120 .detach();
121 let mut view = DevicesView {
122 app,
123 preview,
124 cameras: camera_entries(&[]),
125 audio_devices: if demo {
126 demo_devices()
127 } else {
128 DeviceLists::default()
129 },
130 camera,
131 background,
132 preview_blocked,
133 _app_subscription: app_subscription,
134 _release: release,
135 };
136 view.load_devices(demo, cx);
137 view.apply_background(cx);
138 view.start_preview();
139 view
140 }
141
142 fn take_frames(&mut self, cx: &mut Context<Self>) {
143 self.preview.take_frames(cx);
144 cx.notify();
145 }
146
147 fn load_devices(&mut self, demo: bool, cx: &mut Context<Self>) {
148 cx.spawn(async move |this, cx| {
149 let (cameras, audio_devices) = cx
150 .background_executor()
151 .spawn(async move {
152 let audio_devices = (!demo).then(|| list_devices(&shared_factory()));
153 (list_cameras(), audio_devices)
154 })
155 .await;
156 this.update(cx, |view, cx| {
157 view.cameras = camera_entries(&cameras);
158 if let Some(audio_devices) = audio_devices {
159 view.audio_devices = audio_devices;
160 }
161 cx.notify();
162 })
163 .ok();
164 })
165 .detach();
166 }
167
168 fn start_preview(&mut self) {
169 if !self.preview_blocked {
170 self.preview.start(&self.camera);
171 }
172 }
173
174 fn sync_preview_block(&mut self, cx: &mut Context<Self>) {
175 let blocked = camera_in_call(self.app.read(cx));
176 if blocked == self.preview_blocked {
177 return;
178 }
179 self.preview_blocked = blocked;
180 if blocked {
181 self.preview.stop(cx);
182 } else {
183 self.start_preview();
184 }
185 cx.notify();
186 }
187
188 fn select_camera(&mut self, camera: DeviceChoice, cx: &mut Context<Self>) {
189 self.camera = camera.clone();
190 self.app
191 .update(cx, |state, cx| state.select_call_camera(camera, cx));
192 self.start_preview();
193 cx.notify();
194 }
195
196 fn select_background(&mut self, pick: BackgroundPick, cx: &mut Context<Self>) {
197 self.background = pick.clone();
198 self.app
199 .update(cx, |state, cx| state.set_call_background(pick, cx));
200 self.apply_background(cx);
201 cx.notify();
202 }
203
204 fn apply_background(&self, cx: &App) {
205 let state = self.app.read(cx);
206 if let Some(choice) = state.call_backgrounds.choice_for(&self.background) {
207 self.preview.set_background(choice);
208 }
209 }
210
211 fn set_mic(&mut self, settings: MicSettings, cx: &mut Context<Self>) {
212 self.app
213 .update(cx, |state, cx| state.set_call_mic(settings, cx));
214 cx.notify();
215 }
216
217 fn set_effects(&mut self, effects: CameraEffects, cx: &mut Context<Self>) {
218 self.preview.set_effects(effects);
219 self.app
220 .update(cx, |state, cx| state.set_call_effects(effects, cx));
221 cx.notify();
222 }
223
224 fn preview_status(&self) -> String {
225 if self.preview_blocked {
226 return CAMERA_IN_USE.to_owned();
227 }
228 match self.preview.failure() {
229 Some(reason) => format!("Camera could not start: {reason}"),
230 None => self
231 .preview
232 .fps()
233 .map_or("Starting camera...".to_owned(), |fps| {
234 format!("{fps:.0} fps")
235 }),
236 }
237 }
238
239 fn audio_rows(&self, cx: &mut Context<Self>) -> Vec<AnyElement> {
240 let view = cx.entity();
241 let state = self.app.read(cx);
242 let (input, output, mic) = (
243 state.call_input.clone(),
244 state.call_output.clone(),
245 state.call_mic,
246 );
247 let device_choices = |entries: Vec<DeviceEntry>, current: &DeviceChoice, output: bool| {
248 entries
249 .into_iter()
250 .map(|entry| {
251 let (app, choice) = (self.app.clone(), entry.choice.clone());
252 Choice::new(entry.label, &entry.choice == current, move |cx| {
253 let choice = choice.clone();
254 app.update(cx, |state, cx| {
255 if output {
256 state.select_call_output(choice, cx)
257 } else {
258 state.select_call_input(choice, cx)
259 }
260 })
261 })
262 })
263 .collect::<Vec<_>>()
264 };
265 let (outputs, inputs) = (
266 self.audio_devices.output_entries(),
267 self.audio_devices.input_entries(),
268 );
269 let speaker_label = label_of(&outputs, &output, DEFAULT_DEVICE_LABEL);
270 let microphone_label = label_of(&inputs, &input, DEFAULT_DEVICE_LABEL);
271 let noise_choices = NoiseSuppression::ALL
272 .iter()
273 .map(|level| {
274 let (view, level) = (view.clone(), *level);
275 Choice::new(level.label(), level == mic.noise_suppression, move |cx| {
276 view.update(cx, |view, cx| {
277 view.set_mic(
278 MicSettings {
279 noise_suppression: level,
280 ..mic
281 },
282 cx,
283 )
284 })
285 })
286 })
287 .collect();
288 let music_view = view.clone();
289 let call_app = self.app.clone();
290 vec![
291 control_row(
292 "Speaker",
293 "",
294 select(
295 "settings-speaker",
296 speaker_label,
297 false,
298 device_choices(outputs, &output, true),
299 ),
300 )
301 .into_any_element(),
302 control_row(
303 "Microphone",
304 "",
305 select(
306 "settings-microphone",
307 microphone_label,
308 false,
309 device_choices(inputs, &input, false),
310 ),
311 )
312 .into_any_element(),
313 control_row(
314 "Noise suppression",
315 if mic.music_mode {
316 "Off while music mode is on"
317 } else {
318 "Echo, hum and background noise"
319 },
320 select(
321 "noise-suppression-select",
322 mic.noise_suppression.label(),
323 mic.music_mode,
324 noise_choices,
325 ),
326 )
327 .into_any_element(),
328 toggle_row(
329 "music-mode-row",
330 "Music mode",
331 "Keeps echo cancellation, turns off the rest",
332 theme::text_muted(),
333 mic.music_mode,
334 )
335 .on_click(move |_, _, cx| {
336 music_view.update(cx, |view, cx| {
337 view.set_mic(
338 MicSettings {
339 music_mode: !mic.music_mode,
340 ..mic
341 },
342 cx,
343 )
344 })
345 })
346 .into_any_element(),
347 control_row(
348 "Make a test call",
349 "Echo bot, checks your speaker and microphone",
350 text_button("settings-test-call", "Make a test call").on_click(move |_, _, cx| {
351 call_app.update(cx, |state, cx| state.start_test_call(cx))
352 }),
353 )
354 .into_any_element(),
355 ]
356 }
357
358 fn camera_block(&self, cx: &mut Context<Self>) -> Div {
359 let view = cx.entity();
360 let camera_label = label_of(&self.cameras, &self.camera, DEFAULT_CAMERA_LABEL);
361 let camera_choices = self
362 .cameras
363 .iter()
364 .map(|entry| {
365 let (view, choice) = (view.clone(), entry.choice.clone());
366 Choice::new(
367 entry.label.clone(),
368 entry.choice == self.camera,
369 move |cx| view.update(cx, |view, cx| view.select_camera(choice.clone(), cx)),
370 )
371 })
372 .collect();
373 let backgrounds = preview_backgrounds(&self.app.read(cx).call_backgrounds);
374 let background_label = backgrounds
375 .iter()
376 .find(|(pick, _)| *pick == self.background)
377 .map_or("None".to_owned(), |(_, label)| label.clone());
378 let background_choices = backgrounds
379 .into_iter()
380 .map(|(pick, label)| {
381 let view = view.clone();
382 let checked = pick == self.background;
383 Choice::new(label, checked, move |cx| {
384 view.update(cx, |view, cx| view.select_background(pick.clone(), cx))
385 })
386 })
387 .collect();
388 let image = self.preview.image(Instant::now());
389 v_flex()
390 .w_full()
391 .child(
392 row()
393 .items_start()
394 .flex_wrap()
395 .child(
396 div()
397 .w(px(PREVIEW_WIDTH))
398 .h(px(PREVIEW_HEIGHT))
399 .flex_none()
400 .flex()
401 .items_center()
402 .justify_center()
403 .overflow_hidden()
404 .rounded(px(PREVIEW_RADIUS))
405 .bg(theme::surface())
406 .children(image.map(|image| {
407 img(ImageSource::Render(image))
408 .size_full()
409 .object_fit(ObjectFit::Cover)
410 .rounded(px(PREVIEW_RADIUS))
411 })),
412 )
413 .child(
414 v_flex()
415 .gap(px(12.))
416 .child(device_label("Camera"))
417 .child(select("camera-select", camera_label, false, camera_choices))
418 .child(device_label("Background"))
419 .child(select(
420 "background-select",
421 background_label,
422 false,
423 background_choices,
424 )),
425 ),
426 )
427 .child(
428 div()
429 .px(px(super::rows::ROW_INSET))
430 .text_size(px(12.))
431 .text_color(theme::text_muted())
432 .child(self.preview_status()),
433 )
434 }
435
436 fn effect_rows(&self, cx: &mut Context<Self>) -> Vec<AnyElement> {
437 let effects = self.app.read(cx).call_effects;
438 let mut rows: Vec<AnyElement> = EFFECTS
439 .iter()
440 .map(|effect| {
441 let view = cx.entity();
442 let flip = effect.flip;
443 toggle_row(
444 effect.id,
445 effect.title,
446 "",
447 theme::text_muted(),
448 (effect.read)(&effects),
449 )
450 .on_click(move |_, _, cx| {
451 view.update(cx, |view, cx| {
452 let mut changed = view.app.read(cx).call_effects;
453 flip(&mut changed);
454 view.set_effects(changed, cx)
455 })
456 })
457 .into_any_element()
458 })
459 .collect();
460 if effects.soft_focus {
461 rows.push(self.strength_row(effects, cx).into_any_element());
462 }
463 rows
464 }
465
466 fn strength_row(&self, effects: CameraEffects, cx: &mut Context<Self>) -> Div {
467 let levels = SOFT_FOCUS_LEVELS.map(|(label, level)| {
468 let view = cx.entity();
469 text_button(label, label)
470 .when(effects.soft_focus_strength == level, |button| {
471 button.bg(theme::accent()).text_color(theme::on_accent())
472 })
473 .on_click(move |_, _, cx| {
474 view.update(cx, |view, cx| {
475 let changed = CameraEffects {
476 soft_focus_strength: level,
477 ..view.app.read(cx).call_effects
478 };
479 view.set_effects(changed, cx)
480 })
481 })
482 });
483 control_row(
484 "Soft focus strength",
485 "",
486 h_flex().gap(px(8.)).children(levels),
487 )
488 }
489}
490
491fn device_label(text: &'static str) -> Div {
492 div()
493 .text_size(px(12.))
494 .text_color(theme::text_muted())
495 .child(text)
496}
497
498impl Render for DevicesView {
499 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
500 let report_on = self.app.read(cx).call_report_enabled;
501 let report_app = self.app.clone();
502 v_flex()
503 .w_full()
504 .child(caption("AUDIO DEVICES"))
505 .children(self.audio_rows(cx))
506 .child(caption("CAMERA"))
507 .child(self.camera_block(cx))
508 .children(self.effect_rows(cx))
509 .child(caption("DIAGNOSTICS"))
510 .child(
511 toggle_row(
512 "call-report-row",
513 "Save a test report after each call",
514 "Pseudonymized, stays on this computer",
515 theme::text_muted(),
516 report_on,
517 )
518 .on_click(move |_, _, cx| {
519 report_app.update(cx, |state, cx| {
520 state.set_call_report_enabled(!report_on, cx)
521 })
522 }),
523 )
524 }
525}
crates/app/src/settings/dialog.rs added +305 −0
@@ -0,0 +1,305 @@
1 use app_ui_kit::settings_controls::PAGE_PADDING;
2 use gpui_kit::assets::IconName;
3 use gpui_kit::component::{h_flex, v_flex};
4 use gpui_kit::*;
5
6 use super::devices::DevicesView;
7 use super::mcp::McpView;
8 use super::nav::{NavLayout, label, render_nav};
9 use super::rows::ROW_INSET;
10 use super::{about, calls, chats, general, notifications};
11 use crate::agents::AgentsSettings;
12 use crate::app_state::AppState;
13 use crate::notify::NotificationCenter;
14 use crate::settings_section::SettingsSection;
15 use crate::theme::{self, ElevatedSurface as _};
16 use crate::views::widgets::icon;
17
18 const BACKDROP_OPACITY: f32 = 0.55;
19 pub(super) const PANEL_RADIUS: f32 = 10.;
20 const CONTENT_MAX_WIDTH: f32 = 744.;
21 const CLOSE_SIZE: f32 = 32.;
22 const COMPACT_BELOW_WIDTH: f32 = 1100.;
23 const COMPACT_BELOW_HEIGHT: f32 = 720.;
24
25 pub enum SettingsDialogEvent {
26 Close,
27 }
28
29 #[derive(Debug, Clone, Copy, PartialEq)]
30 pub struct DialogMetrics {
31 pub inset: f32,
32 pub nav_width: f32,
33 pub padding: f32,
34 }
35
36 pub fn metrics(window_width: f32, window_height: f32) -> DialogMetrics {
37 if window_width < COMPACT_BELOW_WIDTH || window_height < COMPACT_BELOW_HEIGHT {
38 DialogMetrics {
39 inset: 24.,
40 nav_width: 216.,
41 padding: 18.,
42 }
43 } else {
44 DialogMetrics {
45 inset: 48.,
46 nav_width: 264.,
47 padding: 24.,
48 }
49 }
50 }
51
52 pub fn available(section: SettingsSection, agents_available: bool) -> SettingsSection {
53 if section == SettingsSection::Agents && !agents_available {
54 SettingsSection::General
55 } else {
56 section
57 }
58 }
59
60 pub struct SettingsDialog {
61 app: Entity<AppState>,
62 center: Entity<NotificationCenter>,
63 section: SettingsSection,
64 devices: Option<Entity<DevicesView>>,
65 mcp: Option<Entity<McpView>>,
66 agents: Option<Entity<AgentsSettings>>,
67 focus_handle: FocusHandle,
68 _subscriptions: [Subscription; 2],
69 }
70
71 impl EventEmitter<SettingsDialogEvent> for SettingsDialog {}
72
73 impl SettingsDialog {
74 pub fn new(
75 app: Entity<AppState>,
76 center: Entity<NotificationCenter>,
77 section: SettingsSection,
78 window: &mut Window,
79 cx: &mut Context<Self>,
80 ) -> Self {
81 let subscriptions = [
82 cx.observe(&center, |_, _, cx| cx.notify()),
83 cx.observe(&app, |_, _, cx| cx.notify()),
84 ];
85 let focus_handle = cx.focus_handle();
86 window.focus(&focus_handle, cx);
87 let mut dialog = SettingsDialog {
88 app,
89 center,
90 section,
91 devices: None,
92 mcp: None,
93 agents: None,
94 focus_handle,
95 _subscriptions: subscriptions,
96 };
97 dialog.show(section, window, cx);
98 dialog
99 }
100
101 pub fn show(&mut self, section: SettingsSection, window: &mut Window, cx: &mut Context<Self>) {
102 let section = available(section, crate::agents::runs_handle(cx).is_some());
103 self.section = section;
104 if section == SettingsSection::Devices {
105 if self.devices.is_none() {
106 let app = self.app.clone();
107 self.devices = Some(cx.new(|cx| DevicesView::new(app, cx)));
108 }
109 } else {
110 self.devices = None;
111 }
112 if section == SettingsSection::Mcp && self.mcp.is_none() {
113 let app = self.app.clone();
114 self.mcp = Some(cx.new(|cx| McpView::new(app, window, cx)));
115 }
116 if section == SettingsSection::Agents && self.agents.is_none() {
117 self.agents = crate::agents::runs_handle(cx)
118 .map(|runs| cx.new(|cx| AgentsSettings::new(runs, cx)));
119 }
120 cx.notify();
121 }
122
123 fn on_key_down(&mut self, event: &KeyDownEvent, _: &mut Window, cx: &mut Context<Self>) {
124 if event.keystroke.key == "escape" {
125 cx.emit(SettingsDialogEvent::Close);
126 cx.stop_propagation();
127 }
128 }
129
130 fn content(&self, cx: &mut Context<Self>) -> AnyElement {
131 match self.section {
132 SettingsSection::General => {
133 general::render(&self.center, &self.app, cx).into_any_element()
134 }
135 SettingsSection::Notifications => {
136 notifications::render(&self.center, cx).into_any_element()
137 }
138 SettingsSection::Chats => chats::render(&self.app, cx).into_any_element(),
139 SettingsSection::Calls => calls::render(&self.center, cx).into_any_element(),
140 SettingsSection::Devices => self
141 .devices
142 .clone()
143 .map_or_else(|| div().into_any_element(), |view| view.into_any_element()),
144 SettingsSection::Agents => self
145 .agents
146 .clone()
147 .map_or_else(|| div().into_any_element(), |view| view.into_any_element()),
148 SettingsSection::Mcp => self
149 .mcp
150 .clone()
151 .map_or_else(|| div().into_any_element(), |view| view.into_any_element()),
152 SettingsSection::About => about::render().into_any_element(),
153 }
154 }
155
156 fn header(&self, metrics: DialogMetrics, cx: &mut Context<Self>) -> Div {
157 h_flex()
158 .debug_selector(|| "settings/main/header".into())
159 .w_full()
160 .flex_none()
161 .items_center()
162 .pt(px(metrics.padding))
163 .pr(px(metrics.padding))
164 .pb(px(metrics.padding / 2.))
165 .pl(px(metrics.padding + ROW_INSET))
166 .child(
167 div()
168 .flex_1()
169 .min_w_0()
170 .truncate()
171 .text_size(px(20.))
172 .line_height(px(28.))
173 .font_weight(FontWeight::SEMIBOLD)
174 .text_color(theme::text())
175 .child(label(self.section)),
176 )
177 .child(
178 div()
179 .id("settings-close")
180 .size(px(CLOSE_SIZE))
181 .flex_none()
182 .flex()
183 .items_center()
184 .justify_center()
185 .rounded(px(6.))
186 .cursor_pointer()
187 .hover(|button| button.bg(theme::popup_hover()))
188 .on_click(cx.listener(|_, _, _, cx| cx.emit(SettingsDialogEvent::Close)))
189 .child(icon(IconName::X, 16., theme::text_muted())),
190 )
191 }
192 }
193
194 impl Render for SettingsDialog {
195 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
196 let viewport = window.viewport_size();
197 let metrics = metrics(f32::from(viewport.width), f32::from(viewport.height));
198 let dialog = cx.entity();
199 let nav = render_nav(
200 self.section,
201 crate::agents::runs_handle(cx).is_some(),
202 NavLayout {
203 width: metrics.nav_width,
204 padding_y: metrics.padding,
205 },
206 move |section, window, cx| {
207 dialog.update(cx, |dialog, cx| dialog.show(section, window, cx))
208 },
209 );
210 let body_inset = if self.section == SettingsSection::Agents {
211 metrics.padding + ROW_INSET - PAGE_PADDING
212 } else {
213 metrics.padding
214 };
215 let body = div()
216 .id(SharedString::from(format!(
217 "settings-body-{}",
218 label(self.section)
219 )))
220 .debug_selector(|| "settings/main/body".into())
221 .w_full()
222 .flex_1()
223 .min_h_0()
224 .overflow_y_scroll()
225 .px(px(body_inset.max(0.)))
226 .pb(px(metrics.padding))
227 .child(
228 div()
229 .w_full()
230 .max_w(px(CONTENT_MAX_WIDTH))
231 .child(self.content(cx)),
232 );
233 div()
234 .id("settings-layer")
235 .absolute()
236 .top_0()
237 .left_0()
238 .size_full()
239 .child(
240 div()
241 .id("settings-backdrop")
242 .absolute()
243 .top_0()
244 .left_0()
245 .size_full()
246 .bg(black().opacity(BACKDROP_OPACITY))
247 .occlude()
248 .on_click(cx.listener(|_, _, _, cx| cx.emit(SettingsDialogEvent::Close))),
249 )
250 .child(
251 h_flex()
252 .id("settings-dialog")
253 .debug_selector(|| "settings".into())
254 .track_focus(&self.focus_handle)
255 .on_key_down(cx.listener(Self::on_key_down))
256 .absolute()
257 .top(px(metrics.inset))
258 .left(px(metrics.inset))
259 .right(px(metrics.inset))
260 .bottom(px(metrics.inset))
261 .overflow_hidden()
262 .rounded(px(PANEL_RADIUS))
263 .dialog_surface()
264 .text_color(theme::text())
265 .occlude()
266 .child(nav)
267 .child(
268 v_flex()
269 .debug_selector(|| "settings/main".into())
270 .flex_1()
271 .min_w_0()
272 .h_full()
273 .child(self.header(metrics, cx))
274 .child(body),
275 ),
276 )
277 }
278 }
279
280 #[cfg(test)]
281 mod tests {
282 use super::{available, metrics};
283 use crate::settings_section::SettingsSection;
284
285 #[test]
286 fn small_windows_get_the_compact_inset() {
287 assert_eq!(metrics(1280., 800.).inset, 48.);
288 assert_eq!(metrics(1920., 1080.).nav_width, 264.);
289 assert_eq!(metrics(960., 640.).inset, 24.);
290 assert_eq!(metrics(1280., 640.).nav_width, 216.);
291 }
292
293 #[test]
294 fn agents_falls_back_to_general_without_agent_runs() {
295 assert_eq!(
296 available(SettingsSection::Agents, false),
297 SettingsSection::General
298 );
299 assert_eq!(
300 available(SettingsSection::Agents, true),
301 SettingsSection::Agents
302 );
303 assert_eq!(available(SettingsSection::Mcp, false), SettingsSection::Mcp);
304 }
305 }
@@ -0,0 +1,305 @@
1use app_ui_kit::settings_controls::PAGE_PADDING;
2use gpui_kit::assets::IconName;
3use gpui_kit::component::{h_flex, v_flex};
4use gpui_kit::*;
5
6use super::devices::DevicesView;
7use super::mcp::McpView;
8use super::nav::{NavLayout, label, render_nav};
9use super::rows::ROW_INSET;
10use super::{about, calls, chats, general, notifications};
11use crate::agents::AgentsSettings;
12use crate::app_state::AppState;
13use crate::notify::NotificationCenter;
14use crate::settings_section::SettingsSection;
15use crate::theme::{self, ElevatedSurface as _};
16use crate::views::widgets::icon;
17
18const BACKDROP_OPACITY: f32 = 0.55;
19pub(super) const PANEL_RADIUS: f32 = 10.;
20const CONTENT_MAX_WIDTH: f32 = 744.;
21const CLOSE_SIZE: f32 = 32.;
22const COMPACT_BELOW_WIDTH: f32 = 1100.;
23const COMPACT_BELOW_HEIGHT: f32 = 720.;
24
25pub enum SettingsDialogEvent {
26 Close,
27}
28
29#[derive(Debug, Clone, Copy, PartialEq)]
30pub struct DialogMetrics {
31 pub inset: f32,
32 pub nav_width: f32,
33 pub padding: f32,
34}
35
36pub fn metrics(window_width: f32, window_height: f32) -> DialogMetrics {
37 if window_width < COMPACT_BELOW_WIDTH || window_height < COMPACT_BELOW_HEIGHT {
38 DialogMetrics {
39 inset: 24.,
40 nav_width: 216.,
41 padding: 18.,
42 }
43 } else {
44 DialogMetrics {
45 inset: 48.,
46 nav_width: 264.,
47 padding: 24.,
48 }
49 }
50}
51
52pub fn available(section: SettingsSection, agents_available: bool) -> SettingsSection {
53 if section == SettingsSection::Agents && !agents_available {
54 SettingsSection::General
55 } else {
56 section
57 }
58}
59
60pub struct SettingsDialog {
61 app: Entity<AppState>,
62 center: Entity<NotificationCenter>,
63 section: SettingsSection,
64 devices: Option<Entity<DevicesView>>,
65 mcp: Option<Entity<McpView>>,
66 agents: Option<Entity<AgentsSettings>>,
67 focus_handle: FocusHandle,
68 _subscriptions: [Subscription; 2],
69}
70
71impl EventEmitter<SettingsDialogEvent> for SettingsDialog {}
72
73impl SettingsDialog {
74 pub fn new(
75 app: Entity<AppState>,
76 center: Entity<NotificationCenter>,
77 section: SettingsSection,
78 window: &mut Window,
79 cx: &mut Context<Self>,
80 ) -> Self {
81 let subscriptions = [
82 cx.observe(&center, |_, _, cx| cx.notify()),
83 cx.observe(&app, |_, _, cx| cx.notify()),
84 ];
85 let focus_handle = cx.focus_handle();
86 window.focus(&focus_handle, cx);
87 let mut dialog = SettingsDialog {
88 app,
89 center,
90 section,
91 devices: None,
92 mcp: None,
93 agents: None,
94 focus_handle,
95 _subscriptions: subscriptions,
96 };
97 dialog.show(section, window, cx);
98 dialog
99 }
100
101 pub fn show(&mut self, section: SettingsSection, window: &mut Window, cx: &mut Context<Self>) {
102 let section = available(section, crate::agents::runs_handle(cx).is_some());
103 self.section = section;
104 if section == SettingsSection::Devices {
105 if self.devices.is_none() {
106 let app = self.app.clone();
107 self.devices = Some(cx.new(|cx| DevicesView::new(app, cx)));
108 }
109 } else {
110 self.devices = None;
111 }
112 if section == SettingsSection::Mcp && self.mcp.is_none() {
113 let app = self.app.clone();
114 self.mcp = Some(cx.new(|cx| McpView::new(app, window, cx)));
115 }
116 if section == SettingsSection::Agents && self.agents.is_none() {
117 self.agents = crate::agents::runs_handle(cx)
118 .map(|runs| cx.new(|cx| AgentsSettings::new(runs, cx)));
119 }
120 cx.notify();
121 }
122
123 fn on_key_down(&mut self, event: &KeyDownEvent, _: &mut Window, cx: &mut Context<Self>) {
124 if event.keystroke.key == "escape" {
125 cx.emit(SettingsDialogEvent::Close);
126 cx.stop_propagation();
127 }
128 }
129
130 fn content(&self, cx: &mut Context<Self>) -> AnyElement {
131 match self.section {
132 SettingsSection::General => {
133 general::render(&self.center, &self.app, cx).into_any_element()
134 }
135 SettingsSection::Notifications => {
136 notifications::render(&self.center, cx).into_any_element()
137 }
138 SettingsSection::Chats => chats::render(&self.app, cx).into_any_element(),
139 SettingsSection::Calls => calls::render(&self.center, cx).into_any_element(),
140 SettingsSection::Devices => self
141 .devices
142 .clone()
143 .map_or_else(|| div().into_any_element(), |view| view.into_any_element()),
144 SettingsSection::Agents => self
145 .agents
146 .clone()
147 .map_or_else(|| div().into_any_element(), |view| view.into_any_element()),
148 SettingsSection::Mcp => self
149 .mcp
150 .clone()
151 .map_or_else(|| div().into_any_element(), |view| view.into_any_element()),
152 SettingsSection::About => about::render().into_any_element(),
153 }
154 }
155
156 fn header(&self, metrics: DialogMetrics, cx: &mut Context<Self>) -> Div {
157 h_flex()
158 .debug_selector(|| "settings/main/header".into())
159 .w_full()
160 .flex_none()
161 .items_center()
162 .pt(px(metrics.padding))
163 .pr(px(metrics.padding))
164 .pb(px(metrics.padding / 2.))
165 .pl(px(metrics.padding + ROW_INSET))
166 .child(
167 div()
168 .flex_1()
169 .min_w_0()
170 .truncate()
171 .text_size(px(20.))
172 .line_height(px(28.))
173 .font_weight(FontWeight::SEMIBOLD)
174 .text_color(theme::text())
175 .child(label(self.section)),
176 )
177 .child(
178 div()
179 .id("settings-close")
180 .size(px(CLOSE_SIZE))
181 .flex_none()
182 .flex()
183 .items_center()
184 .justify_center()
185 .rounded(px(6.))
186 .cursor_pointer()
187 .hover(|button| button.bg(theme::popup_hover()))
188 .on_click(cx.listener(|_, _, _, cx| cx.emit(SettingsDialogEvent::Close)))
189 .child(icon(IconName::X, 16., theme::text_muted())),
190 )
191 }
192}
193
194impl Render for SettingsDialog {
195 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
196 let viewport = window.viewport_size();
197 let metrics = metrics(f32::from(viewport.width), f32::from(viewport.height));
198 let dialog = cx.entity();
199 let nav = render_nav(
200 self.section,
201 crate::agents::runs_handle(cx).is_some(),
202 NavLayout {
203 width: metrics.nav_width,
204 padding_y: metrics.padding,
205 },
206 move |section, window, cx| {
207 dialog.update(cx, |dialog, cx| dialog.show(section, window, cx))
208 },
209 );
210 let body_inset = if self.section == SettingsSection::Agents {
211 metrics.padding + ROW_INSET - PAGE_PADDING
212 } else {
213 metrics.padding
214 };
215 let body = div()
216 .id(SharedString::from(format!(
217 "settings-body-{}",
218 label(self.section)
219 )))
220 .debug_selector(|| "settings/main/body".into())
221 .w_full()
222 .flex_1()
223 .min_h_0()
224 .overflow_y_scroll()
225 .px(px(body_inset.max(0.)))
226 .pb(px(metrics.padding))
227 .child(
228 div()
229 .w_full()
230 .max_w(px(CONTENT_MAX_WIDTH))
231 .child(self.content(cx)),
232 );
233 div()
234 .id("settings-layer")
235 .absolute()
236 .top_0()
237 .left_0()
238 .size_full()
239 .child(
240 div()
241 .id("settings-backdrop")
242 .absolute()
243 .top_0()
244 .left_0()
245 .size_full()
246 .bg(black().opacity(BACKDROP_OPACITY))
247 .occlude()
248 .on_click(cx.listener(|_, _, _, cx| cx.emit(SettingsDialogEvent::Close))),
249 )
250 .child(
251 h_flex()
252 .id("settings-dialog")
253 .debug_selector(|| "settings".into())
254 .track_focus(&self.focus_handle)
255 .on_key_down(cx.listener(Self::on_key_down))
256 .absolute()
257 .top(px(metrics.inset))
258 .left(px(metrics.inset))
259 .right(px(metrics.inset))
260 .bottom(px(metrics.inset))
261 .overflow_hidden()
262 .rounded(px(PANEL_RADIUS))
263 .dialog_surface()
264 .text_color(theme::text())
265 .occlude()
266 .child(nav)
267 .child(
268 v_flex()
269 .debug_selector(|| "settings/main".into())
270 .flex_1()
271 .min_w_0()
272 .h_full()
273 .child(self.header(metrics, cx))
274 .child(body),
275 ),
276 )
277 }
278}
279
280#[cfg(test)]
281mod tests {
282 use super::{available, metrics};
283 use crate::settings_section::SettingsSection;
284
285 #[test]
286 fn small_windows_get_the_compact_inset() {
287 assert_eq!(metrics(1280., 800.).inset, 48.);
288 assert_eq!(metrics(1920., 1080.).nav_width, 264.);
289 assert_eq!(metrics(960., 640.).inset, 24.);
290 assert_eq!(metrics(1280., 640.).nav_width, 216.);
291 }
292
293 #[test]
294 fn agents_falls_back_to_general_without_agent_runs() {
295 assert_eq!(
296 available(SettingsSection::Agents, false),
297 SettingsSection::General
298 );
299 assert_eq!(
300 available(SettingsSection::Agents, true),
301 SettingsSection::Agents
302 );
303 assert_eq!(available(SettingsSection::Mcp, false), SettingsSection::Mcp);
304 }
305}
crates/app/src/settings/general.rs added +194 −0
@@ -0,0 +1,194 @@
1 use gpui_kit::assets::IconName;
2 use gpui_kit::component::{
3 button::Button,
4 h_flex,
5 menu::{DropdownMenu as _, PopupMenuItem},
6 v_flex,
7 };
8 use gpui_kit::*;
9 use teams_core::TranslationBehavior;
10
11 use super::rows::{Choice, caption, control_row, select, toggle_row};
12 use crate::app_state::AppState;
13 use crate::notify::NotificationCenter;
14 use crate::theme;
15 use crate::views::widgets::icon;
16
17 const BEHAVIORS: [(&str, TranslationBehavior); 3] = [
18 ("Ask me before translating", TranslationBehavior::Ask),
19 ("Auto-translate all messages", TranslationBehavior::Auto),
20 ("Never translate", TranslationBehavior::Never),
21 ];
22 const CHIP_HEIGHT: f32 = 24.;
23 const LANGUAGE_MENU_HEIGHT: f32 = 320.;
24
25 pub fn render(center: &Entity<NotificationCenter>, app: &Entity<AppState>, cx: &App) -> Div {
26 let close_to_tray = center.read(cx).settings().close_to_tray;
27 let toggle_center = center.clone();
28 v_flex()
29 .w_full()
30 .child(caption("SYSTEM"))
31 .child(
32 toggle_row(
33 "settings-close-to-tray",
34 "On close, keep the application running",
35 "The title bar X hides the window to the tray",
36 theme::text_muted(),
37 close_to_tray,
38 )
39 .on_click(move |_, _, cx| {
40 toggle_center.update(cx, |center, cx| {
41 center.update_settings(cx, |settings| {
42 settings.close_to_tray = !settings.close_to_tray
43 })
44 })
45 }),
46 )
47 .child(caption("TRANSLATION"))
48 .children(translation_rows(app, cx))
49 }
50
51 fn translation_rows(app: &Entity<AppState>, cx: &App) -> Vec<AnyElement> {
52 let state = app.read(cx);
53 if state.translation.settings.is_none() {
54 return vec![
55 control_row("Translation", "Translation settings not loaded yet", div())
56 .into_any_element(),
57 ];
58 }
59 let translation = &state.translation;
60 let target = translation.target();
61 let behavior = translation.behavior();
62 let targets = translation
63 .languages
64 .iter()
65 .map(|language| {
66 let (app, code) = (app.clone(), language.code.clone());
67 Choice::new(language.name.clone(), language.code == target, move |cx| {
68 app.update(cx, |state, cx| state.set_translation_target(&code, cx))
69 })
70 })
71 .collect();
72 let behaviors = BEHAVIORS
73 .into_iter()
74 .map(|(label, choice)| {
75 let app = app.clone();
76 Choice::new(label, behavior == choice, move |cx| {
77 app.update(cx, |state, cx| state.set_translation_behavior(choice, cx))
78 })
79 })
80 .collect();
81 let behavior_label = BEHAVIORS
82 .iter()
83 .find(|(_, choice)| *choice == behavior)
84 .map_or("", |(label, _)| label);
85 vec![
86 control_row(
87 "Translate messages into this language",
88 "Read from your Teams account",
89 select(
90 "settings-translation-target",
91 translation.language_name(&target),
92 false,
93 targets,
94 ),
95 )
96 .into_any_element(),
97 control_row(
98 "How to handle messages in other languages",
99 "",
100 select(
101 "settings-translation-behavior",
102 behavior_label,
103 false,
104 behaviors,
105 ),
106 )
107 .into_any_element(),
108 control_row(
109 "Never translate messages in these languages",
110 "",
111 never_chips(app, &target, cx),
112 )
113 .into_any_element(),
114 ]
115 }
116
117 fn never_chips(app: &Entity<AppState>, target: &str, cx: &App) -> Div {
118 let translation = &app.read(cx).translation;
119 let never: Vec<String> = translation
120 .display_codes()
121 .into_iter()
122 .filter(|code| code != target)
123 .collect();
124 let chips = never.iter().map(|code| {
125 let (remove_app, remove_code) = (app.clone(), code.clone());
126 h_flex()
127 .h(px(CHIP_HEIGHT))
128 .pl(px(8.))
129 .gap(px(4.))
130 .items_center()
131 .rounded(px(6.))
132 .bg(theme::surface_raised())
133 .text_size(px(12.))
134 .text_color(theme::text_strong())
135 .child(translation.language_name(code))
136 .child(
137 div()
138 .id(SharedString::from(format!("settings-never-remove-{code}")))
139 .w(px(16.))
140 .h_full()
141 .flex()
142 .items_center()
143 .justify_center()
144 .cursor_pointer()
145 .child(icon(IconName::X, 10., theme::text_faint()))
146 .on_click(move |_, _, cx| {
147 remove_app.update(cx, |state, cx| {
148 state.allow_translating_language(&remove_code, cx)
149 })
150 }),
151 )
152 });
153 let addable = translation
154 .languages
155 .iter()
156 .filter(|language| language.code != target && !never.contains(&language.code))
157 .map(|language| {
158 let (app, code) = (app.clone(), language.code.clone());
159 Choice::new(language.name.clone(), false, move |cx| {
160 app.update(cx, |state, cx| state.never_translate_language(&code, cx))
161 })
162 })
163 .collect();
164 h_flex()
165 .flex_wrap()
166 .justify_end()
167 .gap(px(6.))
168 .items_center()
169 .children(chips)
170 .child(add_language_button(addable))
171 }
172
173 fn add_language_button(choices: Vec<Choice>) -> impl IntoElement {
174 Button::new("settings-never-add")
175 .outline()
176 .h(px(CHIP_HEIGHT))
177 .px(px(8.))
178 .rounded(px(6.))
179 .text_size(px(12.))
180 .text_color(theme::accent_text())
181 .label("+ Add language")
182 .dropdown_menu(move |menu, _, _| {
183 choices.iter().fold(
184 menu.max_h(px(LANGUAGE_MENU_HEIGHT)).scrollable(true),
185 |menu, choice| {
186 let choose = choice.choose.clone();
187 menu.item(
188 PopupMenuItem::new(choice.label.clone())
189 .on_click(move |_, _, cx| choose(cx)),
190 )
191 },
192 )
193 })
194 }
@@ -0,0 +1,194 @@
1use gpui_kit::assets::IconName;
2use gpui_kit::component::{
3 button::Button,
4 h_flex,
5 menu::{DropdownMenu as _, PopupMenuItem},
6 v_flex,
7};
8use gpui_kit::*;
9use teams_core::TranslationBehavior;
10
11use super::rows::{Choice, caption, control_row, select, toggle_row};
12use crate::app_state::AppState;
13use crate::notify::NotificationCenter;
14use crate::theme;
15use crate::views::widgets::icon;
16
17const BEHAVIORS: [(&str, TranslationBehavior); 3] = [
18 ("Ask me before translating", TranslationBehavior::Ask),
19 ("Auto-translate all messages", TranslationBehavior::Auto),
20 ("Never translate", TranslationBehavior::Never),
21];
22const CHIP_HEIGHT: f32 = 24.;
23const LANGUAGE_MENU_HEIGHT: f32 = 320.;
24
25pub fn render(center: &Entity<NotificationCenter>, app: &Entity<AppState>, cx: &App) -> Div {
26 let close_to_tray = center.read(cx).settings().close_to_tray;
27 let toggle_center = center.clone();
28 v_flex()
29 .w_full()
30 .child(caption("SYSTEM"))
31 .child(
32 toggle_row(
33 "settings-close-to-tray",
34 "On close, keep the application running",
35 "The title bar X hides the window to the tray",
36 theme::text_muted(),
37 close_to_tray,
38 )
39 .on_click(move |_, _, cx| {
40 toggle_center.update(cx, |center, cx| {
41 center.update_settings(cx, |settings| {
42 settings.close_to_tray = !settings.close_to_tray
43 })
44 })
45 }),
46 )
47 .child(caption("TRANSLATION"))
48 .children(translation_rows(app, cx))
49}
50
51fn translation_rows(app: &Entity<AppState>, cx: &App) -> Vec<AnyElement> {
52 let state = app.read(cx);
53 if state.translation.settings.is_none() {
54 return vec![
55 control_row("Translation", "Translation settings not loaded yet", div())
56 .into_any_element(),
57 ];
58 }
59 let translation = &state.translation;
60 let target = translation.target();
61 let behavior = translation.behavior();
62 let targets = translation
63 .languages
64 .iter()
65 .map(|language| {
66 let (app, code) = (app.clone(), language.code.clone());
67 Choice::new(language.name.clone(), language.code == target, move |cx| {
68 app.update(cx, |state, cx| state.set_translation_target(&code, cx))
69 })
70 })
71 .collect();
72 let behaviors = BEHAVIORS
73 .into_iter()
74 .map(|(label, choice)| {
75 let app = app.clone();
76 Choice::new(label, behavior == choice, move |cx| {
77 app.update(cx, |state, cx| state.set_translation_behavior(choice, cx))
78 })
79 })
80 .collect();
81 let behavior_label = BEHAVIORS
82 .iter()
83 .find(|(_, choice)| *choice == behavior)
84 .map_or("", |(label, _)| label);
85 vec![
86 control_row(
87 "Translate messages into this language",
88 "Read from your Teams account",
89 select(
90 "settings-translation-target",
91 translation.language_name(&target),
92 false,
93 targets,
94 ),
95 )
96 .into_any_element(),
97 control_row(
98 "How to handle messages in other languages",
99 "",
100 select(
101 "settings-translation-behavior",
102 behavior_label,
103 false,
104 behaviors,
105 ),
106 )
107 .into_any_element(),
108 control_row(
109 "Never translate messages in these languages",
110 "",
111 never_chips(app, &target, cx),
112 )
113 .into_any_element(),
114 ]
115}
116
117fn never_chips(app: &Entity<AppState>, target: &str, cx: &App) -> Div {
118 let translation = &app.read(cx).translation;
119 let never: Vec<String> = translation
120 .display_codes()
121 .into_iter()
122 .filter(|code| code != target)
123 .collect();
124 let chips = never.iter().map(|code| {
125 let (remove_app, remove_code) = (app.clone(), code.clone());
126 h_flex()
127 .h(px(CHIP_HEIGHT))
128 .pl(px(8.))
129 .gap(px(4.))
130 .items_center()
131 .rounded(px(6.))
132 .bg(theme::surface_raised())
133 .text_size(px(12.))
134 .text_color(theme::text_strong())
135 .child(translation.language_name(code))
136 .child(
137 div()
138 .id(SharedString::from(format!("settings-never-remove-{code}")))
139 .w(px(16.))
140 .h_full()
141 .flex()
142 .items_center()
143 .justify_center()
144 .cursor_pointer()
145 .child(icon(IconName::X, 10., theme::text_faint()))
146 .on_click(move |_, _, cx| {
147 remove_app.update(cx, |state, cx| {
148 state.allow_translating_language(&remove_code, cx)
149 })
150 }),
151 )
152 });
153 let addable = translation
154 .languages
155 .iter()
156 .filter(|language| language.code != target && !never.contains(&language.code))
157 .map(|language| {
158 let (app, code) = (app.clone(), language.code.clone());
159 Choice::new(language.name.clone(), false, move |cx| {
160 app.update(cx, |state, cx| state.never_translate_language(&code, cx))
161 })
162 })
163 .collect();
164 h_flex()
165 .flex_wrap()
166 .justify_end()
167 .gap(px(6.))
168 .items_center()
169 .children(chips)
170 .child(add_language_button(addable))
171}
172
173fn add_language_button(choices: Vec<Choice>) -> impl IntoElement {
174 Button::new("settings-never-add")
175 .outline()
176 .h(px(CHIP_HEIGHT))
177 .px(px(8.))
178 .rounded(px(6.))
179 .text_size(px(12.))
180 .text_color(theme::accent_text())
181 .label("+ Add language")
182 .dropdown_menu(move |menu, _, _| {
183 choices.iter().fold(
184 menu.max_h(px(LANGUAGE_MENU_HEIGHT)).scrollable(true),
185 |menu, choice| {
186 let choose = choice.choose.clone();
187 menu.item(
188 PopupMenuItem::new(choice.label.clone())
189 .on_click(move |_, _, cx| choose(cx)),
190 )
191 },
192 )
193 })
194}
crates/app/src/notify/settings_mcp.rs crates/app/src/settings/mcp.rs renamed +41 −163
@@ -12,7 +12,7 @@ use gpui_kit::*;
12 12 use mcp::install::{InstallReport, InstallState, Location, Target};
13 13 use mcp::{Access, AgentPolicy};
14 14
15 use super::settings_view::{control_row, switch, titled_with};
15 use super::rows::{ROW_INSET, caption, control_row, toggle_row};
16 16 use crate::agent_api::{self, ServerStatus};
17 17 use crate::app_state::AppState;
18 18 use crate::data::is_one_on_one;
@@ -23,7 +23,8 @@ use crate::views::widgets::icon;
23 23
24 24 const COPIED_SHOWN: Duration = Duration::from_millis(1500);
25 25 const PORT_WIDTH: f32 = 72.;
26 const FIELD_HEIGHT: f32 = 36.;
26 const FIELD_HEIGHT: f32 = 28.;
27 const FIELD_LABEL_WIDTH: f32 = 60.;
27 28 const SMALL_BUTTON_HEIGHT: f32 = 28.;
28 29 const PICKER_ROW_HEIGHT: f32 = 30.;
29 30 const PICKER_MAX_ROWS: usize = 6;
@@ -32,25 +33,6 @@ const TOKEN_TAIL: usize = 4;
32 33 const CHIP_MAX_WIDTH: f32 = 180.;
33 34 const WSL_WARNING: &str = "WSL agents cannot reach 127.0.0.1 on Windows. Add networkingMode=mirrored to .wslconfig and run wsl --shutdown.";
34 35
35 #[derive(Clone, Copy, PartialEq, Eq)]
36 enum McpTab {
37 Server,
38 Access,
39 Install,
40 }
41
42 impl McpTab {
43 const ALL: [McpTab; 3] = [McpTab::Server, McpTab::Access, McpTab::Install];
44
45 fn label(self) -> &'static str {
46 match self {
47 McpTab::Server => "Server",
48 McpTab::Access => "Access",
49 McpTab::Install => "Install",
50 }
51 }
52 }
53
54 36 #[derive(Clone, Copy, PartialEq, Eq)]
55 37 enum Scope {
56 38 Chats,
@@ -99,7 +81,6 @@ impl Scope {
99 81 enum Copied {
100 82 Url,
101 83 Token,
102 Manual,
103 84 }
104 85
105 86 #[derive(Clone, Copy, PartialEq, Eq)]
@@ -215,7 +196,6 @@ fn wsl_warning() -> Div {
215 196
216 197 pub struct McpView {
217 198 app: Entity<AppState>,
218 tab: McpTab,
219 199 picker: Option<Scope>,
220 200 port_input: Entity<InputState>,
221 201 port_invalid: bool,
@@ -249,7 +229,6 @@ impl McpView {
249 229 }
250 230 let mut view = McpView {
251 231 app,
252 tab: McpTab::Server,
253 232 picker: None,
254 233 port_input,
255 234 port_invalid: false,
@@ -262,6 +241,7 @@ impl McpView {
262 241 _subscriptions: subscriptions,
263 242 };
264 243 view.refresh_wsl(cx);
244 view.refresh_installs(cx);
265 245 view
266 246 }
267 247
@@ -368,20 +348,6 @@ impl McpView {
368 348 cx.notify();
369 349 }
370 350
371 fn select_tab(&mut self, tab: McpTab, cx: &mut Context<Self>) {
372 self.tab = tab;
373 self.picker = None;
374 match tab {
375 McpTab::Install => {
376 self.refresh_installs(cx);
377 self.refresh_wsl(cx);
378 }
379 McpTab::Server => self.refresh_wsl(cx),
380 McpTab::Access => {}
381 }
382 cx.notify();
383 }
384
385 351 fn copy(&mut self, target: Copied, text: String, cx: &mut Context<Self>) {
386 352 cx.write_to_clipboard(ClipboardItem::new_string(text));
387 353 self.copied = Some(target);
@@ -436,47 +402,16 @@ fn inert_button(id: impl Into<ElementId>, label: impl Into<SharedString>) -> Sta
436 402 .child(label.into())
437 403 }
438 404
439 fn caption(label: &'static str) -> Div {
440 div()
441 .px(px(20.))
442 .pt(px(16.))
443 .pb(px(4.))
444 .text_size(px(12.))
445 .font_weight(FontWeight::SEMIBOLD)
446 .text_color(theme::text_muted())
447 .child(label)
448 }
449
450 fn toggle_row(
451 id: &'static str,
452 title: &'static str,
453 detail: &'static str,
454 detail_color: Hsla,
455 on: bool,
456 ) -> Stateful<Div> {
457 h_flex()
458 .id(id)
459 .w_full()
460 .px(px(20.))
461 .py(px(10.))
462 .gap(px(12.))
463 .items_center()
464 .cursor_pointer()
465 .hover(|row| row.bg(theme::row_hover()))
466 .child(titled_with(title, detail, detail_color))
467 .child(switch(on))
468 }
469
470 405 fn note_box(content: impl IntoElement, margin_top: f32) -> Div {
471 406 h_flex()
472 .mx(px(20.))
407 .mx(px(ROW_INSET))
473 408 .mt(px(margin_top))
474 409 .mb(px(12.))
475 410 .px(px(12.))
476 411 .py(px(10.))
477 412 .gap(px(8.))
478 413 .rounded(px(8.))
479 .bg(theme::row_hover())
414 .bg(theme::surface_raised())
480 415 .text_size(px(12.))
481 416 .text_color(theme::text_muted())
482 417 .child(content)
@@ -511,51 +446,14 @@ fn chat_kind_label(state: &AppState, conversation_id: &str) -> Option<&'static s
511 446
512 447 impl Render for McpView {
513 448 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
514 let view = cx.entity();
515 let tabs = h_flex()
516 .mx(px(20.))
517 .mt(px(12.))
518 .mb(px(4.))
519 .p(px(2.))
520 .rounded(px(8.))
521 .bg(theme::surface())
522 .children(McpTab::ALL.map(|tab| {
523 let active = tab == self.tab;
524 let view = view.clone();
525 div()
526 .id(tab.label())
527 .flex_1()
528 .h(px(SMALL_BUTTON_HEIGHT))
529 .flex()
530 .items_center()
531 .justify_center()
532 .rounded(px(6.))
533 .cursor_pointer()
534 .text_size(px(12.))
535 .font_weight(FontWeight::SEMIBOLD)
536 .text_color(if active {
537 theme::text()
538 } else {
539 theme::text_muted()
540 })
541 .when(active, |tab| tab.bg(theme::surface_raised()))
542 .child(tab.label())
543 .on_click(move |_, _, cx| view.update(cx, |view, cx| view.select_tab(tab, cx)))
544 }));
545 let body = match self.tab {
546 McpTab::Server => self.server_tab(cx).into_any_element(),
547 McpTab::Access => self.access_tab(cx).into_any_element(),
548 McpTab::Install => self.install_tab(cx).into_any_element(),
549 };
550 v_flex().w_full().flex_1().min_h_0().child(tabs).child(
551 div()
552 .id("mcp-body")
553 .w_full()
554 .flex_1()
555 .min_h_0()
556 .overflow_y_scroll()
557 .child(body),
558 )
449 v_flex()
450 .w_full()
451 .child(caption("SERVER"))
452 .child(self.server_tab(cx))
453 .child(caption("ACCESS"))
454 .child(self.access_tab(cx))
455 .child(caption("INSTALL"))
456 .child(self.install_tab(cx))
559 457 }
560 458 }
561 459
@@ -567,39 +465,36 @@ impl McpView {
567 465 buttons: Vec<AnyElement>,
568 466 cx: &App,
569 467 ) -> Div {
570 v_flex()
468 h_flex()
571 469 .w_full()
572 .px(px(20.))
573 .pb(px(8.))
574 .gap(px(4.))
470 .px(px(ROW_INSET))
471 .py(px(6.))
472 .gap(px(8.))
473 .items_center()
575 474 .child(
576 475 div()
577 .text_size(px(11.))
476 .w(px(FIELD_LABEL_WIDTH))
477 .flex_none()
478 .text_size(px(12.))
578 479 .text_color(theme::text_faint())
579 480 .child(label),
580 481 )
581 482 .child(
582 h_flex()
583 .w_full()
584 .gap(px(8.))
483 div()
484 .flex_1()
485 .min_w_0()
486 .h(px(FIELD_HEIGHT))
487 .px(px(10.))
488 .flex()
585 489 .items_center()
586 .child(
587 div()
588 .flex_1()
589 .min_w_0()
590 .h(px(FIELD_HEIGHT))
591 .px(px(12.))
592 .flex()
593 .items_center()
594 .rounded(px(8.))
595 .bg(theme::surface())
596 .font_family(cx.theme().mono_font_family.clone())
597 .text_size(px(12.))
598 .text_color(theme::text_soft())
599 .child(div().truncate().child(value)),
600 )
601 .children(buttons),
490 .rounded(px(7.))
491 .bg(theme::surface_raised())
492 .font_family(cx.theme().mono_font_family.clone())
493 .text_size(px(12.))
494 .text_color(theme::text_soft())
495 .child(div().truncate().child(value)),
602 496 )
497 .children(buttons)
603 498 }
604 499
605 500 fn copy_button(
@@ -692,7 +587,7 @@ impl McpView {
692 587 .when(self.port_invalid, |tab| {
693 588 tab.child(
694 589 div()
695 .px(px(20.))
590 .px(px(ROW_INSET))
696 591 .pb(px(4.))
697 592 .text_size(px(12.))
698 593 .text_color(theme::red_soft())
@@ -702,7 +597,6 @@ impl McpView {
702 597 .when(running && self.wsl_unreachable, |tab| {
703 598 tab.child(wsl_warning())
704 599 })
705 .child(caption("CONNECTION"))
706 600 .child(self.field_row(
707 601 "URL",
708 602 url.clone(),
@@ -849,7 +743,7 @@ impl McpView {
849 743 .w_full()
850 744 .flex_wrap()
851 745 .gap(px(6.))
852 .px(px(20.))
746 .px(px(ROW_INSET))
853 747 .pb(px(8.))
854 748 .children(chips)
855 749 .child(add),
@@ -934,7 +828,7 @@ impl McpView {
934 828 })
935 829 .collect();
936 830 v_flex()
937 .mx(px(20.))
831 .mx(px(ROW_INSET))
938 832 .mb(px(8.))
939 833 .p(px(6.))
940 834 .gap(px(4.))
@@ -1043,7 +937,7 @@ impl McpView {
1043 937 .child(
1044 938 h_flex()
1045 939 .w_full()
1046 .px(px(20.))
940 .px(px(ROW_INSET))
1047 941 .py(px(8.))
1048 942 .gap(px(12.))
1049 943 .items_center()
@@ -1077,7 +971,7 @@ impl McpView {
1077 971 )
1078 972 .children(self.install_errors.get(&target).map(|message| {
1079 973 div()
1080 .px(px(20.))
974 .px(px(ROW_INSET))
1081 975 .pb(px(4.))
1082 976 .pl(px(60.))
1083 977 .text_size(px(12.))
@@ -1087,27 +981,11 @@ impl McpView {
1087 981 }
1088 982
1089 983 fn install_tab(&self, cx: &mut Context<Self>) -> Div {
1090 let url = agent_api::endpoint_url(agent_api::policy(cx).port);
1091 let running = agent_api::handle(cx)
1092 .is_some_and(|api| matches!(api.read(cx).status(), ServerStatus::Running(_)));
1093 984 let rows: Vec<Div> = Target::ALL
1094 985 .into_iter()
1095 986 .enumerate()
1096 987 .map(|(index, target)| self.install_row(index, target, cx))
1097 988 .collect();
1098 v_flex()
1099 .w_full()
1100 .pt(px(8.))
1101 .children(rows)
1102 .child(caption("MANUAL"))
1103 .child(self.field_row(
1104 "URL",
1105 url.clone(),
1106 vec![self.copy_button("mcp-manual-copy", Copied::Manual, url, cx)],
1107 cx,
1108 ))
1109 .when(running && self.wsl_unreachable, |tab| {
1110 tab.child(wsl_warning())
1111 })
989 v_flex().w_full().children(rows)
1112 990 }
1113 991 }
@@ -12,7 +12,7 @@ use gpui_kit::*;
12use mcp::install::{InstallReport, InstallState, Location, Target};
12use mcp::install::{InstallReport, InstallState, Location, Target};
13use mcp::{Access, AgentPolicy};
13use mcp::{Access, AgentPolicy};
14
14
15use super::settings_view::{control_row, switch, titled_with};
15use super::rows::{ROW_INSET, caption, control_row, toggle_row};
16use crate::agent_api::{self, ServerStatus};
16use crate::agent_api::{self, ServerStatus};
17use crate::app_state::AppState;
17use crate::app_state::AppState;
18use crate::data::is_one_on_one;
18use crate::data::is_one_on_one;
@@ -23,7 +23,8 @@ use crate::views::widgets::icon;
23
23
24const COPIED_SHOWN: Duration = Duration::from_millis(1500);
24const COPIED_SHOWN: Duration = Duration::from_millis(1500);
25const PORT_WIDTH: f32 = 72.;
25const PORT_WIDTH: f32 = 72.;
26const FIELD_HEIGHT: f32 = 36.;
26const FIELD_HEIGHT: f32 = 28.;
27const FIELD_LABEL_WIDTH: f32 = 60.;
27const SMALL_BUTTON_HEIGHT: f32 = 28.;
28const SMALL_BUTTON_HEIGHT: f32 = 28.;
28const PICKER_ROW_HEIGHT: f32 = 30.;
29const PICKER_ROW_HEIGHT: f32 = 30.;
29const PICKER_MAX_ROWS: usize = 6;
30const PICKER_MAX_ROWS: usize = 6;
@@ -32,25 +33,6 @@ const TOKEN_TAIL: usize = 4;
32const CHIP_MAX_WIDTH: f32 = 180.;
33const CHIP_MAX_WIDTH: f32 = 180.;
33const WSL_WARNING: &str = "WSL agents cannot reach 127.0.0.1 on Windows. Add networkingMode=mirrored to .wslconfig and run wsl --shutdown.";
34const WSL_WARNING: &str = "WSL agents cannot reach 127.0.0.1 on Windows. Add networkingMode=mirrored to .wslconfig and run wsl --shutdown.";
34
35
35#[derive(Clone, Copy, PartialEq, Eq)]
36enum McpTab {
37 Server,
38 Access,
39 Install,
40}
41
42impl McpTab {
43 const ALL: [McpTab; 3] = [McpTab::Server, McpTab::Access, McpTab::Install];
44
45 fn label(self) -> &'static str {
46 match self {
47 McpTab::Server => "Server",
48 McpTab::Access => "Access",
49 McpTab::Install => "Install",
50 }
51 }
52}
53
54#[derive(Clone, Copy, PartialEq, Eq)]
36#[derive(Clone, Copy, PartialEq, Eq)]
55enum Scope {
37enum Scope {
56 Chats,
38 Chats,
@@ -99,7 +81,6 @@ impl Scope {
99enum Copied {
81enum Copied {
100 Url,
82 Url,
101 Token,
83 Token,
102 Manual,
103}
84}
104
85
105#[derive(Clone, Copy, PartialEq, Eq)]
86#[derive(Clone, Copy, PartialEq, Eq)]
@@ -215,7 +196,6 @@ fn wsl_warning() -> Div {
215
196
216pub struct McpView {
197pub struct McpView {
217 app: Entity<AppState>,
198 app: Entity<AppState>,
218 tab: McpTab,
219 picker: Option<Scope>,
199 picker: Option<Scope>,
220 port_input: Entity<InputState>,
200 port_input: Entity<InputState>,
221 port_invalid: bool,
201 port_invalid: bool,
@@ -249,7 +229,6 @@ impl McpView {
249 }
229 }
250 let mut view = McpView {
230 let mut view = McpView {
251 app,
231 app,
252 tab: McpTab::Server,
253 picker: None,
232 picker: None,
254 port_input,
233 port_input,
255 port_invalid: false,
234 port_invalid: false,
@@ -262,6 +241,7 @@ impl McpView {
262 _subscriptions: subscriptions,
241 _subscriptions: subscriptions,
263 };
242 };
264 view.refresh_wsl(cx);
243 view.refresh_wsl(cx);
244 view.refresh_installs(cx);
265 view
245 view
266 }
246 }
267
247
@@ -368,20 +348,6 @@ impl McpView {
368 cx.notify();
348 cx.notify();
369 }
349 }
370
350
371 fn select_tab(&mut self, tab: McpTab, cx: &mut Context<Self>) {
372 self.tab = tab;
373 self.picker = None;
374 match tab {
375 McpTab::Install => {
376 self.refresh_installs(cx);
377 self.refresh_wsl(cx);
378 }
379 McpTab::Server => self.refresh_wsl(cx),
380 McpTab::Access => {}
381 }
382 cx.notify();
383 }
384
385 fn copy(&mut self, target: Copied, text: String, cx: &mut Context<Self>) {
351 fn copy(&mut self, target: Copied, text: String, cx: &mut Context<Self>) {
386 cx.write_to_clipboard(ClipboardItem::new_string(text));
352 cx.write_to_clipboard(ClipboardItem::new_string(text));
387 self.copied = Some(target);
353 self.copied = Some(target);
@@ -436,47 +402,16 @@ fn inert_button(id: impl Into<ElementId>, label: impl Into<SharedString>) -> Sta
436 .child(label.into())
402 .child(label.into())
437}
403}
438
404
439fn caption(label: &'static str) -> Div {
440 div()
441 .px(px(20.))
442 .pt(px(16.))
443 .pb(px(4.))
444 .text_size(px(12.))
445 .font_weight(FontWeight::SEMIBOLD)
446 .text_color(theme::text_muted())
447 .child(label)
448}
449
450fn toggle_row(
451 id: &'static str,
452 title: &'static str,
453 detail: &'static str,
454 detail_color: Hsla,
455 on: bool,
456) -> Stateful<Div> {
457 h_flex()
458 .id(id)
459 .w_full()
460 .px(px(20.))
461 .py(px(10.))
462 .gap(px(12.))
463 .items_center()
464 .cursor_pointer()
465 .hover(|row| row.bg(theme::row_hover()))
466 .child(titled_with(title, detail, detail_color))
467 .child(switch(on))
468}
469
470fn note_box(content: impl IntoElement, margin_top: f32) -> Div {
405fn note_box(content: impl IntoElement, margin_top: f32) -> Div {
471 h_flex()
406 h_flex()
472 .mx(px(20.))
407 .mx(px(ROW_INSET))
473 .mt(px(margin_top))
408 .mt(px(margin_top))
474 .mb(px(12.))
409 .mb(px(12.))
475 .px(px(12.))
410 .px(px(12.))
476 .py(px(10.))
411 .py(px(10.))
477 .gap(px(8.))
412 .gap(px(8.))
478 .rounded(px(8.))
413 .rounded(px(8.))
479 .bg(theme::row_hover())
414 .bg(theme::surface_raised())
480 .text_size(px(12.))
415 .text_size(px(12.))
481 .text_color(theme::text_muted())
416 .text_color(theme::text_muted())
482 .child(content)
417 .child(content)
@@ -511,51 +446,14 @@ fn chat_kind_label(state: &AppState, conversation_id: &str) -> Option<&'static s
511
446
512impl Render for McpView {
447impl Render for McpView {
513 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
448 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
514 let view = cx.entity();
449 v_flex()
515 let tabs = h_flex()
450 .w_full()
516 .mx(px(20.))
451 .child(caption("SERVER"))
517 .mt(px(12.))
452 .child(self.server_tab(cx))
518 .mb(px(4.))
453 .child(caption("ACCESS"))
519 .p(px(2.))
454 .child(self.access_tab(cx))
520 .rounded(px(8.))
455 .child(caption("INSTALL"))
521 .bg(theme::surface())
456 .child(self.install_tab(cx))
522 .children(McpTab::ALL.map(|tab| {
523 let active = tab == self.tab;
524 let view = view.clone();
525 div()
526 .id(tab.label())
527 .flex_1()
528 .h(px(SMALL_BUTTON_HEIGHT))
529 .flex()
530 .items_center()
531 .justify_center()
532 .rounded(px(6.))
533 .cursor_pointer()
534 .text_size(px(12.))
535 .font_weight(FontWeight::SEMIBOLD)
536 .text_color(if active {
537 theme::text()
538 } else {
539 theme::text_muted()
540 })
541 .when(active, |tab| tab.bg(theme::surface_raised()))
542 .child(tab.label())
543 .on_click(move |_, _, cx| view.update(cx, |view, cx| view.select_tab(tab, cx)))
544 }));
545 let body = match self.tab {
546 McpTab::Server => self.server_tab(cx).into_any_element(),
547 McpTab::Access => self.access_tab(cx).into_any_element(),
548 McpTab::Install => self.install_tab(cx).into_any_element(),
549 };
550 v_flex().w_full().flex_1().min_h_0().child(tabs).child(
551 div()
552 .id("mcp-body")
553 .w_full()
554 .flex_1()
555 .min_h_0()
556 .overflow_y_scroll()
557 .child(body),
558 )
559 }
457 }
560}
458}
561
459
@@ -567,39 +465,36 @@ impl McpView {
567 buttons: Vec<AnyElement>,
465 buttons: Vec<AnyElement>,
568 cx: &App,
466 cx: &App,
569 ) -> Div {
467 ) -> Div {
570 v_flex()
468 h_flex()
571 .w_full()
469 .w_full()
572 .px(px(20.))
470 .px(px(ROW_INSET))
573 .pb(px(8.))
471 .py(px(6.))
574 .gap(px(4.))
472 .gap(px(8.))
473 .items_center()
575 .child(
474 .child(
576 div()
475 div()
577 .text_size(px(11.))
476 .w(px(FIELD_LABEL_WIDTH))
477 .flex_none()
478 .text_size(px(12.))
578 .text_color(theme::text_faint())
479 .text_color(theme::text_faint())
579 .child(label),
480 .child(label),
580 )
481 )
581 .child(
482 .child(
582 h_flex()
483 div()
583 .w_full()
484 .flex_1()
584 .gap(px(8.))
485 .min_w_0()
486 .h(px(FIELD_HEIGHT))
487 .px(px(10.))
488 .flex()
585 .items_center()
489 .items_center()
586 .child(
490 .rounded(px(7.))
587 div()
491 .bg(theme::surface_raised())
588 .flex_1()
492 .font_family(cx.theme().mono_font_family.clone())
589 .min_w_0()
493 .text_size(px(12.))
590 .h(px(FIELD_HEIGHT))
494 .text_color(theme::text_soft())
591 .px(px(12.))
495 .child(div().truncate().child(value)),
592 .flex()
593 .items_center()
594 .rounded(px(8.))
595 .bg(theme::surface())
596 .font_family(cx.theme().mono_font_family.clone())
597 .text_size(px(12.))
598 .text_color(theme::text_soft())
599 .child(div().truncate().child(value)),
600 )
601 .children(buttons),
602 )
496 )
497 .children(buttons)
603 }
498 }
604
499
605 fn copy_button(
500 fn copy_button(
@@ -692,7 +587,7 @@ impl McpView {
692 .when(self.port_invalid, |tab| {
587 .when(self.port_invalid, |tab| {
693 tab.child(
588 tab.child(
694 div()
589 div()
695 .px(px(20.))
590 .px(px(ROW_INSET))
696 .pb(px(4.))
591 .pb(px(4.))
697 .text_size(px(12.))
592 .text_size(px(12.))
698 .text_color(theme::red_soft())
593 .text_color(theme::red_soft())
@@ -702,7 +597,6 @@ impl McpView {
702 .when(running && self.wsl_unreachable, |tab| {
597 .when(running && self.wsl_unreachable, |tab| {
703 tab.child(wsl_warning())
598 tab.child(wsl_warning())
704 })
599 })
705 .child(caption("CONNECTION"))
706 .child(self.field_row(
600 .child(self.field_row(
707 "URL",
601 "URL",
708 url.clone(),
602 url.clone(),
@@ -849,7 +743,7 @@ impl McpView {
849 .w_full()
743 .w_full()
850 .flex_wrap()
744 .flex_wrap()
851 .gap(px(6.))
745 .gap(px(6.))
852 .px(px(20.))
746 .px(px(ROW_INSET))
853 .pb(px(8.))
747 .pb(px(8.))
854 .children(chips)
748 .children(chips)
855 .child(add),
749 .child(add),
@@ -934,7 +828,7 @@ impl McpView {
934 })
828 })
935 .collect();
829 .collect();
936 v_flex()
830 v_flex()
937 .mx(px(20.))
831 .mx(px(ROW_INSET))
938 .mb(px(8.))
832 .mb(px(8.))
939 .p(px(6.))
833 .p(px(6.))
940 .gap(px(4.))
834 .gap(px(4.))
@@ -1043,7 +937,7 @@ impl McpView {
1043 .child(
937 .child(
1044 h_flex()
938 h_flex()
1045 .w_full()
939 .w_full()
1046 .px(px(20.))
940 .px(px(ROW_INSET))
1047 .py(px(8.))
941 .py(px(8.))
1048 .gap(px(12.))
942 .gap(px(12.))
1049 .items_center()
943 .items_center()
@@ -1077,7 +971,7 @@ impl McpView {
1077 )
971 )
1078 .children(self.install_errors.get(&target).map(|message| {
972 .children(self.install_errors.get(&target).map(|message| {
1079 div()
973 div()
1080 .px(px(20.))
974 .px(px(ROW_INSET))
1081 .pb(px(4.))
975 .pb(px(4.))
1082 .pl(px(60.))
976 .pl(px(60.))
1083 .text_size(px(12.))
977 .text_size(px(12.))
@@ -1087,27 +981,11 @@ impl McpView {
1087 }
981 }
1088
982
1089 fn install_tab(&self, cx: &mut Context<Self>) -> Div {
983 fn install_tab(&self, cx: &mut Context<Self>) -> Div {
1090 let url = agent_api::endpoint_url(agent_api::policy(cx).port);
1091 let running = agent_api::handle(cx)
1092 .is_some_and(|api| matches!(api.read(cx).status(), ServerStatus::Running(_)));
1093 let rows: Vec<Div> = Target::ALL
984 let rows: Vec<Div> = Target::ALL
1094 .into_iter()
985 .into_iter()
1095 .enumerate()
986 .enumerate()
1096 .map(|(index, target)| self.install_row(index, target, cx))
987 .map(|(index, target)| self.install_row(index, target, cx))
1097 .collect();
988 .collect();
1098 v_flex()
989 v_flex().w_full().children(rows)
1099 .w_full()
1100 .pt(px(8.))
1101 .children(rows)
1102 .child(caption("MANUAL"))
1103 .child(self.field_row(
1104 "URL",
1105 url.clone(),
1106 vec![self.copy_button("mcp-manual-copy", Copied::Manual, url, cx)],
1107 cx,
1108 ))
1109 .when(running && self.wsl_unreachable, |tab| {
1110 tab.child(wsl_warning())
1111 })
1112 }
990 }
1113}
991}
crates/app/src/settings/mod.rs added +15 −0
@@ -0,0 +1,15 @@
1 mod about;
2 mod calls;
3 mod chats;
4 mod devices;
5 mod dialog;
6 mod general;
7 mod mcp;
8 mod nav;
9 mod notifications;
10 mod rows;
11
12 pub use dialog::{SettingsDialog, SettingsDialogEvent};
13 #[cfg(test)]
14 pub use dialog::metrics;
15 pub(crate) use rows::switch;
@@ -0,0 +1,15 @@
1mod about;
2mod calls;
3mod chats;
4mod devices;
5mod dialog;
6mod general;
7mod mcp;
8mod nav;
9mod notifications;
10mod rows;
11
12pub use dialog::{SettingsDialog, SettingsDialogEvent};
13#[cfg(test)]
14pub use dialog::metrics;
15pub(crate) use rows::switch;
crates/app/src/settings/nav.rs added +155 −0
@@ -0,0 +1,155 @@
1 use gpui_kit::assets::IconName;
2 use gpui_kit::component::{h_flex, v_flex};
3 use gpui_kit::prelude::FluentBuilder as _;
4 use gpui_kit::*;
5
6 use crate::settings_section::SettingsSection;
7 use crate::theme;
8 use crate::views::widgets::icon;
9
10 pub const TEAMS_GROUP: [SettingsSection; 5] = [
11 SettingsSection::General,
12 SettingsSection::Notifications,
13 SettingsSection::Chats,
14 SettingsSection::Calls,
15 SettingsSection::Devices,
16 ];
17 pub const RUSTY_GROUP: [SettingsSection; 2] = [SettingsSection::Agents, SettingsSection::Mcp];
18 const ITEM_HEIGHT: f32 = 34.;
19 const ITEM_GAP: f32 = 2.;
20 const ITEM_RADIUS: f32 = 6.;
21 const ITEM_ICON: f32 = 16.;
22 const NAV_PADDING_X: f32 = 12.;
23
24 pub fn label(section: SettingsSection) -> &'static str {
25 match section {
26 SettingsSection::General => "General",
27 SettingsSection::Notifications => "Notifications and activity",
28 SettingsSection::Chats => "Chats and channels",
29 SettingsSection::Calls => "Calls",
30 SettingsSection::Devices => "Devices",
31 SettingsSection::Agents => "Agents",
32 SettingsSection::Mcp => "MCP",
33 SettingsSection::About => "About",
34 }
35 }
36
37 fn icon_name(section: SettingsSection) -> IconName {
38 match section {
39 SettingsSection::General => IconName::SlidersHorizontal,
40 SettingsSection::Notifications => IconName::Bell,
41 SettingsSection::Chats => IconName::MessageSquare,
42 SettingsSection::Calls => IconName::Phone,
43 SettingsSection::Devices => IconName::Headphones,
44 SettingsSection::Agents => IconName::Bot,
45 SettingsSection::Mcp => IconName::Plug,
46 SettingsSection::About => IconName::Info,
47 }
48 }
49
50 fn element_id(section: SettingsSection) -> &'static str {
51 match section {
52 SettingsSection::General => "settings-nav-general",
53 SettingsSection::Notifications => "settings-nav-notifications",
54 SettingsSection::Chats => "settings-nav-chats",
55 SettingsSection::Calls => "settings-nav-calls",
56 SettingsSection::Devices => "settings-nav-devices",
57 SettingsSection::Agents => "settings-nav-agents",
58 SettingsSection::Mcp => "settings-nav-mcp",
59 SettingsSection::About => "settings-nav-about",
60 }
61 }
62
63 pub struct NavLayout {
64 pub width: f32,
65 pub padding_y: f32,
66 }
67
68 pub fn render_nav(
69 active: SettingsSection,
70 agents_available: bool,
71 layout: NavLayout,
72 on_select: impl Fn(SettingsSection, &mut Window, &mut App) + Clone + 'static,
73 ) -> Div {
74 let item = |section: SettingsSection| nav_item(section, section == active, on_select.clone());
75 let rusty: Vec<Stateful<Div>> = RUSTY_GROUP
76 .into_iter()
77 .filter(|section| agents_available || *section != SettingsSection::Agents)
78 .map(item)
79 .collect();
80 v_flex()
81 .debug_selector(|| "settings/nav".into())
82 .w(px(layout.width))
83 .h_full()
84 .flex_none()
85 .px(px(NAV_PADDING_X))
86 .py(px(layout.padding_y))
87 .gap(px(ITEM_GAP))
88 .rounded_l(px(super::dialog::PANEL_RADIUS))
89 .bg(theme::surface_raised())
90 .child(
91 div()
92 .mx(px(12.))
93 .mb(px(18.))
94 .text_size(px(20.))
95 .line_height(px(26.))
96 .font_weight(FontWeight::SEMIBOLD)
97 .text_color(theme::text())
98 .child("Settings"),
99 )
100 .children(TEAMS_GROUP.map(item))
101 .child(
102 div()
103 .mt(px(10.))
104 .px(px(12.))
105 .pt(px(12.))
106 .pb(px(6.))
107 .border_t_1()
108 .border_color(theme::border_strong())
109 .text_size(px(12.))
110 .font_weight(FontWeight::SEMIBOLD)
111 .text_color(theme::text_muted())
112 .child("RUSTY TEAMS"),
113 )
114 .children(rusty)
115 .child(div().flex_1().min_h(px(0.)))
116 .child(item(SettingsSection::About))
117 }
118
119 fn nav_item(
120 section: SettingsSection,
121 active: bool,
122 on_select: impl Fn(SettingsSection, &mut Window, &mut App) + 'static,
123 ) -> Stateful<Div> {
124 h_flex()
125 .id(element_id(section))
126 .w_full()
127 .h(px(ITEM_HEIGHT))
128 .flex_none()
129 .px(px(12.))
130 .gap(px(12.))
131 .items_center()
132 .rounded(px(ITEM_RADIUS))
133 .cursor_pointer()
134 .text_size(px(14.))
135 .when(active, |item| {
136 item.bg(theme::popup_hover())
137 .font_weight(FontWeight::SEMIBOLD)
138 .text_color(theme::text())
139 })
140 .when(!active, |item| {
141 item.text_color(theme::text_strong())
142 .hover(|item| item.bg(theme::popup()))
143 })
144 .child(icon(
145 icon_name(section),
146 ITEM_ICON,
147 if active {
148 theme::accent_text()
149 } else {
150 theme::text_muted()
151 },
152 ))
153 .child(div().flex_1().min_w_0().truncate().child(label(section)))
154 .on_click(move |_, window, cx| on_select(section, window, cx))
155 }
@@ -0,0 +1,155 @@
1use gpui_kit::assets::IconName;
2use gpui_kit::component::{h_flex, v_flex};
3use gpui_kit::prelude::FluentBuilder as _;
4use gpui_kit::*;
5
6use crate::settings_section::SettingsSection;
7use crate::theme;
8use crate::views::widgets::icon;
9
10pub const TEAMS_GROUP: [SettingsSection; 5] = [
11 SettingsSection::General,
12 SettingsSection::Notifications,
13 SettingsSection::Chats,
14 SettingsSection::Calls,
15 SettingsSection::Devices,
16];
17pub const RUSTY_GROUP: [SettingsSection; 2] = [SettingsSection::Agents, SettingsSection::Mcp];
18const ITEM_HEIGHT: f32 = 34.;
19const ITEM_GAP: f32 = 2.;
20const ITEM_RADIUS: f32 = 6.;
21const ITEM_ICON: f32 = 16.;
22const NAV_PADDING_X: f32 = 12.;
23
24pub fn label(section: SettingsSection) -> &'static str {
25 match section {
26 SettingsSection::General => "General",
27 SettingsSection::Notifications => "Notifications and activity",
28 SettingsSection::Chats => "Chats and channels",
29 SettingsSection::Calls => "Calls",
30 SettingsSection::Devices => "Devices",
31 SettingsSection::Agents => "Agents",
32 SettingsSection::Mcp => "MCP",
33 SettingsSection::About => "About",
34 }
35}
36
37fn icon_name(section: SettingsSection) -> IconName {
38 match section {
39 SettingsSection::General => IconName::SlidersHorizontal,
40 SettingsSection::Notifications => IconName::Bell,
41 SettingsSection::Chats => IconName::MessageSquare,
42 SettingsSection::Calls => IconName::Phone,
43 SettingsSection::Devices => IconName::Headphones,
44 SettingsSection::Agents => IconName::Bot,
45 SettingsSection::Mcp => IconName::Plug,
46 SettingsSection::About => IconName::Info,
47 }
48}
49
50fn element_id(section: SettingsSection) -> &'static str {
51 match section {
52 SettingsSection::General => "settings-nav-general",
53 SettingsSection::Notifications => "settings-nav-notifications",
54 SettingsSection::Chats => "settings-nav-chats",
55 SettingsSection::Calls => "settings-nav-calls",
56 SettingsSection::Devices => "settings-nav-devices",
57 SettingsSection::Agents => "settings-nav-agents",
58 SettingsSection::Mcp => "settings-nav-mcp",
59 SettingsSection::About => "settings-nav-about",
60 }
61}
62
63pub struct NavLayout {
64 pub width: f32,
65 pub padding_y: f32,
66}
67
68pub fn render_nav(
69 active: SettingsSection,
70 agents_available: bool,
71 layout: NavLayout,
72 on_select: impl Fn(SettingsSection, &mut Window, &mut App) + Clone + 'static,
73) -> Div {
74 let item = |section: SettingsSection| nav_item(section, section == active, on_select.clone());
75 let rusty: Vec<Stateful<Div>> = RUSTY_GROUP
76 .into_iter()
77 .filter(|section| agents_available || *section != SettingsSection::Agents)
78 .map(item)
79 .collect();
80 v_flex()
81 .debug_selector(|| "settings/nav".into())
82 .w(px(layout.width))
83 .h_full()
84 .flex_none()
85 .px(px(NAV_PADDING_X))
86 .py(px(layout.padding_y))
87 .gap(px(ITEM_GAP))
88 .rounded_l(px(super::dialog::PANEL_RADIUS))
89 .bg(theme::surface_raised())
90 .child(
91 div()
92 .mx(px(12.))
93 .mb(px(18.))
94 .text_size(px(20.))
95 .line_height(px(26.))
96 .font_weight(FontWeight::SEMIBOLD)
97 .text_color(theme::text())
98 .child("Settings"),
99 )
100 .children(TEAMS_GROUP.map(item))
101 .child(
102 div()
103 .mt(px(10.))
104 .px(px(12.))
105 .pt(px(12.))
106 .pb(px(6.))
107 .border_t_1()
108 .border_color(theme::border_strong())
109 .text_size(px(12.))
110 .font_weight(FontWeight::SEMIBOLD)
111 .text_color(theme::text_muted())
112 .child("RUSTY TEAMS"),
113 )
114 .children(rusty)
115 .child(div().flex_1().min_h(px(0.)))
116 .child(item(SettingsSection::About))
117}
118
119fn nav_item(
120 section: SettingsSection,
121 active: bool,
122 on_select: impl Fn(SettingsSection, &mut Window, &mut App) + 'static,
123) -> Stateful<Div> {
124 h_flex()
125 .id(element_id(section))
126 .w_full()
127 .h(px(ITEM_HEIGHT))
128 .flex_none()
129 .px(px(12.))
130 .gap(px(12.))
131 .items_center()
132 .rounded(px(ITEM_RADIUS))
133 .cursor_pointer()
134 .text_size(px(14.))
135 .when(active, |item| {
136 item.bg(theme::popup_hover())
137 .font_weight(FontWeight::SEMIBOLD)
138 .text_color(theme::text())
139 })
140 .when(!active, |item| {
141 item.text_color(theme::text_strong())
142 .hover(|item| item.bg(theme::popup()))
143 })
144 .child(icon(
145 icon_name(section),
146 ITEM_ICON,
147 if active {
148 theme::accent_text()
149 } else {
150 theme::text_muted()
151 },
152 ))
153 .child(div().flex_1().min_w_0().truncate().child(label(section)))
154 .on_click(move |_, window, cx| on_select(section, window, cx))
155}
crates/app/src/settings/notifications.rs added +221 −0
@@ -0,0 +1,221 @@
1 use gpui_kit::component::{h_flex, v_flex};
2 use gpui_kit::*;
3
4 use super::rows::{Choice, caption, control_row, select, text_button, toggle_row};
5 use crate::notify::NotificationCenter;
6 use crate::notify::rules::{Corner, Settings};
7 use crate::notify::sounds::AlertSound;
8 use crate::theme;
9
10 type Accessor = fn(&mut Settings) -> &mut bool;
11 type SoundAccessor = fn(&mut Settings) -> &mut AlertSound;
12
13 struct Toggle {
14 id: &'static str,
15 title: &'static str,
16 detail: &'static str,
17 field: Accessor,
18 }
19
20 const APPEARANCE: [Toggle; 2] = [
21 Toggle {
22 id: "settings-preview",
23 title: "Show message preview",
24 detail: "Off: only \"New message\"",
25 field: |settings| &mut settings.preview,
26 },
27 Toggle {
28 id: "settings-flash",
29 title: "Flash taskbar when notifications are received",
30 detail: "On new messages, until you open the window",
31 field: |settings| &mut settings.flash,
32 },
33 ];
34
35 const NOTIFICATION_SOUND: Toggle = Toggle {
36 id: "settings-notification-sound",
37 title: "Play sounds with notifications",
38 detail: "",
39 field: |settings| &mut settings.sounds.notification_sound,
40 };
41
42 const URGENT_SOUND: Toggle = Toggle {
43 id: "settings-urgent-sound",
44 title: "Play sounds with urgent and priority contact notifications",
45 detail: "",
46 field: |settings| &mut settings.sounds.urgent_sound,
47 };
48
49 const CALL_SOUNDS: [Toggle; 2] = [
50 Toggle {
51 id: "settings-call-sound",
52 title: "Play sounds with incoming calls, requests to join, and meeting start notifications",
53 detail: "",
54 field: |settings| &mut settings.sounds.call_and_meeting_sound,
55 },
56 Toggle {
57 id: "settings-busy-sound",
58 title: "Play sounds when I'm busy or in a meeting",
59 detail: "",
60 field: |settings| &mut settings.sounds.sound_when_busy,
61 },
62 ];
63
64 const MENTIONS_ONLY: Toggle = Toggle {
65 id: "settings-mentions-only",
66 title: "Mentions only",
67 detail: "Direct messages and @mentions",
68 field: |settings| &mut settings.mentions_only,
69 };
70
71 const HIDE_IN_CALLS: Toggle = Toggle {
72 id: "settings-hide-in-calls",
73 title: "Hide notifications during calls and meetings",
74 detail: "No message toasts while a call is active",
75 field: |settings| &mut settings.mute_in_calls,
76 };
77
78 pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {
79 let mut current = center.read(cx).settings().clone();
80 let corner = current.corner;
81 let sounds = current.sounds.clone();
82 let mut toggle = |toggle: &Toggle| {
83 let on = *(toggle.field)(&mut current);
84 toggle_element(center, toggle, on)
85 };
86 let appearance: Vec<Stateful<Div>> = APPEARANCE.iter().map(&mut toggle).collect();
87 let notification_sound = toggle(&NOTIFICATION_SOUND);
88 let urgent_sound = toggle(&URGENT_SOUND);
89 let call_sounds: Vec<Stateful<Div>> = CALL_SOUNDS.iter().map(&mut toggle).collect();
90 let mentions_only = toggle(&MENTIONS_ONLY);
91 let hide_in_calls = toggle(&HIDE_IN_CALLS);
92 let test_center = center.clone();
93 v_flex()
94 .w_full()
95 .child(caption("APPEARANCE AND SOUND"))
96 .children(appearance)
97 .child(control_row(
98 "Position on the screen",
99 "Corner of the main screen",
100 select(
101 "settings-position",
102 corner.label(),
103 false,
104 corner_choices(center, corner),
105 ),
106 ))
107 .child(control_row(
108 "Test notification",
109 "Shows a toast with the settings above",
110 text_button("settings-test-notification", "Send test notification").on_click(
111 move |_, _, cx| {
112 test_center.update(cx, |center, cx| center.send_test_notification(cx))
113 },
114 ),
115 ))
116 .child(caption("SOUND"))
117 .child(notification_sound)
118 .child(sound_row(
119 center,
120 (
121 "settings-notification-sound-type",
122 "settings-notification-sound-preview",
123 ),
124 "Notification sound",
125 &AlertSound::NORMAL,
126 sounds.notification_sound_type,
127 sounds.notification_sound,
128 |settings| &mut settings.sounds.notification_sound_type,
129 ))
130 .child(urgent_sound)
131 .child(sound_row(
132 center,
133 (
134 "settings-urgent-sound-type",
135 "settings-urgent-sound-preview",
136 ),
137 "Urgent sound",
138 &AlertSound::URGENT,
139 sounds.urgent_sound_type,
140 sounds.urgent_sound,
141 |settings| &mut settings.sounds.urgent_sound_type,
142 ))
143 .children(call_sounds)
144 .child(caption("WHAT YOU GET NOTIFIED FOR"))
145 .child(mentions_only)
146 .child(caption("MEETINGS AND CALLS"))
147 .child(hide_in_calls)
148 }
149
150 fn toggle_element(center: &Entity<NotificationCenter>, toggle: &Toggle, on: bool) -> Stateful<Div> {
151 let center = center.clone();
152 let field = toggle.field;
153 toggle_row(
154 toggle.id,
155 toggle.title,
156 toggle.detail,
157 theme::text_muted(),
158 on,
159 )
160 .on_click(move |_, _, cx| {
161 center.update(cx, |center, cx| {
162 center.update_settings(cx, |settings| {
163 let value = field(settings);
164 *value = !*value;
165 })
166 })
167 })
168 }
169
170 fn corner_choices(center: &Entity<NotificationCenter>, current: Corner) -> Vec<Choice> {
171 Corner::ALL
172 .into_iter()
173 .map(|corner| {
174 let center = center.clone();
175 Choice::new(corner.label(), corner == current, move |cx| {
176 center.update(cx, |center, cx| {
177 center.update_settings(cx, |settings| settings.corner = corner)
178 })
179 })
180 })
181 .collect()
182 }
183
184 fn sound_row(
185 center: &Entity<NotificationCenter>,
186 (id, preview_id): (&'static str, &'static str),
187 title: &'static str,
188 options: &'static [AlertSound],
189 current: AlertSound,
190 enabled: bool,
191 field: SoundAccessor,
192 ) -> Div {
193 let choices = options
194 .iter()
195 .map(|sound| {
196 let (center, sound) = (center.clone(), *sound);
197 Choice::new(sound.label(), sound == current, move |cx| {
198 center.update(cx, |center, cx| {
199 center.update_settings(cx, |settings| *field(settings) = sound);
200 center.preview_sound(sound.file_name(), cx);
201 })
202 })
203 })
204 .collect();
205 let preview_center = center.clone();
206 control_row(
207 title,
208 "",
209 h_flex()
210 .gap(px(8.))
211 .items_center()
212 .child(select(id, current.label(), !enabled, choices))
213 .child(
214 text_button(preview_id, "Preview").on_click(move |_, _, cx| {
215 preview_center.update(cx, |center, cx| {
216 center.preview_sound(current.file_name(), cx)
217 })
218 }),
219 ),
220 )
221 }
@@ -0,0 +1,221 @@
1use gpui_kit::component::{h_flex, v_flex};
2use gpui_kit::*;
3
4use super::rows::{Choice, caption, control_row, select, text_button, toggle_row};
5use crate::notify::NotificationCenter;
6use crate::notify::rules::{Corner, Settings};
7use crate::notify::sounds::AlertSound;
8use crate::theme;
9
10type Accessor = fn(&mut Settings) -> &mut bool;
11type SoundAccessor = fn(&mut Settings) -> &mut AlertSound;
12
13struct Toggle {
14 id: &'static str,
15 title: &'static str,
16 detail: &'static str,
17 field: Accessor,
18}
19
20const APPEARANCE: [Toggle; 2] = [
21 Toggle {
22 id: "settings-preview",
23 title: "Show message preview",
24 detail: "Off: only \"New message\"",
25 field: |settings| &mut settings.preview,
26 },
27 Toggle {
28 id: "settings-flash",
29 title: "Flash taskbar when notifications are received",
30 detail: "On new messages, until you open the window",
31 field: |settings| &mut settings.flash,
32 },
33];
34
35const NOTIFICATION_SOUND: Toggle = Toggle {
36 id: "settings-notification-sound",
37 title: "Play sounds with notifications",
38 detail: "",
39 field: |settings| &mut settings.sounds.notification_sound,
40};
41
42const URGENT_SOUND: Toggle = Toggle {
43 id: "settings-urgent-sound",
44 title: "Play sounds with urgent and priority contact notifications",
45 detail: "",
46 field: |settings| &mut settings.sounds.urgent_sound,
47};
48
49const CALL_SOUNDS: [Toggle; 2] = [
50 Toggle {
51 id: "settings-call-sound",
52 title: "Play sounds with incoming calls, requests to join, and meeting start notifications",
53 detail: "",
54 field: |settings| &mut settings.sounds.call_and_meeting_sound,
55 },
56 Toggle {
57 id: "settings-busy-sound",
58 title: "Play sounds when I'm busy or in a meeting",
59 detail: "",
60 field: |settings| &mut settings.sounds.sound_when_busy,
61 },
62];
63
64const MENTIONS_ONLY: Toggle = Toggle {
65 id: "settings-mentions-only",
66 title: "Mentions only",
67 detail: "Direct messages and @mentions",
68 field: |settings| &mut settings.mentions_only,
69};
70
71const HIDE_IN_CALLS: Toggle = Toggle {
72 id: "settings-hide-in-calls",
73 title: "Hide notifications during calls and meetings",
74 detail: "No message toasts while a call is active",
75 field: |settings| &mut settings.mute_in_calls,
76};
77
78pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {
79 let mut current = center.read(cx).settings().clone();
80 let corner = current.corner;
81 let sounds = current.sounds.clone();
82 let mut toggle = |toggle: &Toggle| {
83 let on = *(toggle.field)(&mut current);
84 toggle_element(center, toggle, on)
85 };
86 let appearance: Vec<Stateful<Div>> = APPEARANCE.iter().map(&mut toggle).collect();
87 let notification_sound = toggle(&NOTIFICATION_SOUND);
88 let urgent_sound = toggle(&URGENT_SOUND);
89 let call_sounds: Vec<Stateful<Div>> = CALL_SOUNDS.iter().map(&mut toggle).collect();
90 let mentions_only = toggle(&MENTIONS_ONLY);
91 let hide_in_calls = toggle(&HIDE_IN_CALLS);
92 let test_center = center.clone();
93 v_flex()
94 .w_full()
95 .child(caption("APPEARANCE AND SOUND"))
96 .children(appearance)
97 .child(control_row(
98 "Position on the screen",
99 "Corner of the main screen",
100 select(
101 "settings-position",
102 corner.label(),
103 false,
104 corner_choices(center, corner),
105 ),
106 ))
107 .child(control_row(
108 "Test notification",
109 "Shows a toast with the settings above",
110 text_button("settings-test-notification", "Send test notification").on_click(
111 move |_, _, cx| {
112 test_center.update(cx, |center, cx| center.send_test_notification(cx))
113 },
114 ),
115 ))
116 .child(caption("SOUND"))
117 .child(notification_sound)
118 .child(sound_row(
119 center,
120 (
121 "settings-notification-sound-type",
122 "settings-notification-sound-preview",
123 ),
124 "Notification sound",
125 &AlertSound::NORMAL,
126 sounds.notification_sound_type,
127 sounds.notification_sound,
128 |settings| &mut settings.sounds.notification_sound_type,
129 ))
130 .child(urgent_sound)
131 .child(sound_row(
132 center,
133 (
134 "settings-urgent-sound-type",
135 "settings-urgent-sound-preview",
136 ),
137 "Urgent sound",
138 &AlertSound::URGENT,
139 sounds.urgent_sound_type,
140 sounds.urgent_sound,
141 |settings| &mut settings.sounds.urgent_sound_type,
142 ))
143 .children(call_sounds)
144 .child(caption("WHAT YOU GET NOTIFIED FOR"))
145 .child(mentions_only)
146 .child(caption("MEETINGS AND CALLS"))
147 .child(hide_in_calls)
148}
149
150fn toggle_element(center: &Entity<NotificationCenter>, toggle: &Toggle, on: bool) -> Stateful<Div> {
151 let center = center.clone();
152 let field = toggle.field;
153 toggle_row(
154 toggle.id,
155 toggle.title,
156 toggle.detail,
157 theme::text_muted(),
158 on,
159 )
160 .on_click(move |_, _, cx| {
161 center.update(cx, |center, cx| {
162 center.update_settings(cx, |settings| {
163 let value = field(settings);
164 *value = !*value;
165 })
166 })
167 })
168}
169
170fn corner_choices(center: &Entity<NotificationCenter>, current: Corner) -> Vec<Choice> {
171 Corner::ALL
172 .into_iter()
173 .map(|corner| {
174 let center = center.clone();
175 Choice::new(corner.label(), corner == current, move |cx| {
176 center.update(cx, |center, cx| {
177 center.update_settings(cx, |settings| settings.corner = corner)
178 })
179 })
180 })
181 .collect()
182}
183
184fn sound_row(
185 center: &Entity<NotificationCenter>,
186 (id, preview_id): (&'static str, &'static str),
187 title: &'static str,
188 options: &'static [AlertSound],
189 current: AlertSound,
190 enabled: bool,
191 field: SoundAccessor,
192) -> Div {
193 let choices = options
194 .iter()
195 .map(|sound| {
196 let (center, sound) = (center.clone(), *sound);
197 Choice::new(sound.label(), sound == current, move |cx| {
198 center.update(cx, |center, cx| {
199 center.update_settings(cx, |settings| *field(settings) = sound);
200 center.preview_sound(sound.file_name(), cx);
201 })
202 })
203 })
204 .collect();
205 let preview_center = center.clone();
206 control_row(
207 title,
208 "",
209 h_flex()
210 .gap(px(8.))
211 .items_center()
212 .child(select(id, current.label(), !enabled, choices))
213 .child(
214 text_button(preview_id, "Preview").on_click(move |_, _, cx| {
215 preview_center.update(cx, |center, cx| {
216 center.preview_sound(current.file_name(), cx)
217 })
218 }),
219 ),
220 )
221}
crates/app/src/settings/rows.rs added +212 −0
@@ -0,0 +1,212 @@
1 use std::rc::Rc;
2
3 use gpui_kit::assets::IconName;
4 use gpui_kit::base::Disableable as _;
5 use gpui_kit::component::{
6 button::Button,
7 h_flex,
8 menu::{DropdownMenu as _, PopupMenuItem},
9 v_flex,
10 };
11 use gpui_kit::prelude::FluentBuilder as _;
12 use gpui_kit::*;
13
14 use crate::theme;
15 use crate::views::widgets::icon;
16
17 pub const ROW_INSET: f32 = 12.;
18 pub const SELECT_WIDTH: f32 = 216.;
19 const ROW_PADDING: f32 = 12.;
20 const ROW_GAP: f32 = 12.;
21 const ROW_RADIUS: f32 = 8.;
22 const BUTTON_HEIGHT: f32 = 32.;
23 const BUTTON_RADIUS: f32 = 8.;
24 const SCROLL_MENU_AFTER: usize = 10;
25 const MENU_MAX_HEIGHT: f32 = 320.;
26
27 pub struct Choice {
28 pub label: SharedString,
29 pub checked: bool,
30 pub choose: Rc<dyn Fn(&mut App)>,
31 }
32
33 impl Choice {
34 pub fn new(
35 label: impl Into<SharedString>,
36 checked: bool,
37 choose: impl Fn(&mut App) + 'static,
38 ) -> Self {
39 Choice {
40 label: label.into(),
41 checked,
42 choose: Rc::new(choose),
43 }
44 }
45 }
46
47 pub fn switch(on: bool) -> Div {
48 div()
49 .w(px(36.))
50 .h(px(20.))
51 .flex_none()
52 .rounded_full()
53 .relative()
54 .bg(if on {
55 theme::accent()
56 } else {
57 theme::border_strong()
58 })
59 .child(
60 div()
61 .absolute()
62 .top(px(2.))
63 .left(px(if on { 18. } else { 2. }))
64 .size(px(16.))
65 .rounded_full()
66 .bg(theme::text()),
67 )
68 }
69
70 pub fn titled(
71 title: impl Into<SharedString>,
72 detail: impl Into<SharedString>,
73 detail_color: Hsla,
74 ) -> Div {
75 let detail = detail.into();
76 v_flex()
77 .flex_1()
78 .min_w(px(0.))
79 .gap(px(2.))
80 .child(
81 div()
82 .text_size(px(14.))
83 .line_height(px(20.))
84 .font_weight(FontWeight::SEMIBOLD)
85 .text_color(theme::text())
86 .child(title.into()),
87 )
88 .when(!detail.is_empty(), |column| {
89 column.child(
90 div()
91 .text_size(px(12.))
92 .line_height(px(16.))
93 .text_color(detail_color)
94 .child(detail),
95 )
96 })
97 }
98
99 pub fn row() -> Div {
100 h_flex()
101 .w_full()
102 .px(px(ROW_INSET))
103 .py(px(ROW_PADDING))
104 .gap(px(ROW_GAP))
105 .items_center()
106 .rounded(px(ROW_RADIUS))
107 }
108
109 pub fn control_row(
110 title: impl Into<SharedString>,
111 detail: impl Into<SharedString>,
112 control: impl IntoElement,
113 ) -> Div {
114 row()
115 .child(titled(title, detail, theme::text_muted()))
116 .child(control)
117 }
118
119 pub fn toggle_row(
120 id: impl Into<ElementId>,
121 title: impl Into<SharedString>,
122 detail: impl Into<SharedString>,
123 detail_color: Hsla,
124 on: bool,
125 ) -> Stateful<Div> {
126 row()
127 .id(id)
128 .cursor_pointer()
129 .hover(|row| row.bg(theme::popup_hover()))
130 .child(titled(title, detail, detail_color))
131 .child(switch(on))
132 }
133
134 pub fn caption(label: impl Into<SharedString>) -> Div {
135 div()
136 .w_full()
137 .px(px(ROW_INSET))
138 .pt(px(18.))
139 .pb(px(6.))
140 .text_size(px(12.))
141 .font_weight(FontWeight::SEMIBOLD)
142 .text_color(theme::text_muted())
143 .child(label.into())
144 }
145
146 pub fn text_button(id: impl Into<ElementId>, label: impl Into<SharedString>) -> Stateful<Div> {
147 div()
148 .id(id)
149 .h(px(BUTTON_HEIGHT))
150 .px(px(14.))
151 .flex()
152 .flex_none()
153 .items_center()
154 .rounded(px(BUTTON_RADIUS))
155 .border_1()
156 .border_color(theme::border_strong())
157 .cursor_pointer()
158 .text_size(px(13.))
159 .font_weight(FontWeight::SEMIBOLD)
160 .text_color(theme::text())
161 .hover(|button| button.bg(theme::popup_hover()))
162 .child(label.into())
163 }
164
165 pub fn select(
166 id: impl Into<ElementId>,
167 label: impl Into<SharedString>,
168 disabled: bool,
169 choices: Vec<Choice>,
170 ) -> impl IntoElement {
171 select_with_width(id, label, SELECT_WIDTH, disabled, choices)
172 }
173
174 pub fn select_with_width(
175 id: impl Into<ElementId>,
176 label: impl Into<SharedString>,
177 width: f32,
178 disabled: bool,
179 choices: Vec<Choice>,
180 ) -> impl IntoElement {
181 let scrollable = choices.len() > SCROLL_MENU_AFTER;
182 Button::new(id)
183 .outline()
184 .w(px(width))
185 .flex_none()
186 .disabled(disabled)
187 .child(
188 h_flex()
189 .w_full()
190 .min_w_0()
191 .gap(px(8.))
192 .items_center()
193 .justify_between()
194 .child(div().flex_1().min_w_0().truncate().child(label.into()))
195 .child(icon(IconName::ChevronDown, 12., theme::text_muted())),
196 )
197 .dropdown_menu(move |menu, _, _| {
198 let menu = if scrollable {
199 menu.max_h(px(MENU_MAX_HEIGHT)).scrollable(true)
200 } else {
201 menu
202 };
203 choices.iter().fold(menu, |menu, choice| {
204 let choose = choice.choose.clone();
205 menu.item(
206 PopupMenuItem::new(choice.label.clone())
207 .checked(choice.checked)
208 .on_click(move |_, _, cx| choose(cx)),
209 )
210 })
211 })
212 }
@@ -0,0 +1,212 @@
1use std::rc::Rc;
2
3use gpui_kit::assets::IconName;
4use gpui_kit::base::Disableable as _;
5use gpui_kit::component::{
6 button::Button,
7 h_flex,
8 menu::{DropdownMenu as _, PopupMenuItem},
9 v_flex,
10};
11use gpui_kit::prelude::FluentBuilder as _;
12use gpui_kit::*;
13
14use crate::theme;
15use crate::views::widgets::icon;
16
17pub const ROW_INSET: f32 = 12.;
18pub const SELECT_WIDTH: f32 = 216.;
19const ROW_PADDING: f32 = 12.;
20const ROW_GAP: f32 = 12.;
21const ROW_RADIUS: f32 = 8.;
22const BUTTON_HEIGHT: f32 = 32.;
23const BUTTON_RADIUS: f32 = 8.;
24const SCROLL_MENU_AFTER: usize = 10;
25const MENU_MAX_HEIGHT: f32 = 320.;
26
27pub struct Choice {
28 pub label: SharedString,
29 pub checked: bool,
30 pub choose: Rc<dyn Fn(&mut App)>,
31}
32
33impl Choice {
34 pub fn new(
35 label: impl Into<SharedString>,
36 checked: bool,
37 choose: impl Fn(&mut App) + 'static,
38 ) -> Self {
39 Choice {
40 label: label.into(),
41 checked,
42 choose: Rc::new(choose),
43 }
44 }
45}
46
47pub fn switch(on: bool) -> Div {
48 div()
49 .w(px(36.))
50 .h(px(20.))
51 .flex_none()
52 .rounded_full()
53 .relative()
54 .bg(if on {
55 theme::accent()
56 } else {
57 theme::border_strong()
58 })
59 .child(
60 div()
61 .absolute()
62 .top(px(2.))
63 .left(px(if on { 18. } else { 2. }))
64 .size(px(16.))
65 .rounded_full()
66 .bg(theme::text()),
67 )
68}
69
70pub fn titled(
71 title: impl Into<SharedString>,
72 detail: impl Into<SharedString>,
73 detail_color: Hsla,
74) -> Div {
75 let detail = detail.into();
76 v_flex()
77 .flex_1()
78 .min_w(px(0.))
79 .gap(px(2.))
80 .child(
81 div()
82 .text_size(px(14.))
83 .line_height(px(20.))
84 .font_weight(FontWeight::SEMIBOLD)
85 .text_color(theme::text())
86 .child(title.into()),
87 )
88 .when(!detail.is_empty(), |column| {
89 column.child(
90 div()
91 .text_size(px(12.))
92 .line_height(px(16.))
93 .text_color(detail_color)
94 .child(detail),
95 )
96 })
97}
98
99pub fn row() -> Div {
100 h_flex()
101 .w_full()
102 .px(px(ROW_INSET))
103 .py(px(ROW_PADDING))
104 .gap(px(ROW_GAP))
105 .items_center()
106 .rounded(px(ROW_RADIUS))
107}
108
109pub fn control_row(
110 title: impl Into<SharedString>,
111 detail: impl Into<SharedString>,
112 control: impl IntoElement,
113) -> Div {
114 row()
115 .child(titled(title, detail, theme::text_muted()))
116 .child(control)
117}
118
119pub fn toggle_row(
120 id: impl Into<ElementId>,
121 title: impl Into<SharedString>,
122 detail: impl Into<SharedString>,
123 detail_color: Hsla,
124 on: bool,
125) -> Stateful<Div> {
126 row()
127 .id(id)
128 .cursor_pointer()
129 .hover(|row| row.bg(theme::popup_hover()))
130 .child(titled(title, detail, detail_color))
131 .child(switch(on))
132}
133
134pub fn caption(label: impl Into<SharedString>) -> Div {
135 div()
136 .w_full()
137 .px(px(ROW_INSET))
138 .pt(px(18.))
139 .pb(px(6.))
140 .text_size(px(12.))
141 .font_weight(FontWeight::SEMIBOLD)
142 .text_color(theme::text_muted())
143 .child(label.into())
144}
145
146pub fn text_button(id: impl Into<ElementId>, label: impl Into<SharedString>) -> Stateful<Div> {
147 div()
148 .id(id)
149 .h(px(BUTTON_HEIGHT))
150 .px(px(14.))
151 .flex()
152 .flex_none()
153 .items_center()
154 .rounded(px(BUTTON_RADIUS))
155 .border_1()
156 .border_color(theme::border_strong())
157 .cursor_pointer()
158 .text_size(px(13.))
159 .font_weight(FontWeight::SEMIBOLD)
160 .text_color(theme::text())
161 .hover(|button| button.bg(theme::popup_hover()))
162 .child(label.into())
163}
164
165pub fn select(
166 id: impl Into<ElementId>,
167 label: impl Into<SharedString>,
168 disabled: bool,
169 choices: Vec<Choice>,
170) -> impl IntoElement {
171 select_with_width(id, label, SELECT_WIDTH, disabled, choices)
172}
173
174pub fn select_with_width(
175 id: impl Into<ElementId>,
176 label: impl Into<SharedString>,
177 width: f32,
178 disabled: bool,
179 choices: Vec<Choice>,
180) -> impl IntoElement {
181 let scrollable = choices.len() > SCROLL_MENU_AFTER;
182 Button::new(id)
183 .outline()
184 .w(px(width))
185 .flex_none()
186 .disabled(disabled)
187 .child(
188 h_flex()
189 .w_full()
190 .min_w_0()
191 .gap(px(8.))
192 .items_center()
193 .justify_between()
194 .child(div().flex_1().min_w_0().truncate().child(label.into()))
195 .child(icon(IconName::ChevronDown, 12., theme::text_muted())),
196 )
197 .dropdown_menu(move |menu, _, _| {
198 let menu = if scrollable {
199 menu.max_h(px(MENU_MAX_HEIGHT)).scrollable(true)
200 } else {
201 menu
202 };
203 choices.iter().fold(menu, |menu, choice| {
204 let choose = choice.choose.clone();
205 menu.item(
206 PopupMenuItem::new(choice.label.clone())
207 .checked(choice.checked)
208 .on_click(move |_, _, cx| choose(cx)),
209 )
210 })
211 })
212}
crates/app/src/views/call_card.rs +16 −148
@@ -3,11 +3,12 @@ use gpui_kit::prelude::FluentBuilder as _;
3 3 use gpui_kit::*;
4 4
5 5 use super::avatar::person_avatar;
6 use super::call_notice::{RecapActions, notice_row};
6 7 use super::message_row::{AVATAR_GAP, AVATAR_SIZE, RowAction, day_separator, new_marker};
7 8 use super::profile_card::opens_profile;
8 9 use super::widgets::symbol;
9 10 use crate::data::Directory;
10 use crate::rows::{CallCard, CallIcon, CallParticipant, MessageRow, RecordingCard};
11 use crate::rows::{CallCard, CallIcon, CallParticipant, MessageRow};
11 12 use crate::theme;
12 13
13 14 const SERIES_START_GAP: f32 = 8.;
@@ -20,19 +21,11 @@ const DETAIL_SIZE: f32 = 11.;
20 21 const JOIN_HEIGHT: f32 = 24.;
21 22 const PARTICIPANT_AVATAR: f32 = 20.;
22 23 const PARTICIPANT_GAP: f32 = 2.;
23 const TILE_WIDTH: f32 = 288.;
24 const TILE_HEIGHT: f32 = 162.;
25 const TILE_RADIUS: f32 = 8.;
26 const PLAY_CIRCLE: f32 = 40.;
27 const PLAY_GLYPH: f32 = 24.;
28 const DURATION_INSET: f32 = 6.;
29 const CHIP_HEIGHT: f32 = 26.;
30 24
31 25 pub struct CallActions {
32 26 pub call_back: RowAction,
33 27 pub join: RowAction,
34 pub open_recording: RowAction,
35 pub open_transcript: RowAction,
28 pub recap: RecapActions,
36 29 }
37 30
38 31 impl CallActions {
@@ -40,8 +33,12 @@ impl CallActions {
40 33 CallActions {
41 34 call_back: None,
42 35 join: None,
43 open_recording: None,
44 open_transcript: None,
36 recap: RecapActions {
37 view_recap: None,
38 open_recording: None,
39 transcript: None,
40 share: None,
41 },
45 42 }
46 43 }
47 44 }
@@ -51,12 +48,12 @@ fn icon_circle(call: &CallCard, own: bool) -> Div {
51 48 CallIcon::Missed => (theme::red().opacity(0.2), "call_missed", theme::red_soft()),
52 49 CallIcon::Call => (circle_fill(own), "call", theme::text()),
53 50 CallIcon::Video => (circle_fill(own), "videocam", theme::text()),
54 CallIcon::Record => (
51 CallIcon::Record | CallIcon::Saved => (
55 52 circle_fill(own),
56 "radio_button_checked",
53 "fluent_record",
57 54 theme::accent_text(),
58 55 ),
59 CallIcon::RecordStop => (circle_fill(own), "stop_circle", theme::text()),
56 CallIcon::RecordStop => (circle_fill(own), "fluent_record_stop", theme::text()),
60 57 };
61 58 h_flex()
62 59 .size(px(ICON_CIRCLE))
@@ -161,130 +158,6 @@ fn participant_stack(
161 158 )
162 159 }
163 160
164 fn recording_thumbnail(recording: &RecordingCard, directory: &Directory) -> AnyElement {
165 let image = recording
166 .thumbnail
167 .as_ref()
168 .and_then(|thumbnail| directory.image(&thumbnail.url));
169 match image {
170 Some(entry) => img(entry.path.clone())
171 .size_full()
172 .object_fit(ObjectFit::Cover)
173 .into_any_element(),
174 None => div()
175 .size_full()
176 .bg(theme::code_surface())
177 .into_any_element(),
178 }
179 }
180
181 fn recording_tile(
182 recording: &RecordingCard,
183 index: usize,
184 directory: &Directory,
185 open_recording: RowAction,
186 ) -> Stateful<Div> {
187 div()
188 .id(ElementId::Name(format!("call-recording-{index}").into()))
189 .relative()
190 .w(px(TILE_WIDTH))
191 .h(px(TILE_HEIGHT))
192 .flex_none()
193 .rounded(px(TILE_RADIUS))
194 .overflow_hidden()
195 .cursor_pointer()
196 .hover(|tile| tile.opacity(0.92))
197 .child(recording_thumbnail(recording, directory))
198 .child(
199 h_flex()
200 .absolute()
201 .inset_0()
202 .items_center()
203 .justify_center()
204 .child(
205 h_flex()
206 .size(px(PLAY_CIRCLE))
207 .items_center()
208 .justify_center()
209 .rounded_full()
210 .bg(black().opacity(0.55))
211 .child(symbol("play_arrow", PLAY_GLYPH, theme::white())),
212 ),
213 )
214 .children(recording.duration.clone().map(|duration| {
215 div()
216 .absolute()
217 .bottom(px(DURATION_INSET))
218 .right(px(DURATION_INSET))
219 .px(px(6.))
220 .py(px(1.))
221 .rounded(px(4.))
222 .bg(black().opacity(0.65))
223 .text_size(px(DETAIL_SIZE))
224 .font_weight(FontWeight::SEMIBOLD)
225 .text_color(theme::white())
226 .child(duration)
227 }))
228 .when_some(open_recording, |tile, open| {
229 tile.on_click(move |_, _, cx| open(cx))
230 })
231 }
232
233 fn transcript_chip(index: usize, open_transcript: RowAction) -> Stateful<Div> {
234 h_flex()
235 .id(ElementId::Name(format!("call-transcript-{index}").into()))
236 .h(px(CHIP_HEIGHT))
237 .px(px(10.))
238 .gap(px(6.))
239 .flex_none()
240 .items_center()
241 .rounded(px(6.))
242 .border_1()
243 .border_color(theme::border())
244 .text_size(px(DETAIL_SIZE + 1.))
245 .font_weight(FontWeight::SEMIBOLD)
246 .text_color(theme::text())
247 .cursor_pointer()
248 .hover(|chip| chip.bg(theme::popup_hover()))
249 .child(symbol("description", 15., theme::accent_text()))
250 .child("Transcript")
251 .when_some(open_transcript, |chip, open| {
252 chip.on_click(move |_, _, cx| open(cx))
253 })
254 }
255
256 fn recording_block(
257 recording: &RecordingCard,
258 index: usize,
259 directory: &Directory,
260 open_recording: RowAction,
261 open_transcript: RowAction,
262 ) -> Div {
263 v_flex()
264 .pt(px(4.))
265 .gap(px(8.))
266 .child(recording_tile(recording, index, directory, open_recording))
267 .child(
268 h_flex()
269 .w(px(TILE_WIDTH))
270 .gap(px(8.))
271 .items_center()
272 .child(
273 div()
274 .flex_1()
275 .min_w_0()
276 .truncate()
277 .text_size(px(TITLE_SIZE))
278 .font_weight(FontWeight::SEMIBOLD)
279 .text_color(theme::text())
280 .child(recording.title.clone()),
281 )
282 .when(recording.transcript, |line| {
283 line.child(transcript_chip(index, open_transcript))
284 }),
285 )
286 }
287
288 161 fn card(
289 162 call: &CallCard,
290 163 index: usize,
@@ -292,12 +165,7 @@ fn card(
292 165 actions: CallActions,
293 166 directory: &Directory,
294 167 ) -> Div {
295 let CallActions {
296 call_back,
297 join,
298 open_recording,
299 open_transcript,
300 } = actions;
168 let CallActions { call_back, join, .. } = actions;
301 169 let show_join = call.started && join.is_some();
302 170 let summary = h_flex()
303 171 .gap(px(8.))
@@ -341,9 +209,6 @@ fn card(
341 209 theme::bubble_other()
342 210 })
343 211 .child(summary)
344 .children(call.recording.as_ref().map(|recording| {
345 recording_block(recording, index, directory, open_recording, open_transcript)
346 }))
347 212 }
348 213
349 214 pub(super) fn post_call_card(
@@ -362,6 +227,9 @@ pub(super) fn call_card_row(
362 227 directory: &Directory,
363 228 actions: CallActions,
364 229 ) -> AnyElement {
230 if let Some(notice) = &call.notice {
231 return notice_row(row, call, notice, index, directory, actions.recap);
232 }
365 233 let own = row.own;
366 234 let body = if own {
367 235 h_flex()
@@ -3,11 +3,12 @@ use gpui_kit::prelude::FluentBuilder as _;
3use gpui_kit::*;
3use gpui_kit::*;
4
4
5use super::avatar::person_avatar;
5use super::avatar::person_avatar;
6use super::call_notice::{RecapActions, notice_row};
6use super::message_row::{AVATAR_GAP, AVATAR_SIZE, RowAction, day_separator, new_marker};
7use super::message_row::{AVATAR_GAP, AVATAR_SIZE, RowAction, day_separator, new_marker};
7use super::profile_card::opens_profile;
8use super::profile_card::opens_profile;
8use super::widgets::symbol;
9use super::widgets::symbol;
9use crate::data::Directory;
10use crate::data::Directory;
10use crate::rows::{CallCard, CallIcon, CallParticipant, MessageRow, RecordingCard};
11use crate::rows::{CallCard, CallIcon, CallParticipant, MessageRow};
11use crate::theme;
12use crate::theme;
12
13
13const SERIES_START_GAP: f32 = 8.;
14const SERIES_START_GAP: f32 = 8.;
@@ -20,19 +21,11 @@ const DETAIL_SIZE: f32 = 11.;
20const JOIN_HEIGHT: f32 = 24.;
21const JOIN_HEIGHT: f32 = 24.;
21const PARTICIPANT_AVATAR: f32 = 20.;
22const PARTICIPANT_AVATAR: f32 = 20.;
22const PARTICIPANT_GAP: f32 = 2.;
23const PARTICIPANT_GAP: f32 = 2.;
23const TILE_WIDTH: f32 = 288.;
24const TILE_HEIGHT: f32 = 162.;
25const TILE_RADIUS: f32 = 8.;
26const PLAY_CIRCLE: f32 = 40.;
27const PLAY_GLYPH: f32 = 24.;
28const DURATION_INSET: f32 = 6.;
29const CHIP_HEIGHT: f32 = 26.;
30
24
31pub struct CallActions {
25pub struct CallActions {
32 pub call_back: RowAction,
26 pub call_back: RowAction,
33 pub join: RowAction,
27 pub join: RowAction,
34 pub open_recording: RowAction,
28 pub recap: RecapActions,
35 pub open_transcript: RowAction,
36}
29}
37
30
38impl CallActions {
31impl CallActions {
@@ -40,8 +33,12 @@ impl CallActions {
40 CallActions {
33 CallActions {
41 call_back: None,
34 call_back: None,
42 join: None,
35 join: None,
43 open_recording: None,
36 recap: RecapActions {
44 open_transcript: None,
37 view_recap: None,
38 open_recording: None,
39 transcript: None,
40 share: None,
41 },
45 }
42 }
46 }
43 }
47}
44}
@@ -51,12 +48,12 @@ fn icon_circle(call: &CallCard, own: bool) -> Div {
51 CallIcon::Missed => (theme::red().opacity(0.2), "call_missed", theme::red_soft()),
48 CallIcon::Missed => (theme::red().opacity(0.2), "call_missed", theme::red_soft()),
52 CallIcon::Call => (circle_fill(own), "call", theme::text()),
49 CallIcon::Call => (circle_fill(own), "call", theme::text()),
53 CallIcon::Video => (circle_fill(own), "videocam", theme::text()),
50 CallIcon::Video => (circle_fill(own), "videocam", theme::text()),
54 CallIcon::Record => (
51 CallIcon::Record | CallIcon::Saved => (
55 circle_fill(own),
52 circle_fill(own),
56 "radio_button_checked",
53 "fluent_record",
57 theme::accent_text(),
54 theme::accent_text(),
58 ),
55 ),
59 CallIcon::RecordStop => (circle_fill(own), "stop_circle", theme::text()),
56 CallIcon::RecordStop => (circle_fill(own), "fluent_record_stop", theme::text()),
60 };
57 };
61 h_flex()
58 h_flex()
62 .size(px(ICON_CIRCLE))
59 .size(px(ICON_CIRCLE))
@@ -161,130 +158,6 @@ fn participant_stack(
161 )
158 )
162}
159}
163
160
164fn recording_thumbnail(recording: &RecordingCard, directory: &Directory) -> AnyElement {
165 let image = recording
166 .thumbnail
167 .as_ref()
168 .and_then(|thumbnail| directory.image(&thumbnail.url));
169 match image {
170 Some(entry) => img(entry.path.clone())
171 .size_full()
172 .object_fit(ObjectFit::Cover)
173 .into_any_element(),
174 None => div()
175 .size_full()
176 .bg(theme::code_surface())
177 .into_any_element(),
178 }
179}
180
181fn recording_tile(
182 recording: &RecordingCard,
183 index: usize,
184 directory: &Directory,
185 open_recording: RowAction,
186) -> Stateful<Div> {
187 div()
188 .id(ElementId::Name(format!("call-recording-{index}").into()))
189 .relative()
190 .w(px(TILE_WIDTH))
191 .h(px(TILE_HEIGHT))
192 .flex_none()
193 .rounded(px(TILE_RADIUS))
194 .overflow_hidden()
195 .cursor_pointer()
196 .hover(|tile| tile.opacity(0.92))
197 .child(recording_thumbnail(recording, directory))
198 .child(
199 h_flex()
200 .absolute()
201 .inset_0()
202 .items_center()
203 .justify_center()
204 .child(
205 h_flex()
206 .size(px(PLAY_CIRCLE))
207 .items_center()
208 .justify_center()
209 .rounded_full()
210 .bg(black().opacity(0.55))
211 .child(symbol("play_arrow", PLAY_GLYPH, theme::white())),
212 ),
213 )
214 .children(recording.duration.clone().map(|duration| {
215 div()
216 .absolute()
217 .bottom(px(DURATION_INSET))
218 .right(px(DURATION_INSET))
219 .px(px(6.))
220 .py(px(1.))
221 .rounded(px(4.))
222 .bg(black().opacity(0.65))
223 .text_size(px(DETAIL_SIZE))
224 .font_weight(FontWeight::SEMIBOLD)
225 .text_color(theme::white())
226 .child(duration)
227 }))
228 .when_some(open_recording, |tile, open| {
229 tile.on_click(move |_, _, cx| open(cx))
230 })
231}
232
233fn transcript_chip(index: usize, open_transcript: RowAction) -> Stateful<Div> {
234 h_flex()
235 .id(ElementId::Name(format!("call-transcript-{index}").into()))
236 .h(px(CHIP_HEIGHT))
237 .px(px(10.))
238 .gap(px(6.))
239 .flex_none()
240 .items_center()
241 .rounded(px(6.))
242 .border_1()
243 .border_color(theme::border())
244 .text_size(px(DETAIL_SIZE + 1.))
245 .font_weight(FontWeight::SEMIBOLD)
246 .text_color(theme::text())
247 .cursor_pointer()
248 .hover(|chip| chip.bg(theme::popup_hover()))
249 .child(symbol("description", 15., theme::accent_text()))
250 .child("Transcript")
251 .when_some(open_transcript, |chip, open| {
252 chip.on_click(move |_, _, cx| open(cx))
253 })
254}
255
256fn recording_block(
257 recording: &RecordingCard,
258 index: usize,
259 directory: &Directory,
260 open_recording: RowAction,
261 open_transcript: RowAction,
262) -> Div {
263 v_flex()
264 .pt(px(4.))
265 .gap(px(8.))
266 .child(recording_tile(recording, index, directory, open_recording))
267 .child(
268 h_flex()
269 .w(px(TILE_WIDTH))
270 .gap(px(8.))
271 .items_center()
272 .child(
273 div()
274 .flex_1()
275 .min_w_0()
276 .truncate()
277 .text_size(px(TITLE_SIZE))
278 .font_weight(FontWeight::SEMIBOLD)
279 .text_color(theme::text())
280 .child(recording.title.clone()),
281 )
282 .when(recording.transcript, |line| {
283 line.child(transcript_chip(index, open_transcript))
284 }),
285 )
286}
287
288fn card(
161fn card(
289 call: &CallCard,
162 call: &CallCard,
290 index: usize,
163 index: usize,
@@ -292,12 +165,7 @@ fn card(
292 actions: CallActions,
165 actions: CallActions,
293 directory: &Directory,
166 directory: &Directory,
294) -> Div {
167) -> Div {
295 let CallActions {
168 let CallActions { call_back, join, .. } = actions;
296 call_back,
297 join,
298 open_recording,
299 open_transcript,
300 } = actions;
301 let show_join = call.started && join.is_some();
169 let show_join = call.started && join.is_some();
302 let summary = h_flex()
170 let summary = h_flex()
303 .gap(px(8.))
171 .gap(px(8.))
@@ -341,9 +209,6 @@ fn card(
341 theme::bubble_other()
209 theme::bubble_other()
342 })
210 })
343 .child(summary)
211 .child(summary)
344 .children(call.recording.as_ref().map(|recording| {
345 recording_block(recording, index, directory, open_recording, open_transcript)
346 }))
347}
212}
348
213
349pub(super) fn post_call_card(
214pub(super) fn post_call_card(
@@ -362,6 +227,9 @@ pub(super) fn call_card_row(
362 directory: &Directory,
227 directory: &Directory,
363 actions: CallActions,
228 actions: CallActions,
364) -> AnyElement {
229) -> AnyElement {
230 if let Some(notice) = &call.notice {
231 return notice_row(row, call, notice, index, directory, actions.recap);
232 }
365 let own = row.own;
233 let own = row.own;
366 let body = if own {
234 let body = if own {
367 h_flex()
235 h_flex()
crates/app/src/views/call_notice.rs added +379 −0
@@ -0,0 +1,379 @@
1 use gpui_kit::component::{h_flex, v_flex};
2 use gpui_kit::prelude::FluentBuilder as _;
3 use gpui_kit::*;
4
5 use super::message_row::{AVATAR_GAP, AVATAR_SIZE, RowAction, day_separator, new_marker};
6 use super::widgets::symbol;
7 use crate::data::Directory;
8 use crate::rows::{CallCard, CallIcon, CallNotice, MessageRow, RecapCard, RecordingCard};
9 use crate::theme;
10
11 const ROW_TOP: f32 = 8.;
12 const LINE_HEIGHT: f32 = 20.;
13 const TEXT_SIZE: f32 = 12.;
14 const ICON_SIZE: f32 = 20.;
15 const STAMP_GAP: &str = "\u{2003}";
16 const CARD_TOP: f32 = 14.;
17 const CARD_MAX_WIDTH: f32 = 646.;
18 const CARD_RADIUS: f32 = 8.;
19 const CARD_PADDING_X: f32 = 20.;
20 const CARD_PADDING_TOP: f32 = 14.;
21 const TITLE_SIZE: f32 = 16.;
22 const BUTTON_HEIGHT: f32 = 32.;
23 const BUTTON_RADIUS: f32 = 4.;
24 const VIEW_RECAP_WIDTH: f32 = 108.;
25 const VIEW_RECAP_SIZE: f32 = 14.;
26 const DIVIDER_GAP: f32 = 12.;
27 const CONTENT_GAP_TOP: f32 = 12.;
28 const CONTENT_GAP_BOTTOM: f32 = 16.;
29 const CHIP_MIN_WIDTH: f32 = 96.;
30 const CHIP_ICON_GAP: f32 = 6.;
31 const THUMB_WIDTH: f32 = 108.;
32 const THUMB_HEIGHT: f32 = 60.;
33 const THUMB_RADIUS: f32 = 6.;
34 const BADGE_INSET_RIGHT: f32 = 6.;
35 const BADGE_INSET_BOTTOM: f32 = 8.;
36 const EXPIRY_SIZE: f32 = 10.;
37 const EXPIRY_LINE: f32 = 24.;
38 const EXPIRY_ICON_GAP: f32 = 4.;
39 const CONTENT_LABEL: &str = "Content";
40
41 pub struct RecapActions {
42 pub view_recap: RowAction,
43 pub open_recording: RowAction,
44 pub transcript: RowAction,
45 pub share: RowAction,
46 }
47
48 fn notice_icon(icon: CallIcon) -> (&'static str, Hsla) {
49 match icon {
50 CallIcon::Record => ("fluent_record", theme::accent_text()),
51 CallIcon::RecordStop => ("fluent_record_stop", theme::text_muted()),
52 CallIcon::Saved => ("fluent_cloud_arrow_up", theme::text_muted()),
53 CallIcon::Video | CallIcon::Call | CallIcon::Missed => {
54 ("fluent_video", theme::text_muted())
55 }
56 }
57 }
58
59 fn notice_text(notice: &CallNotice) -> StyledText {
60 let mut text = format!("{}{STAMP_GAP}{}", notice.stamp, notice.text);
61 let mut highlights = Vec::new();
62 if let Some(emphasis) = &notice.emphasis {
63 text.push('\u{a0}');
64 let start = text.len();
65 text.push_str(emphasis);
66 highlights.push((
67 start..text.len(),
68 HighlightStyle {
69 font_weight: Some(FontWeight::BOLD),
70 ..HighlightStyle::default()
71 },
72 ));
73 }
74 StyledText::new(text).with_highlights(highlights)
75 }
76
77 fn plain_button(id: String, action: RowAction) -> Stateful<Div> {
78 h_flex()
79 .id(ElementId::Name(id.into()))
80 .h(px(BUTTON_HEIGHT))
81 .flex_none()
82 .items_center()
83 .justify_center()
84 .rounded(px(BUTTON_RADIUS))
85 .cursor_pointer()
86 .when_some(action, |button, action| {
87 button.on_click(move |_, _, cx| action(cx))
88 })
89 }
90
91 fn recap_header(recap: &RecapCard, index: usize, open: RowAction, share: RowAction) -> Div {
92 h_flex()
93 .w_full()
94 .items_start()
95 .gap(px(4.))
96 .child(
97 v_flex()
98 .flex_1()
99 .min_w_0()
100 .line_height(px(LINE_HEIGHT))
101 .child(
102 div()
103 .truncate()
104 .text_size(px(TITLE_SIZE))
105 .font_weight(FontWeight::SEMIBOLD)
106 .text_color(theme::text())
107 .child(recap.title.clone()),
108 )
109 .child(
110 div()
111 .truncate()
112 .text_size(px(TEXT_SIZE))
113 .text_color(theme::text_muted())
114 .child(recap.date_line.clone()),
115 ),
116 )
117 .child(
118 h_flex()
119 .pt(px(2.))
120 .gap(px(4.))
121 .child(
122 plain_button(format!("recap-share-{index}"), share)
123 .w(px(BUTTON_HEIGHT))
124 .hover(|button| button.bg(theme::popup_hover()))
125 .child(symbol("fluent_share", ICON_SIZE, theme::text_soft())),
126 )
127 .child(
128 plain_button(format!("recap-view-{index}"), open)
129 .w(px(VIEW_RECAP_WIDTH))
130 .bg(theme::accent())
131 .hover(|button| button.opacity(0.85))
132 .text_size(px(VIEW_RECAP_SIZE))
133 .font_weight(FontWeight::SEMIBOLD)
134 .text_color(theme::white())
135 .child("View recap"),
136 ),
137 )
138 }
139
140 fn divider() -> Div {
141 div()
142 .w_full()
143 .py(px(DIVIDER_GAP))
144 .child(div().w_full().h(px(1.)).bg(theme::border_strong()))
145 }
146
147 fn transcript_chip(index: usize, transcript: RowAction) -> Stateful<Div> {
148 plain_button(format!("recap-transcript-{index}"), transcript)
149 .min_w(px(CHIP_MIN_WIDTH))
150 .px(px(8.))
151 .gap(px(CHIP_ICON_GAP))
152 .border_1()
153 .border_color(theme::border_strong())
154 .bg(theme::bubble_other())
155 .hover(|chip| chip.bg(theme::popup_hover()))
156 .text_size(px(TEXT_SIZE))
157 .font_weight(FontWeight::SEMIBOLD)
158 .text_color(theme::text())
159 .child(symbol(
160 "fluent_document_text",
161 ICON_SIZE,
162 theme::accent_text(),
163 ))
164 .child("Transcript")
165 }
166
167 fn thumbnail_image(recording: &RecordingCard, directory: &Directory) -> AnyElement {
168 let image = recording
169 .thumbnail
170 .as_ref()
171 .and_then(|thumbnail| directory.image(&thumbnail.url));
172 match image {
173 Some(entry) => img(entry.path.clone())
174 .size_full()
175 .object_fit(ObjectFit::Cover)
176 .into_any_element(),
177 None => h_flex()
178 .size_full()
179 .items_center()
180 .justify_center()
181 .bg(theme::code_surface())
182 .when(recording.duration.is_none(), |tile| {
183 tile.child(symbol("fluent_video", ICON_SIZE, theme::text()))
184 })
185 .into_any_element(),
186 }
187 }
188
189 fn recording_thumbnail(
190 recording: &RecordingCard,
191 index: usize,
192 directory: &Directory,
193 open: RowAction,
194 ) -> Div {
195 v_flex()
196 .w(px(THUMB_WIDTH))
197 .flex_none()
198 .child(
199 div()
200 .id(ElementId::Name(format!("recap-recording-{index}").into()))
201 .relative()
202 .w(px(THUMB_WIDTH))
203 .h(px(THUMB_HEIGHT))
204 .rounded(px(THUMB_RADIUS))
205 .overflow_hidden()
206 .cursor_pointer()
207 .hover(|tile| tile.opacity(0.92))
208 .child(thumbnail_image(recording, directory))
209 .children(recording.duration.clone().map(|duration| {
210 div()
211 .absolute()
212 .right(px(BADGE_INSET_RIGHT))
213 .bottom(px(BADGE_INSET_BOTTOM))
214 .px(px(6.))
215 .py(px(1.))
216 .rounded(px(2.))
217 .bg(black().opacity(0.5))
218 .text_size(px(TEXT_SIZE))
219 .line_height(px(16.))
220 .text_color(theme::white())
221 .child(duration)
222 }))
223 .when_some(open, |tile, open| tile.on_click(move |_, _, cx| open(cx))),
224 )
225 .children(recording.expires_in_days.map(|days| {
226 h_flex()
227 .h(px(EXPIRY_LINE))
228 .justify_center()
229 .items_center()
230 .gap(px(EXPIRY_ICON_GAP))
231 .text_size(px(EXPIRY_SIZE))
232 .text_color(theme::text_muted())
233 .child(symbol("fluent_clock", EXPIRY_SIZE, theme::text_muted()))
234 .child(if days == 1 {
235 "Expires in 1 day".to_owned()
236 } else {
237 format!("Expires in {days} days")
238 })
239 }))
240 }
241
242 fn recap_card(
243 recap: &RecapCard,
244 index: usize,
245 directory: &Directory,
246 actions: RecapActions,
247 ) -> Div {
248 let RecapActions {
249 view_recap,
250 open_recording,
251 transcript,
252 share,
253 } = actions;
254 v_flex()
255 .mt(px(CARD_TOP))
256 .w_full()
257 .max_w(px(CARD_MAX_WIDTH))
258 .pt(px(CARD_PADDING_TOP))
259 .px(px(CARD_PADDING_X))
260 .rounded(px(CARD_RADIUS))
261 .bg(theme::bubble_other())
262 .shadow(card_shadow())
263 .child(recap_header(recap, index, view_recap, share))
264 .child(divider())
265 .child(
266 h_flex()
267 .w_full()
268 .items_start()
269 .child(
270 v_flex()
271 .flex_1()
272 .min_w_0()
273 .child(
274 div()
275 .text_size(px(TEXT_SIZE))
276 .line_height(px(16.))
277 .font_weight(FontWeight::SEMIBOLD)
278 .text_color(theme::text_soft())
279 .child(CONTENT_LABEL),
280 )
281 .child(
282 h_flex()
283 .mt(px(CONTENT_GAP_TOP))
284 .mb(px(CONTENT_GAP_BOTTOM))
285 .when(recap.recording.transcript, |chips| {
286 chips.child(transcript_chip(index, transcript))
287 }),
288 ),
289 )
290 .child(recording_thumbnail(
291 &recap.recording,
292 index,
293 directory,
294 open_recording,
295 )),
296 )
297 }
298
299 fn card_shadow() -> Vec<BoxShadow> {
300 vec![
301 BoxShadow {
302 color: hsla(0., 0., 0., 0.24),
303 offset: point(px(0.), px(0.)),
304 blur_radius: px(1.),
305 spread_radius: px(0.),
306 inset: false,
307 },
308 BoxShadow {
309 color: hsla(0., 0., 0., 0.28),
310 offset: point(px(0.), px(2.)),
311 blur_radius: px(2.),
312 spread_radius: px(0.),
313 inset: false,
314 },
315 ]
316 }
317
318 pub(super) fn notice_line(
319 call: &CallCard,
320 notice: &CallNotice,
321 index: usize,
322 directory: &Directory,
323 actions: RecapActions,
324 ) -> Div {
325 let (glyph, tint) = notice_icon(call.icon);
326 h_flex()
327 .w_full()
328 .pt(px(ROW_TOP))
329 .items_start()
330 .gap(px(AVATAR_GAP))
331 .child(
332 h_flex()
333 .w(px(AVATAR_SIZE))
334 .h(px(LINE_HEIGHT))
335 .flex_none()
336 .justify_center()
337 .items_center()
338 .child(symbol(glyph, ICON_SIZE, tint)),
339 )
340 .child(
341 v_flex()
342 .flex_1()
343 .min_w_0()
344 .child(
345 div()
346 .text_size(px(TEXT_SIZE))
347 .line_height(px(LINE_HEIGHT))
348 .text_color(theme::text_muted())
349 .child(notice_text(notice)),
350 )
351 .children(
352 call.recap
353 .as_ref()
354 .map(|recap| recap_card(recap, index, directory, actions)),
355 ),
356 )
357 }
358
359 pub(super) fn notice_row(
360 row: &MessageRow,
361 call: &CallCard,
362 notice: &CallNotice,
363 index: usize,
364 directory: &Directory,
365 actions: RecapActions,
366 ) -> AnyElement {
367 v_flex()
368 .w_full()
369 .px(px(20.))
370 .children(row.day_header.as_deref().map(day_separator))
371 .when(row.new_marker, |column| column.child(new_marker()))
372 .child(
373 div()
374 .id(ElementId::Name(format!("row-{index}").into()))
375 .w_full()
376 .child(notice_line(call, notice, index, directory, actions)),
377 )
378 .into_any_element()
379 }
@@ -0,0 +1,379 @@
1use gpui_kit::component::{h_flex, v_flex};
2use gpui_kit::prelude::FluentBuilder as _;
3use gpui_kit::*;
4
5use super::message_row::{AVATAR_GAP, AVATAR_SIZE, RowAction, day_separator, new_marker};
6use super::widgets::symbol;
7use crate::data::Directory;
8use crate::rows::{CallCard, CallIcon, CallNotice, MessageRow, RecapCard, RecordingCard};
9use crate::theme;
10
11const ROW_TOP: f32 = 8.;
12const LINE_HEIGHT: f32 = 20.;
13const TEXT_SIZE: f32 = 12.;
14const ICON_SIZE: f32 = 20.;
15const STAMP_GAP: &str = "\u{2003}";
16const CARD_TOP: f32 = 14.;
17const CARD_MAX_WIDTH: f32 = 646.;
18const CARD_RADIUS: f32 = 8.;
19const CARD_PADDING_X: f32 = 20.;
20const CARD_PADDING_TOP: f32 = 14.;
21const TITLE_SIZE: f32 = 16.;
22const BUTTON_HEIGHT: f32 = 32.;
23const BUTTON_RADIUS: f32 = 4.;
24const VIEW_RECAP_WIDTH: f32 = 108.;
25const VIEW_RECAP_SIZE: f32 = 14.;
26const DIVIDER_GAP: f32 = 12.;
27const CONTENT_GAP_TOP: f32 = 12.;
28const CONTENT_GAP_BOTTOM: f32 = 16.;
29const CHIP_MIN_WIDTH: f32 = 96.;
30const CHIP_ICON_GAP: f32 = 6.;
31const THUMB_WIDTH: f32 = 108.;
32const THUMB_HEIGHT: f32 = 60.;
33const THUMB_RADIUS: f32 = 6.;
34const BADGE_INSET_RIGHT: f32 = 6.;
35const BADGE_INSET_BOTTOM: f32 = 8.;
36const EXPIRY_SIZE: f32 = 10.;
37const EXPIRY_LINE: f32 = 24.;
38const EXPIRY_ICON_GAP: f32 = 4.;
39const CONTENT_LABEL: &str = "Content";
40
41pub struct RecapActions {
42 pub view_recap: RowAction,
43 pub open_recording: RowAction,
44 pub transcript: RowAction,
45 pub share: RowAction,
46}
47
48fn notice_icon(icon: CallIcon) -> (&'static str, Hsla) {
49 match icon {
50 CallIcon::Record => ("fluent_record", theme::accent_text()),
51 CallIcon::RecordStop => ("fluent_record_stop", theme::text_muted()),
52 CallIcon::Saved => ("fluent_cloud_arrow_up", theme::text_muted()),
53 CallIcon::Video | CallIcon::Call | CallIcon::Missed => {
54 ("fluent_video", theme::text_muted())
55 }
56 }
57}
58
59fn notice_text(notice: &CallNotice) -> StyledText {
60 let mut text = format!("{}{STAMP_GAP}{}", notice.stamp, notice.text);
61 let mut highlights = Vec::new();
62 if let Some(emphasis) = &notice.emphasis {
63 text.push('\u{a0}');
64 let start = text.len();
65 text.push_str(emphasis);
66 highlights.push((
67 start..text.len(),
68 HighlightStyle {
69 font_weight: Some(FontWeight::BOLD),
70 ..HighlightStyle::default()
71 },
72 ));
73 }
74 StyledText::new(text).with_highlights(highlights)
75}
76
77fn plain_button(id: String, action: RowAction) -> Stateful<Div> {
78 h_flex()
79 .id(ElementId::Name(id.into()))
80 .h(px(BUTTON_HEIGHT))
81 .flex_none()
82 .items_center()
83 .justify_center()
84 .rounded(px(BUTTON_RADIUS))
85 .cursor_pointer()
86 .when_some(action, |button, action| {
87 button.on_click(move |_, _, cx| action(cx))
88 })
89}
90
91fn recap_header(recap: &RecapCard, index: usize, open: RowAction, share: RowAction) -> Div {
92 h_flex()
93 .w_full()
94 .items_start()
95 .gap(px(4.))
96 .child(
97 v_flex()
98 .flex_1()
99 .min_w_0()
100 .line_height(px(LINE_HEIGHT))
101 .child(
102 div()
103 .truncate()
104 .text_size(px(TITLE_SIZE))
105 .font_weight(FontWeight::SEMIBOLD)
106 .text_color(theme::text())
107 .child(recap.title.clone()),
108 )
109 .child(
110 div()
111 .truncate()
112 .text_size(px(TEXT_SIZE))
113 .text_color(theme::text_muted())
114 .child(recap.date_line.clone()),
115 ),
116 )
117 .child(
118 h_flex()
119 .pt(px(2.))
120 .gap(px(4.))
121 .child(
122 plain_button(format!("recap-share-{index}"), share)
123 .w(px(BUTTON_HEIGHT))
124 .hover(|button| button.bg(theme::popup_hover()))
125 .child(symbol("fluent_share", ICON_SIZE, theme::text_soft())),
126 )
127 .child(
128 plain_button(format!("recap-view-{index}"), open)
129 .w(px(VIEW_RECAP_WIDTH))
130 .bg(theme::accent())
131 .hover(|button| button.opacity(0.85))
132 .text_size(px(VIEW_RECAP_SIZE))
133 .font_weight(FontWeight::SEMIBOLD)
134 .text_color(theme::white())
135 .child("View recap"),
136 ),
137 )
138}
139
140fn divider() -> Div {
141 div()
142 .w_full()
143 .py(px(DIVIDER_GAP))
144 .child(div().w_full().h(px(1.)).bg(theme::border_strong()))
145}
146
147fn transcript_chip(index: usize, transcript: RowAction) -> Stateful<Div> {
148 plain_button(format!("recap-transcript-{index}"), transcript)
149 .min_w(px(CHIP_MIN_WIDTH))
150 .px(px(8.))
151 .gap(px(CHIP_ICON_GAP))
152 .border_1()
153 .border_color(theme::border_strong())
154 .bg(theme::bubble_other())
155 .hover(|chip| chip.bg(theme::popup_hover()))
156 .text_size(px(TEXT_SIZE))
157 .font_weight(FontWeight::SEMIBOLD)
158 .text_color(theme::text())
159 .child(symbol(
160 "fluent_document_text",
161 ICON_SIZE,
162 theme::accent_text(),
163 ))
164 .child("Transcript")
165}
166
167fn thumbnail_image(recording: &RecordingCard, directory: &Directory) -> AnyElement {
168 let image = recording
169 .thumbnail
170 .as_ref()
171 .and_then(|thumbnail| directory.image(&thumbnail.url));
172 match image {
173 Some(entry) => img(entry.path.clone())
174 .size_full()
175 .object_fit(ObjectFit::Cover)
176 .into_any_element(),
177 None => h_flex()
178 .size_full()
179 .items_center()
180 .justify_center()
181 .bg(theme::code_surface())
182 .when(recording.duration.is_none(), |tile| {
183 tile.child(symbol("fluent_video", ICON_SIZE, theme::text()))
184 })
185 .into_any_element(),
186 }
187}
188
189fn recording_thumbnail(
190 recording: &RecordingCard,
191 index: usize,
192 directory: &Directory,
193 open: RowAction,
194) -> Div {
195 v_flex()
196 .w(px(THUMB_WIDTH))
197 .flex_none()
198 .child(
199 div()
200 .id(ElementId::Name(format!("recap-recording-{index}").into()))
201 .relative()
202 .w(px(THUMB_WIDTH))
203 .h(px(THUMB_HEIGHT))
204 .rounded(px(THUMB_RADIUS))
205 .overflow_hidden()
206 .cursor_pointer()
207 .hover(|tile| tile.opacity(0.92))
208 .child(thumbnail_image(recording, directory))
209 .children(recording.duration.clone().map(|duration| {
210 div()
211 .absolute()
212 .right(px(BADGE_INSET_RIGHT))
213 .bottom(px(BADGE_INSET_BOTTOM))
214 .px(px(6.))
215 .py(px(1.))
216 .rounded(px(2.))
217 .bg(black().opacity(0.5))
218 .text_size(px(TEXT_SIZE))
219 .line_height(px(16.))
220 .text_color(theme::white())
221 .child(duration)
222 }))
223 .when_some(open, |tile, open| tile.on_click(move |_, _, cx| open(cx))),
224 )
225 .children(recording.expires_in_days.map(|days| {
226 h_flex()
227 .h(px(EXPIRY_LINE))
228 .justify_center()
229 .items_center()
230 .gap(px(EXPIRY_ICON_GAP))
231 .text_size(px(EXPIRY_SIZE))
232 .text_color(theme::text_muted())
233 .child(symbol("fluent_clock", EXPIRY_SIZE, theme::text_muted()))
234 .child(if days == 1 {
235 "Expires in 1 day".to_owned()
236 } else {
237 format!("Expires in {days} days")
238 })
239 }))
240}
241
242fn recap_card(
243 recap: &RecapCard,
244 index: usize,
245 directory: &Directory,
246 actions: RecapActions,
247) -> Div {
248 let RecapActions {
249 view_recap,
250 open_recording,
251 transcript,
252 share,
253 } = actions;
254 v_flex()
255 .mt(px(CARD_TOP))
256 .w_full()
257 .max_w(px(CARD_MAX_WIDTH))
258 .pt(px(CARD_PADDING_TOP))
259 .px(px(CARD_PADDING_X))
260 .rounded(px(CARD_RADIUS))
261 .bg(theme::bubble_other())
262 .shadow(card_shadow())
263 .child(recap_header(recap, index, view_recap, share))
264 .child(divider())
265 .child(
266 h_flex()
267 .w_full()
268 .items_start()
269 .child(
270 v_flex()
271 .flex_1()
272 .min_w_0()
273 .child(
274 div()
275 .text_size(px(TEXT_SIZE))
276 .line_height(px(16.))
277 .font_weight(FontWeight::SEMIBOLD)
278 .text_color(theme::text_soft())
279 .child(CONTENT_LABEL),
280 )
281 .child(
282 h_flex()
283 .mt(px(CONTENT_GAP_TOP))
284 .mb(px(CONTENT_GAP_BOTTOM))
285 .when(recap.recording.transcript, |chips| {
286 chips.child(transcript_chip(index, transcript))
287 }),
288 ),
289 )
290 .child(recording_thumbnail(
291 &recap.recording,
292 index,
293 directory,
294 open_recording,
295 )),
296 )
297}
298
299fn card_shadow() -> Vec<BoxShadow> {
300 vec![
301 BoxShadow {
302 color: hsla(0., 0., 0., 0.24),
303 offset: point(px(0.), px(0.)),
304 blur_radius: px(1.),
305 spread_radius: px(0.),
306 inset: false,
307 },
308 BoxShadow {
309 color: hsla(0., 0., 0., 0.28),
310 offset: point(px(0.), px(2.)),
311 blur_radius: px(2.),
312 spread_radius: px(0.),
313 inset: false,
314 },
315 ]
316}
317
318pub(super) fn notice_line(
319 call: &CallCard,
320 notice: &CallNotice,
321 index: usize,
322 directory: &Directory,
323 actions: RecapActions,
324) -> Div {
325 let (glyph, tint) = notice_icon(call.icon);
326 h_flex()
327 .w_full()
328 .pt(px(ROW_TOP))
329 .items_start()
330 .gap(px(AVATAR_GAP))
331 .child(
332 h_flex()
333 .w(px(AVATAR_SIZE))
334 .h(px(LINE_HEIGHT))
335 .flex_none()
336 .justify_center()
337 .items_center()
338 .child(symbol(glyph, ICON_SIZE, tint)),
339 )
340 .child(
341 v_flex()
342 .flex_1()
343 .min_w_0()
344 .child(
345 div()
346 .text_size(px(TEXT_SIZE))
347 .line_height(px(LINE_HEIGHT))
348 .text_color(theme::text_muted())
349 .child(notice_text(notice)),
350 )
351 .children(
352 call.recap
353 .as_ref()
354 .map(|recap| recap_card(recap, index, directory, actions)),
355 ),
356 )
357}
358
359pub(super) fn notice_row(
360 row: &MessageRow,
361 call: &CallCard,
362 notice: &CallNotice,
363 index: usize,
364 directory: &Directory,
365 actions: RecapActions,
366) -> AnyElement {
367 v_flex()
368 .w_full()
369 .px(px(20.))
370 .children(row.day_header.as_deref().map(day_separator))
371 .when(row.new_marker, |column| column.child(new_marker()))
372 .child(
373 div()
374 .id(ElementId::Name(format!("row-{index}").into()))
375 .w_full()
376 .child(notice_line(call, notice, index, directory, actions)),
377 )
378 .into_any_element()
379}
crates/app/src/views/conversation.rs +2 −1
@@ -643,7 +643,7 @@ impl ConversationView {
643 643 | AppEvent::Forward
644 644 | AppEvent::ImageViewer
645 645 | AppEvent::StatusMessage
646 | AppEvent::NotificationSettings
646 | AppEvent::Settings(_)
647 647 | AppEvent::Profile
648 648 | AppEvent::CallHistory
649 649 | AppEvent::Ring
@@ -1273,6 +1273,7 @@ impl ConversationView {
1273 1273 card_overrides,
1274 1274 translation,
1275 1275 skin_tone: teams_core::skin_tone(&app.store),
1276 meeting: self.meeting_info(app),
1276 1277 }
1277 1278 }
1278 1279
@@ -643,7 +643,7 @@ impl ConversationView {
643 | AppEvent::Forward
643 | AppEvent::Forward
644 | AppEvent::ImageViewer
644 | AppEvent::ImageViewer
645 | AppEvent::StatusMessage
645 | AppEvent::StatusMessage
646 | AppEvent::NotificationSettings
646 | AppEvent::Settings(_)
647 | AppEvent::Profile
647 | AppEvent::Profile
648 | AppEvent::CallHistory
648 | AppEvent::CallHistory
649 | AppEvent::Ring
649 | AppEvent::Ring
@@ -1273,6 +1273,7 @@ impl ConversationView {
1273 card_overrides,
1273 card_overrides,
1274 translation,
1274 translation,
1275 skin_tone: teams_core::skin_tone(&app.store),
1275 skin_tone: teams_core::skin_tone(&app.store),
1276 meeting: self.meeting_info(app),
1276 }
1277 }
1277 }
1278 }
1278
1279
crates/app/src/views/conversation/recap.rs +91 −3
@@ -5,6 +5,7 @@ use std::rc::Rc;
5 5
6 6 use chatsvc::{
7 7 Attendance, Occurrence, Recap, RecordingDetails, TranscriptFormat, TranscriptTurn,
8 days_until_expiry,
8 9 };
9 10 use chrono::Utc;
10 11 use gpui_kit::component::button::{Button, ButtonVariants as _};
@@ -14,7 +15,8 @@ use gpui_kit::component::WindowExt as _;
14 15 use gpui_kit::*;
15 16
16 17 use super::ConversationView;
17 use crate::app_state::Selection;
18 use crate::app_state::{AppState, Selection};
19 use crate::rows::{MeetingInfo, MeetingSlot};
18 20 use crate::channel_files::SharedContent;
19 21 use crate::demo_recap;
20 22 use crate::downloads::{self, DownloadState};
@@ -27,6 +29,7 @@ use crate::views::shared_tab::{SharedCommand, SharedRun};
27 29
28 30 const SEARCH_PLACEHOLDER: &str = "Search transcript";
29 31 const RECORDING_EXTENSION: &str = "mp4";
32 const EXPIRY_OCCURRENCES: usize = 3;
30 33
31 34 pub(super) fn search_input(
32 35 window: &mut Window,
@@ -44,6 +47,7 @@ pub(super) struct RecapState {
44 47 query: String,
45 48 downloads: HashMap<RecapDownload, DownloadState>,
46 49 generation: u64,
50 expiry_days: HashMap<String, i64>,
47 51 }
48 52
49 53 impl Default for RecapState {
@@ -57,6 +61,7 @@ impl Default for RecapState {
57 61 query: String::new(),
58 62 downloads: HashMap::new(),
59 63 generation: 0,
64 expiry_days: HashMap::new(),
60 65 }
61 66 }
62 67 }
@@ -119,7 +124,19 @@ impl ConversationView {
119 124 let state = self.app.read(cx);
120 125 let (demo, engine) = (state.mode.demo, state.engine.clone());
121 126 if demo {
122 self.recap.listing = Load::Ready(demo_recap::occurrences(&conversation_id, Utc::now()));
127 let now = Utc::now();
128 let occurrences = demo_recap::occurrences(&conversation_id, now);
129 self.recap.expiry_days = occurrences
130 .iter()
131 .filter_map(|occurrence| {
132 let expires_at = demo_recap::details(occurrence, now).expires_at?;
133 Some((
134 occurrence.message_id.clone(),
135 days_until_expiry(expires_at, now),
136 ))
137 })
138 .collect();
139 self.recap.listing = Load::Ready(occurrences);
123 140 return;
124 141 }
125 142 let Some(engine) = engine else {
@@ -142,7 +159,10 @@ impl ConversationView {
142 159 return;
143 160 }
144 161 this.recap.listing = match outcome {
145 Ok(occurrences) => Load::Ready(occurrences),
162 Ok(occurrences) => {
163 this.load_expiry(&occurrences, cx);
164 Load::Ready(occurrences)
165 }
146 166 Err(reason) => Load::Failed(reason),
147 167 };
148 168 if this.pane == ChannelPane::Recap {
@@ -155,6 +175,74 @@ impl ConversationView {
155 175 .detach();
156 176 }
157 177
178 /// The chat's recording lines and recap cards say when a recording expires; the value comes
179 /// from the same SharePoint list item the Recap tab reads.
180 fn load_expiry(&mut self, occurrences: &[Occurrence], cx: &mut Context<Self>) {
181 let (Some(engine), Some(conversation_id)) =
182 (self.app.read(cx).engine.clone(), self.conversation_id())
183 else {
184 return;
185 };
186 let newest: Vec<Occurrence> = occurrences
187 .iter()
188 .take(EXPIRY_OCCURRENCES)
189 .cloned()
190 .collect();
191 if newest.is_empty() {
192 return;
193 }
194 let receiver = runtime::spawn(async move {
195 let recap = Recap::new(engine.remote().session());
196 let mut found = Vec::new();
197 for occurrence in newest {
198 if let Ok(details) = recap.details(&occurrence).await {
199 found.push((occurrence.message_id, details.expires_at));
200 }
201 }
202 found
203 });
204 cx.spawn(async move |this, cx| {
205 let Ok(found) = receiver.await else {
206 return;
207 };
208 this.update(cx, |this, cx| {
209 if this.conversation_id().as_deref() != Some(conversation_id.as_str()) {
210 return;
211 }
212 let now = Utc::now();
213 this.recap.expiry_days = found
214 .into_iter()
215 .filter_map(|(message_id, expires_at)| {
216 Some((message_id, days_until_expiry(expires_at?, now)))
217 })
218 .collect();
219 this.rebuild(false, cx);
220 })
221 .ok();
222 })
223 .detach();
224 }
225
226 pub(super) fn meeting_info(&self, app: &AppState) -> MeetingInfo {
227 let Some(current) = self.current.as_ref() else {
228 return MeetingInfo::default();
229 };
230 let conversation_id = current.selection.conversation_id();
231 MeetingInfo {
232 title: Some(current.title.clone()),
233 slots: app
234 .calendar_events
235 .iter()
236 .filter(|event| event.thread_id.as_deref() == Some(conversation_id))
237 .map(|event| MeetingSlot {
238 start: event.start,
239 end: event.end,
240 })
241 .collect(),
242 expiry_days: self.recap.expiry_days.clone(),
243 }
244 }
245
158 246 /// Teams opens a meeting chat recording in the Recap tab at its occurrence and plays any
159 247 /// other recording (channel meetings) in the browser.
160 248 pub(super) fn open_recording(
@@ -5,6 +5,7 @@ use std::rc::Rc;
5
5
6use chatsvc::{
6use chatsvc::{
7 Attendance, Occurrence, Recap, RecordingDetails, TranscriptFormat, TranscriptTurn,
7 Attendance, Occurrence, Recap, RecordingDetails, TranscriptFormat, TranscriptTurn,
8 days_until_expiry,
8};
9};
9use chrono::Utc;
10use chrono::Utc;
10use gpui_kit::component::button::{Button, ButtonVariants as _};
11use gpui_kit::component::button::{Button, ButtonVariants as _};
@@ -14,7 +15,8 @@ use gpui_kit::component::WindowExt as _;
14use gpui_kit::*;
15use gpui_kit::*;
15
16
16use super::ConversationView;
17use super::ConversationView;
17use crate::app_state::Selection;
18use crate::app_state::{AppState, Selection};
19use crate::rows::{MeetingInfo, MeetingSlot};
18use crate::channel_files::SharedContent;
20use crate::channel_files::SharedContent;
19use crate::demo_recap;
21use crate::demo_recap;
20use crate::downloads::{self, DownloadState};
22use crate::downloads::{self, DownloadState};
@@ -27,6 +29,7 @@ use crate::views::shared_tab::{SharedCommand, SharedRun};
27
29
28const SEARCH_PLACEHOLDER: &str = "Search transcript";
30const SEARCH_PLACEHOLDER: &str = "Search transcript";
29const RECORDING_EXTENSION: &str = "mp4";
31const RECORDING_EXTENSION: &str = "mp4";
32const EXPIRY_OCCURRENCES: usize = 3;
30
33
31pub(super) fn search_input(
34pub(super) fn search_input(
32 window: &mut Window,
35 window: &mut Window,
@@ -44,6 +47,7 @@ pub(super) struct RecapState {
44 query: String,
47 query: String,
45 downloads: HashMap<RecapDownload, DownloadState>,
48 downloads: HashMap<RecapDownload, DownloadState>,
46 generation: u64,
49 generation: u64,
50 expiry_days: HashMap<String, i64>,
47}
51}
48
52
49impl Default for RecapState {
53impl Default for RecapState {
@@ -57,6 +61,7 @@ impl Default for RecapState {
57 query: String::new(),
61 query: String::new(),
58 downloads: HashMap::new(),
62 downloads: HashMap::new(),
59 generation: 0,
63 generation: 0,
64 expiry_days: HashMap::new(),
60 }
65 }
61 }
66 }
62}
67}
@@ -119,7 +124,19 @@ impl ConversationView {
119 let state = self.app.read(cx);
124 let state = self.app.read(cx);
120 let (demo, engine) = (state.mode.demo, state.engine.clone());
125 let (demo, engine) = (state.mode.demo, state.engine.clone());
121 if demo {
126 if demo {
122 self.recap.listing = Load::Ready(demo_recap::occurrences(&conversation_id, Utc::now()));
127 let now = Utc::now();
128 let occurrences = demo_recap::occurrences(&conversation_id, now);
129 self.recap.expiry_days = occurrences
130 .iter()
131 .filter_map(|occurrence| {
132 let expires_at = demo_recap::details(occurrence, now).expires_at?;
133 Some((
134 occurrence.message_id.clone(),
135 days_until_expiry(expires_at, now),
136 ))
137 })
138 .collect();
139 self.recap.listing = Load::Ready(occurrences);
123 return;
140 return;
124 }
141 }
125 let Some(engine) = engine else {
142 let Some(engine) = engine else {
@@ -142,7 +159,10 @@ impl ConversationView {
142 return;
159 return;
143 }
160 }
144 this.recap.listing = match outcome {
161 this.recap.listing = match outcome {
145 Ok(occurrences) => Load::Ready(occurrences),
162 Ok(occurrences) => {
163 this.load_expiry(&occurrences, cx);
164 Load::Ready(occurrences)
165 }
146 Err(reason) => Load::Failed(reason),
166 Err(reason) => Load::Failed(reason),
147 };
167 };
148 if this.pane == ChannelPane::Recap {
168 if this.pane == ChannelPane::Recap {
@@ -155,6 +175,74 @@ impl ConversationView {
155 .detach();
175 .detach();
156 }
176 }
157
177
178 /// The chat's recording lines and recap cards say when a recording expires; the value comes
179 /// from the same SharePoint list item the Recap tab reads.
180 fn load_expiry(&mut self, occurrences: &[Occurrence], cx: &mut Context<Self>) {
181 let (Some(engine), Some(conversation_id)) =
182 (self.app.read(cx).engine.clone(), self.conversation_id())
183 else {
184 return;
185 };
186 let newest: Vec<Occurrence> = occurrences
187 .iter()
188 .take(EXPIRY_OCCURRENCES)
189 .cloned()
190 .collect();
191 if newest.is_empty() {
192 return;
193 }
194 let receiver = runtime::spawn(async move {
195 let recap = Recap::new(engine.remote().session());
196 let mut found = Vec::new();
197 for occurrence in newest {
198 if let Ok(details) = recap.details(&occurrence).await {
199 found.push((occurrence.message_id, details.expires_at));
200 }
201 }
202 found
203 });
204 cx.spawn(async move |this, cx| {
205 let Ok(found) = receiver.await else {
206 return;
207 };
208 this.update(cx, |this, cx| {
209 if this.conversation_id().as_deref() != Some(conversation_id.as_str()) {
210 return;
211 }
212 let now = Utc::now();
213 this.recap.expiry_days = found
214 .into_iter()
215 .filter_map(|(message_id, expires_at)| {
216 Some((message_id, days_until_expiry(expires_at?, now)))
217 })
218 .collect();
219 this.rebuild(false, cx);
220 })
221 .ok();
222 })
223 .detach();
224 }
225
226 pub(super) fn meeting_info(&self, app: &AppState) -> MeetingInfo {
227 let Some(current) = self.current.as_ref() else {
228 return MeetingInfo::default();
229 };
230 let conversation_id = current.selection.conversation_id();
231 MeetingInfo {
232 title: Some(current.title.clone()),
233 slots: app
234 .calendar_events
235 .iter()
236 .filter(|event| event.thread_id.as_deref() == Some(conversation_id))
237 .map(|event| MeetingSlot {
238 start: event.start,
239 end: event.end,
240 })
241 .collect(),
242 expiry_days: self.recap.expiry_days.clone(),
243 }
244 }
245
158 /// Teams opens a meeting chat recording in the Recap tab at its occurrence and plays any
246 /// Teams opens a meeting chat recording in the Recap tab at its occurrence and plays any
159 /// other recording (channel meetings) in the browser.
247 /// other recording (channel meetings) in the browser.
160 pub(super) fn open_recording(
248 pub(super) fn open_recording(
crates/app/src/views/conversation/render_env.rs +12 −3
@@ -15,6 +15,7 @@ use crate::agent_api::agent_label;
15 15 use crate::agents::AgentRun;
16 16 use crate::app_state::AppState;
17 17 use crate::rows::{Delivery, MessageRow, PostRow, RecordingCard};
18 use crate::views::call_notice::RecapActions;
18 19 use crate::scheduled_rows::SCHEDULED_KEY_PREFIX;
19 20 use crate::translation::TranslationLine;
20 21 use crate::views::adaptive_card::{ensure_cards_inputs, request_card_refreshes};
@@ -72,7 +73,7 @@ impl RenderEnv {
72 73 message
73 74 .call
74 75 .as_ref()
75 .and_then(|call| call.recording.as_ref()?.thumbnail.clone()),
76 .and_then(|call| call.recap.as_ref()?.recording.thumbnail.clone()),
76 77 )
77 78 .filter(|image| self.app.read(cx).directory.image(&image.url).is_none())
78 79 .collect();
@@ -340,11 +341,19 @@ impl RenderEnv {
340 341 .ok();
341 342 })
342 343 };
344 let recording = call.recap.as_ref().map(|recap| &recap.recording);
345 let share = recording.and_then(|recording| recording.url.clone()).map(|url| {
346 boxed(move |cx| cx.write_to_clipboard(ClipboardItem::new_string(url.clone())))
347 });
343 348 CallActions {
344 349 call_back,
345 350 join,
346 open_recording: call.recording.as_ref().map(open),
347 open_transcript: call.recording.as_ref().map(open),
351 recap: RecapActions {
352 view_recap: recording.map(open),
353 open_recording: recording.map(open),
354 transcript: recording.map(open),
355 share,
356 },
348 357 }
349 358 }
350 359
@@ -15,6 +15,7 @@ use crate::agent_api::agent_label;
15use crate::agents::AgentRun;
15use crate::agents::AgentRun;
16use crate::app_state::AppState;
16use crate::app_state::AppState;
17use crate::rows::{Delivery, MessageRow, PostRow, RecordingCard};
17use crate::rows::{Delivery, MessageRow, PostRow, RecordingCard};
18use crate::views::call_notice::RecapActions;
18use crate::scheduled_rows::SCHEDULED_KEY_PREFIX;
19use crate::scheduled_rows::SCHEDULED_KEY_PREFIX;
19use crate::translation::TranslationLine;
20use crate::translation::TranslationLine;
20use crate::views::adaptive_card::{ensure_cards_inputs, request_card_refreshes};
21use crate::views::adaptive_card::{ensure_cards_inputs, request_card_refreshes};
@@ -72,7 +73,7 @@ impl RenderEnv {
72 message
73 message
73 .call
74 .call
74 .as_ref()
75 .as_ref()
75 .and_then(|call| call.recording.as_ref()?.thumbnail.clone()),
76 .and_then(|call| call.recap.as_ref()?.recording.thumbnail.clone()),
76 )
77 )
77 .filter(|image| self.app.read(cx).directory.image(&image.url).is_none())
78 .filter(|image| self.app.read(cx).directory.image(&image.url).is_none())
78 .collect();
79 .collect();
@@ -340,11 +341,19 @@ impl RenderEnv {
340 .ok();
341 .ok();
341 })
342 })
342 };
343 };
344 let recording = call.recap.as_ref().map(|recap| &recap.recording);
345 let share = recording.and_then(|recording| recording.url.clone()).map(|url| {
346 boxed(move |cx| cx.write_to_clipboard(ClipboardItem::new_string(url.clone())))
347 });
343 CallActions {
348 CallActions {
344 call_back,
349 call_back,
345 join,
350 join,
346 open_recording: call.recording.as_ref().map(open),
351 recap: RecapActions {
347 open_transcript: call.recording.as_ref().map(open),
352 view_recap: recording.map(open),
353 open_recording: recording.map(open),
354 transcript: recording.map(open),
355 share,
356 },
348 }
357 }
349 }
358 }
350
359
crates/app/src/views/mod.rs +1 −0
@@ -5,6 +5,7 @@ pub mod attachment_tray;
5 5 pub mod attachments;
6 6 pub mod avatar;
7 7 pub mod call_card;
8 pub mod call_notice;
8 9 pub mod call_control_fold;
9 10 pub mod call_end_view;
10 11 pub mod call_controls;
@@ -5,6 +5,7 @@ pub mod attachment_tray;
5pub mod attachments;
5pub mod attachments;
6pub mod avatar;
6pub mod avatar;
7pub mod call_card;
7pub mod call_card;
8pub mod call_notice;
8pub mod call_control_fold;
9pub mod call_control_fold;
9pub mod call_end_view;
10pub mod call_end_view;
10pub mod call_controls;
11pub mod call_controls;
crates/app/src/views/post_card.rs +13 −0
@@ -7,6 +7,7 @@ use super::adaptive_card::cards_view;
7 7 use super::attachments::{attachments_view, message_body};
8 8 use super::avatar::{bot_avatar, person_avatar};
9 9 use super::call_card::{CallActions, post_call_card};
10 use super::call_notice::notice_line;
10 11 use super::link_preview::{link_preview_card, meeting_join_chip};
11 12 use super::message_actions::message_toolbar;
12 13 use super::message_row::{BODY_SIZE, RowActions, delivery_note, forwarded_header, has_text};
@@ -199,6 +200,18 @@ fn message_block(
199 200 Some(bot) => bot_avatar(bot, size),
200 201 None => person_avatar(directory, row.sender_id.as_deref(), &row.author, size),
201 202 };
203 if let (Role::Reply, Some(call)) = (role, &row.call)
204 && let Some(notice) = &call.notice
205 {
206 let recap = std::mem::replace(&mut actions.call, CallActions::none()).recap;
207 return div()
208 .id(ElementId::Name(format!("post-message-{index}").into()))
209 .w_full()
210 .px(px(CARD_PADDING))
211 .pb(px(CARD_PADDING))
212 .bg(theme::reply_surface())
213 .child(notice_line(call, notice, index, directory, recap));
214 }
202 215 let profile_user = row.sender_id.as_deref().filter(|_| actions.bot.is_none());
203 216 let content = match &row.call {
204 217 Some(call) => v_flex().child(post_call_card(
@@ -7,6 +7,7 @@ use super::adaptive_card::cards_view;
7use super::attachments::{attachments_view, message_body};
7use super::attachments::{attachments_view, message_body};
8use super::avatar::{bot_avatar, person_avatar};
8use super::avatar::{bot_avatar, person_avatar};
9use super::call_card::{CallActions, post_call_card};
9use super::call_card::{CallActions, post_call_card};
10use super::call_notice::notice_line;
10use super::link_preview::{link_preview_card, meeting_join_chip};
11use super::link_preview::{link_preview_card, meeting_join_chip};
11use super::message_actions::message_toolbar;
12use super::message_actions::message_toolbar;
12use super::message_row::{BODY_SIZE, RowActions, delivery_note, forwarded_header, has_text};
13use super::message_row::{BODY_SIZE, RowActions, delivery_note, forwarded_header, has_text};
@@ -199,6 +200,18 @@ fn message_block(
199 Some(bot) => bot_avatar(bot, size),
200 Some(bot) => bot_avatar(bot, size),
200 None => person_avatar(directory, row.sender_id.as_deref(), &row.author, size),
201 None => person_avatar(directory, row.sender_id.as_deref(), &row.author, size),
201 };
202 };
203 if let (Role::Reply, Some(call)) = (role, &row.call)
204 && let Some(notice) = &call.notice
205 {
206 let recap = std::mem::replace(&mut actions.call, CallActions::none()).recap;
207 return div()
208 .id(ElementId::Name(format!("post-message-{index}").into()))
209 .w_full()
210 .px(px(CARD_PADDING))
211 .pb(px(CARD_PADDING))
212 .bg(theme::reply_surface())
213 .child(notice_line(call, notice, index, directory, recap));
214 }
202 let profile_user = row.sender_id.as_deref().filter(|_| actions.bot.is_none());
215 let profile_user = row.sender_id.as_deref().filter(|_| actions.bot.is_none());
203 let content = match &row.call {
216 let content = match &row.call {
204 Some(call) => v_flex().child(post_call_card(
217 Some(call) => v_flex().child(post_call_card(
crates/app/src/views/prejoin_view.rs +1 −1
@@ -58,7 +58,7 @@ struct DeviceSelect {
58 58 enabled: bool,
59 59 }
60 60
61 fn demo_devices() -> DeviceLists {
61 pub(crate) fn demo_devices() -> DeviceLists {
62 62 let device = |index: u16, name: &str| AudioDevice {
63 63 index,
64 64 guid: format!("demo-{name}"),
@@ -58,7 +58,7 @@ struct DeviceSelect {
58 enabled: bool,
58 enabled: bool,
59}
59}
60
60
61fn demo_devices() -> DeviceLists {
61pub(crate) fn demo_devices() -> DeviceLists {
62 let device = |index: u16, name: &str| AudioDevice {
62 let device = |index: u16, name: &str| AudioDevice {
63 index,
63 index,
64 guid: format!("demo-{name}"),
64 guid: format!("demo-{name}"),
crates/app/src/views/shell.rs +46 −10
@@ -20,7 +20,7 @@ use super::rail::RailView;
20 20 use super::saved_panel::{SavedPanel, SavedPanelEvent};
21 21 use super::shortcuts::{
22 22 AcceptCall, DeclineCall, HangUpCall, JoinMeetingFromToast, NextConversation, OpenActivity,
23 OpenAgents, OpenCallsTab, OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk,
23 OpenAgents, OpenCallsTab, OpenSettings, OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk,
24 24 Scope, ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,
25 25 ToggleCallHand, ToggleCallShare, ZoomShareIn, ZoomShareOut, ZoomShareReset,
26 26 };
@@ -40,6 +40,8 @@ use crate::app_state::{AppEvent, AppState, Selection, selection_for};
40 40 use crate::call::{CallMedia, CallWindows, ZoomStep};
41 41 use crate::notice::NoticeAction;
42 42 use crate::notify::NotificationCenter;
43 use crate::settings::{SettingsDialog, SettingsDialogEvent};
44 use crate::settings_section::SettingsSection;
43 45 use crate::sidebar_model::Step;
44 46 use crate::theme;
45 47 use crate::updater::{self, IdleInputs, UpdateStatus};
@@ -118,6 +120,7 @@ pub struct AppShell {
118 120 status_dialog: Option<Entity<StatusMessageDialog>>,
119 121 shortcuts_dialog: Option<Entity<ShortcutsDialog>>,
120 122 agent_dialog: Option<Entity<StartDialog>>,
123 settings_dialog: Option<Entity<SettingsDialog>>,
121 124 profile_card: Option<Entity<ProfileCard>>,
122 125 focus_handle: FocusHandle,
123 126 call_window_fullscreen: bool,
@@ -202,9 +205,9 @@ impl AppShell {
202 205 cx.subscribe(
203 206 &activity_panel,
204 207 |this, _, event: &ActivityPanelEvent, cx| match event {
205 ActivityPanelEvent::OpenSettings => this
206 .notifications
207 .update(cx, |center, cx| center.open_settings(cx)),
208 ActivityPanelEvent::OpenSettings => this.state.update(cx, |state, cx| {
209 state.open_settings(SettingsSection::Notifications, cx)
210 }),
208 211 ActivityPanelEvent::Open {
209 212 conversation_id,
210 213 message_id,
@@ -227,9 +230,9 @@ impl AppShell {
227 230 AgentRunsEvent::StartRequested(request) => {
228 231 this.open_agent_dialog(request.clone(), window, cx)
229 232 }
230 AgentRunsEvent::OpenSettings => this
231 .notifications
232 .update(cx, |center, cx| center.open_agent_settings(cx)),
233 AgentRunsEvent::OpenSettings => {
234 this.open_settings(SettingsSection::Agents, window, cx)
235 }
233 236 AgentRunsEvent::Finished(_) => {}
234 237 },
235 238 )
@@ -253,9 +256,8 @@ impl AppShell {
253 256 if matches!(event, AppEvent::StatusMessage) {
254 257 this.open_status_dialog(window, cx);
255 258 }
256 if matches!(event, AppEvent::NotificationSettings) {
257 this.notifications
258 .update(cx, |center, cx| center.open_settings(cx));
259 if let AppEvent::Settings(section) = event {
260 this.open_settings(*section, window, cx);
259 261 }
260 262 if matches!(event, AppEvent::Profile) {
261 263 this.open_profile_card(window, cx);
@@ -301,6 +303,7 @@ impl AppShell {
301 303 status_dialog: None,
302 304 shortcuts_dialog: None,
303 305 agent_dialog: None,
306 settings_dialog: None,
304 307 profile_card: None,
305 308 focus_handle,
306 309 call_window_fullscreen: false,
@@ -560,6 +563,34 @@ impl AppShell {
560 563 cx.notify();
561 564 }
562 565
566 fn open_settings(
567 &mut self,
568 section: SettingsSection,
569 window: &mut Window,
570 cx: &mut Context<Self>,
571 ) {
572 if let Some(dialog) = &self.settings_dialog {
573 dialog.update(cx, |dialog, cx| dialog.show(section, window, cx));
574 return;
575 }
576 self.close_image_viewer(window, cx);
577 self.switcher = None;
578 let (app, center) = (self.state.clone(), self.notifications.clone());
579 let dialog = cx.new(|cx| SettingsDialog::new(app, center, section, window, cx));
580 cx.subscribe_in(
581 &dialog,
582 window,
583 |this, _, _: &SettingsDialogEvent, window, cx| {
584 this.settings_dialog = None;
585 this.restore_focus(window, cx);
586 cx.notify();
587 },
588 )
589 .detach();
590 self.settings_dialog = Some(dialog);
591 cx.notify();
592 }
593
563 594 fn toggle_shortcuts_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) {
564 595 if self.shortcuts_dialog.take().is_some() {
565 596 self.restore_focus(window, cx);
@@ -769,6 +800,7 @@ impl Render for AppShell {
769 800 self.status_dialog.is_some(),
770 801 self.shortcuts_dialog.is_some(),
771 802 self.agent_dialog.is_some(),
803 self.settings_dialog.is_some(),
772 804 ]
773 805 .into_iter()
774 806 .filter(|open| *open)
@@ -870,6 +902,9 @@ impl Render for AppShell {
870 902 .update(cx, |state, cx| state.release_push_to_talk(cx));
871 903 }
872 904 }))
905 .on_action(cx.listener(|this, _: &OpenSettings, window, cx| {
906 this.open_settings(SettingsSection::General, window, cx);
907 }))
873 908 .on_action(cx.listener(|this, _: &ShowShortcuts, window, cx| {
874 909 this.toggle_shortcuts_dialog(window, cx);
875 910 }))
@@ -993,6 +1028,7 @@ impl Render for AppShell {
993 1028 .children(self.status_dialog.clone())
994 1029 .children(self.shortcuts_dialog.clone())
995 1030 .children(self.agent_dialog.clone())
1031 .children(self.settings_dialog.clone())
996 1032 .children(self.profile_card.clone())
997 1033 .child(crate::frame_log::probe("last"))
998 1034 }
@@ -20,7 +20,7 @@ use super::rail::RailView;
20use super::saved_panel::{SavedPanel, SavedPanelEvent};
20use super::saved_panel::{SavedPanel, SavedPanelEvent};
21use super::shortcuts::{
21use super::shortcuts::{
22 AcceptCall, DeclineCall, HangUpCall, JoinMeetingFromToast, NextConversation, OpenActivity,
22 AcceptCall, DeclineCall, HangUpCall, JoinMeetingFromToast, NextConversation, OpenActivity,
23 OpenAgents, OpenCallsTab, OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk,
23 OpenAgents, OpenCallsTab, OpenSettings, OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk,
24 Scope, ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,
24 Scope, ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,
25 ToggleCallHand, ToggleCallShare, ZoomShareIn, ZoomShareOut, ZoomShareReset,
25 ToggleCallHand, ToggleCallShare, ZoomShareIn, ZoomShareOut, ZoomShareReset,
26};
26};
@@ -40,6 +40,8 @@ use crate::app_state::{AppEvent, AppState, Selection, selection_for};
40use crate::call::{CallMedia, CallWindows, ZoomStep};
40use crate::call::{CallMedia, CallWindows, ZoomStep};
41use crate::notice::NoticeAction;
41use crate::notice::NoticeAction;
42use crate::notify::NotificationCenter;
42use crate::notify::NotificationCenter;
43use crate::settings::{SettingsDialog, SettingsDialogEvent};
44use crate::settings_section::SettingsSection;
43use crate::sidebar_model::Step;
45use crate::sidebar_model::Step;
44use crate::theme;
46use crate::theme;
45use crate::updater::{self, IdleInputs, UpdateStatus};
47use crate::updater::{self, IdleInputs, UpdateStatus};
@@ -118,6 +120,7 @@ pub struct AppShell {
118 status_dialog: Option<Entity<StatusMessageDialog>>,
120 status_dialog: Option<Entity<StatusMessageDialog>>,
119 shortcuts_dialog: Option<Entity<ShortcutsDialog>>,
121 shortcuts_dialog: Option<Entity<ShortcutsDialog>>,
120 agent_dialog: Option<Entity<StartDialog>>,
122 agent_dialog: Option<Entity<StartDialog>>,
123 settings_dialog: Option<Entity<SettingsDialog>>,
121 profile_card: Option<Entity<ProfileCard>>,
124 profile_card: Option<Entity<ProfileCard>>,
122 focus_handle: FocusHandle,
125 focus_handle: FocusHandle,
123 call_window_fullscreen: bool,
126 call_window_fullscreen: bool,
@@ -202,9 +205,9 @@ impl AppShell {
202 cx.subscribe(
205 cx.subscribe(
203 &activity_panel,
206 &activity_panel,
204 |this, _, event: &ActivityPanelEvent, cx| match event {
207 |this, _, event: &ActivityPanelEvent, cx| match event {
205 ActivityPanelEvent::OpenSettings => this
208 ActivityPanelEvent::OpenSettings => this.state.update(cx, |state, cx| {
206 .notifications
209 state.open_settings(SettingsSection::Notifications, cx)
207 .update(cx, |center, cx| center.open_settings(cx)),
210 }),
208 ActivityPanelEvent::Open {
211 ActivityPanelEvent::Open {
209 conversation_id,
212 conversation_id,
210 message_id,
213 message_id,
@@ -227,9 +230,9 @@ impl AppShell {
227 AgentRunsEvent::StartRequested(request) => {
230 AgentRunsEvent::StartRequested(request) => {
228 this.open_agent_dialog(request.clone(), window, cx)
231 this.open_agent_dialog(request.clone(), window, cx)
229 }
232 }
230 AgentRunsEvent::OpenSettings => this
233 AgentRunsEvent::OpenSettings => {
231 .notifications
234 this.open_settings(SettingsSection::Agents, window, cx)
232 .update(cx, |center, cx| center.open_agent_settings(cx)),
235 }
233 AgentRunsEvent::Finished(_) => {}
236 AgentRunsEvent::Finished(_) => {}
234 },
237 },
235 )
238 )
@@ -253,9 +256,8 @@ impl AppShell {
253 if matches!(event, AppEvent::StatusMessage) {
256 if matches!(event, AppEvent::StatusMessage) {
254 this.open_status_dialog(window, cx);
257 this.open_status_dialog(window, cx);
255 }
258 }
256 if matches!(event, AppEvent::NotificationSettings) {
259 if let AppEvent::Settings(section) = event {
257 this.notifications
260 this.open_settings(*section, window, cx);
258 .update(cx, |center, cx| center.open_settings(cx));
259 }
261 }
260 if matches!(event, AppEvent::Profile) {
262 if matches!(event, AppEvent::Profile) {
261 this.open_profile_card(window, cx);
263 this.open_profile_card(window, cx);
@@ -301,6 +303,7 @@ impl AppShell {
301 status_dialog: None,
303 status_dialog: None,
302 shortcuts_dialog: None,
304 shortcuts_dialog: None,
303 agent_dialog: None,
305 agent_dialog: None,
306 settings_dialog: None,
304 profile_card: None,
307 profile_card: None,
305 focus_handle,
308 focus_handle,
306 call_window_fullscreen: false,
309 call_window_fullscreen: false,
@@ -560,6 +563,34 @@ impl AppShell {
560 cx.notify();
563 cx.notify();
561 }
564 }
562
565
566 fn open_settings(
567 &mut self,
568 section: SettingsSection,
569 window: &mut Window,
570 cx: &mut Context<Self>,
571 ) {
572 if let Some(dialog) = &self.settings_dialog {
573 dialog.update(cx, |dialog, cx| dialog.show(section, window, cx));
574 return;
575 }
576 self.close_image_viewer(window, cx);
577 self.switcher = None;
578 let (app, center) = (self.state.clone(), self.notifications.clone());
579 let dialog = cx.new(|cx| SettingsDialog::new(app, center, section, window, cx));
580 cx.subscribe_in(
581 &dialog,
582 window,
583 |this, _, _: &SettingsDialogEvent, window, cx| {
584 this.settings_dialog = None;
585 this.restore_focus(window, cx);
586 cx.notify();
587 },
588 )
589 .detach();
590 self.settings_dialog = Some(dialog);
591 cx.notify();
592 }
593
563 fn toggle_shortcuts_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) {
594 fn toggle_shortcuts_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) {
564 if self.shortcuts_dialog.take().is_some() {
595 if self.shortcuts_dialog.take().is_some() {
565 self.restore_focus(window, cx);
596 self.restore_focus(window, cx);
@@ -769,6 +800,7 @@ impl Render for AppShell {
769 self.status_dialog.is_some(),
800 self.status_dialog.is_some(),
770 self.shortcuts_dialog.is_some(),
801 self.shortcuts_dialog.is_some(),
771 self.agent_dialog.is_some(),
802 self.agent_dialog.is_some(),
803 self.settings_dialog.is_some(),
772 ]
804 ]
773 .into_iter()
805 .into_iter()
774 .filter(|open| *open)
806 .filter(|open| *open)
@@ -870,6 +902,9 @@ impl Render for AppShell {
870 .update(cx, |state, cx| state.release_push_to_talk(cx));
902 .update(cx, |state, cx| state.release_push_to_talk(cx));
871 }
903 }
872 }))
904 }))
905 .on_action(cx.listener(|this, _: &OpenSettings, window, cx| {
906 this.open_settings(SettingsSection::General, window, cx);
907 }))
873 .on_action(cx.listener(|this, _: &ShowShortcuts, window, cx| {
908 .on_action(cx.listener(|this, _: &ShowShortcuts, window, cx| {
874 this.toggle_shortcuts_dialog(window, cx);
909 this.toggle_shortcuts_dialog(window, cx);
875 }))
910 }))
@@ -993,6 +1028,7 @@ impl Render for AppShell {
993 .children(self.status_dialog.clone())
1028 .children(self.status_dialog.clone())
994 .children(self.shortcuts_dialog.clone())
1029 .children(self.shortcuts_dialog.clone())
995 .children(self.agent_dialog.clone())
1030 .children(self.agent_dialog.clone())
1031 .children(self.settings_dialog.clone())
996 .children(self.profile_card.clone())
1032 .children(self.profile_card.clone())
997 .child(crate::frame_log::probe("last"))
1033 .child(crate::frame_log::probe("last"))
998 }
1034 }
crates/app/src/views/shortcuts.rs +3 −1
@@ -37,7 +37,8 @@ actions!(
37 37 ZoomShareIn,
38 38 ZoomShareOut,
39 39 ZoomShareReset,
40 ShowShortcuts
40 ShowShortcuts,
41 OpenSettings
41 42 ]
42 43 );
43 44
@@ -103,6 +104,7 @@ pub const SHORTCUTS: &[Shortcut] = &[
103 104 shortcut!(General, OutsideComposer, "Search and switch chats", "ctrl-k", Some("cmd-k"), OpenSwitcher),
104 105 shortcut!(General, Global, "New chat", "ctrl-n", Some("cmd-n"), NewChat),
105 106 shortcut!(General, GlobalOverTextFields, "Keyboard shortcuts", "ctrl-.", Some("cmd-."), ShowShortcuts),
107 shortcut!(General, GlobalOverTextFields, "Settings", "ctrl-,", Some("cmd-,"), OpenSettings),
106 108 shortcut!(Navigation, GlobalOverTextFields, "Open Activity", "ctrl-1", Some("cmd-1"), OpenActivity),
107 109 shortcut!(Navigation, GlobalOverTextFields, "Show Chats", "ctrl-2", Some("cmd-2"), OpenChatsTab),
108 110 shortcut!(Navigation, GlobalOverTextFields, "Show Channels", "ctrl-3", Some("cmd-3"), OpenChannelsTab),
@@ -37,7 +37,8 @@ actions!(
37 ZoomShareIn,
37 ZoomShareIn,
38 ZoomShareOut,
38 ZoomShareOut,
39 ZoomShareReset,
39 ZoomShareReset,
40 ShowShortcuts
40 ShowShortcuts,
41 OpenSettings
41 ]
42 ]
42);
43);
43
44
@@ -103,6 +104,7 @@ pub const SHORTCUTS: &[Shortcut] = &[
103 shortcut!(General, OutsideComposer, "Search and switch chats", "ctrl-k", Some("cmd-k"), OpenSwitcher),
104 shortcut!(General, OutsideComposer, "Search and switch chats", "ctrl-k", Some("cmd-k"), OpenSwitcher),
104 shortcut!(General, Global, "New chat", "ctrl-n", Some("cmd-n"), NewChat),
105 shortcut!(General, Global, "New chat", "ctrl-n", Some("cmd-n"), NewChat),
105 shortcut!(General, GlobalOverTextFields, "Keyboard shortcuts", "ctrl-.", Some("cmd-."), ShowShortcuts),
106 shortcut!(General, GlobalOverTextFields, "Keyboard shortcuts", "ctrl-.", Some("cmd-."), ShowShortcuts),
107 shortcut!(General, GlobalOverTextFields, "Settings", "ctrl-,", Some("cmd-,"), OpenSettings),
106 shortcut!(Navigation, GlobalOverTextFields, "Open Activity", "ctrl-1", Some("cmd-1"), OpenActivity),
108 shortcut!(Navigation, GlobalOverTextFields, "Open Activity", "ctrl-1", Some("cmd-1"), OpenActivity),
107 shortcut!(Navigation, GlobalOverTextFields, "Show Chats", "ctrl-2", Some("cmd-2"), OpenChatsTab),
109 shortcut!(Navigation, GlobalOverTextFields, "Show Chats", "ctrl-2", Some("cmd-2"), OpenChatsTab),
108 shortcut!(Navigation, GlobalOverTextFields, "Show Channels", "ctrl-3", Some("cmd-3"), OpenChannelsTab),
110 shortcut!(Navigation, GlobalOverTextFields, "Show Channels", "ctrl-3", Some("cmd-3"), OpenChannelsTab),
crates/app/src/views/status_menu.rs +32 −175
@@ -7,17 +7,14 @@ use gpui_kit::component::{
7 7 menu::{DropdownMenu as _, PopupMenu, PopupMenuItem},
8 8 v_flex,
9 9 };
10 use gpui_kit::prelude::FluentBuilder as _;
11 10 use gpui_kit::*;
12 use teams_core::{
13 ChatSection, ForcedAvailability, ForcedKind, PresenceStatus, TranslationBehavior,
14 WorkLocationKind,
15 };
11 use teams_core::{ForcedAvailability, ForcedKind, PresenceStatus, WorkLocationKind};
16 12
17 13 use super::avatar::{person_avatar, with_presence};
18 14 use super::widgets::{icon, symbol};
19 15 use crate::app_state::AppState;
20 16 use crate::data::{Person, PresenceKind};
17 use crate::settings_section::SettingsSection;
21 18 use crate::own_status::{
22 19 STATUS_CHOICES, STATUS_DURATIONS, StateSummary, StatusDuration, choice_label, duration_target,
23 20 presence_kind_for, state_summary, work_location_label,
@@ -33,12 +30,6 @@ const OWN_STATUS_BUTTON_SIZE: f32 = TITLE_AVATAR_SIZE + 2. * (1. + RING_WIDTH +
33 30 const MENU_ICON_SIZE: f32 = 14.;
34 31 const ICON_COLUMN: f32 = 16.;
35 32 const HEADER_INSET: f32 = 24.;
36 const SWITCH_WIDTH: f32 = 28.;
37 const SWITCH_HEIGHT: f32 = 16.;
38 const SWITCH_THUMB: f32 = 12.;
39 const SWITCH_PADDING: f32 = 2.;
40 const TOGGLE_LABEL_WIDTH: f32 = 270.;
41 const LANGUAGE_LIST_HEIGHT: f32 = 320.;
42 33
43 34 #[derive(Clone)]
44 35 struct MenuContext {
@@ -192,6 +183,9 @@ fn status_menu(
192 183 let header_context = context.clone();
193 184 let message_app = context.app.clone();
194 185 let settings_app = context.app.clone();
186 let chat_list_app = context.app.clone();
187 let translation_app = context.app.clone();
188 let general_app = context.app.clone();
195 189 let call_app = context.app.clone();
196 190 let row_label = match &context.summary.until {
197 191 Some(until) => format!("{} {until}", context.summary.label),
@@ -222,8 +216,22 @@ fn status_menu(
222 216 }),
223 217 )
224 218 .separator()
225 .item(chat_list_item(context, window, cx))
226 .item(translation_item(context, window, cx))
219 .item(
220 PopupMenuItem::new("Chat list")
221 .icon(menu_icon(IconName::LayoutList))
222 .on_click(move |_, _, cx| {
223 chat_list_app
224 .update(cx, |state, cx| state.open_settings(SettingsSection::Chats, cx));
225 }),
226 )
227 .item(
228 PopupMenuItem::new("Translation")
229 .icon(menu_icon(IconName::Languages))
230 .on_click(move |_, _, cx| {
231 translation_app
232 .update(cx, |state, cx| state.open_settings(SettingsSection::General, cx));
233 }),
234 )
227 235 .item(
228 236 PopupMenuItem::new("Make a test call")
229 237 .icon(menu_icon(IconName::Phone))
@@ -233,9 +241,19 @@ fn status_menu(
233 241 )
234 242 .item(
235 243 PopupMenuItem::new("Notification settings")
244 .icon(menu_icon(IconName::Bell))
245 .on_click(move |_, _, cx| {
246 settings_app.update(cx, |state, cx| {
247 state.open_settings(SettingsSection::Notifications, cx)
248 });
249 }),
250 )
251 .item(
252 PopupMenuItem::new("Settings")
236 253 .icon(menu_icon(IconName::Settings))
237 254 .on_click(move |_, _, cx| {
238 settings_app.update(cx, |state, cx| state.open_notification_settings(cx));
255 general_app
256 .update(cx, |state, cx| state.open_settings(SettingsSection::General, cx));
239 257 }),
240 258 );
241 259 if !demo {
@@ -250,167 +268,6 @@ fn status_menu(
250 268 )
251 269 }
252 270
253 fn chat_list_item(
254 context: &MenuContext,
255 window: &mut Window,
256 cx: &mut Context<PopupMenu>,
257 ) -> PopupMenuItem {
258 let app = context.app.clone();
259 let submenu = PopupMenu::build(window, cx, move |menu, _, cx| {
260 let settings = app.read(cx).directory.section_settings;
261 menu.item(section_toggle(
262 &app,
263 ChatSection::Muted,
264 "Show muted chats in own section",
265 settings.enabled(ChatSection::Muted),
266 ))
267 });
268 PopupMenuItem::submenu("Chat list", submenu).icon(menu_icon(IconName::LayoutList))
269 }
270
271 fn translation_item(
272 context: &MenuContext,
273 window: &mut Window,
274 cx: &mut Context<PopupMenu>,
275 ) -> PopupMenuItem {
276 let app = context.app.clone();
277 let submenu = PopupMenu::build(window, cx, move |menu, window, cx| {
278 translation_menu(menu, window, cx, &app)
279 });
280 PopupMenuItem::submenu("Translation", submenu).icon(menu_icon(IconName::Languages))
281 }
282
283 fn translation_menu(
284 menu: PopupMenu,
285 window: &mut Window,
286 cx: &mut Context<PopupMenu>,
287 app: &Entity<AppState>,
288 ) -> PopupMenu {
289 let state = app.read(cx);
290 if state.translation.settings.is_none() {
291 return menu.item(PopupMenuItem::label("Translation settings not loaded yet"));
292 }
293 let target = state.translation.target();
294 let behavior = state.translation.behavior();
295 let languages = state.translation.languages.clone();
296 let never: Vec<(String, String)> = state
297 .translation
298 .display_codes()
299 .into_iter()
300 .filter(|code| *code != target)
301 .map(|code| {
302 let name = state.translation.language_name(&code);
303 (code, name)
304 })
305 .collect();
306 let target_label = format!("Translate to {}", state.translation.language_name(&target));
307 let target_app = app.clone();
308 let mut menu = menu
309 .check_side(Side::Right)
310 .min_w(px(MENU_WIDTH))
311 .submenu_with_icon(None, target_label, window, cx, move |submenu, _, _| {
312 languages.iter().fold(
313 submenu
314 .check_side(Side::Right)
315 .max_h(px(LANGUAGE_LIST_HEIGHT))
316 .scrollable(true),
317 |submenu, language| {
318 let (app, code) = (target_app.clone(), language.code.clone());
319 submenu.item(
320 PopupMenuItem::new(language.name.clone())
321 .checked(language.code == target)
322 .on_click(move |_, _, cx| {
323 app.update(cx, |state, cx| state.set_translation_target(&code, cx));
324 }),
325 )
326 },
327 )
328 });
329 menu = menu.separator();
330 for (label, choice) in [
331 ("Ask me before translating", TranslationBehavior::Ask),
332 ("Auto-translate all messages", TranslationBehavior::Auto),
333 ("Never translate", TranslationBehavior::Never),
334 ] {
335 let app = app.clone();
336 menu = menu.item(
337 PopupMenuItem::new(label)
338 .checked(behavior == choice)
339 .on_click(move |_, _, cx| {
340 app.update(cx, |state, cx| state.set_translation_behavior(choice, cx));
341 }),
342 );
343 }
344 menu = menu
345 .separator()
346 .item(PopupMenuItem::label("Never translate messages in"));
347 if never.is_empty() {
348 return menu.item(PopupMenuItem::label("No languages"));
349 }
350 for (code, name) in never {
351 let app = app.clone();
352 menu = menu.item(
353 PopupMenuItem::element(move |_, _| {
354 h_flex()
355 .w(px(TOGGLE_LABEL_WIDTH))
356 .gap(px(12.))
357 .items_center()
358 .justify_between()
359 .child(div().flex_1().min_w_0().truncate().child(name.clone()))
360 .child(menu_icon(IconName::X))
361 })
362 .on_click(move |_, _, cx| {
363 app.update(cx, |state, cx| state.allow_translating_language(&code, cx));
364 }),
365 );
366 }
367 menu
368 }
369
370 fn section_toggle(
371 app: &Entity<AppState>,
372 section: ChatSection,
373 label: &'static str,
374 enabled: bool,
375 ) -> PopupMenuItem {
376 let app = app.clone();
377 PopupMenuItem::element(move |_, _| {
378 h_flex()
379 .w(px(TOGGLE_LABEL_WIDTH))
380 .gap(px(12.))
381 .items_center()
382 .justify_between()
383 .child(div().flex_1().min_w_0().truncate().child(label))
384 .child(switch(enabled))
385 })
386 .on_click(move |_, _, cx| {
387 app.update(cx, |state, cx| {
388 state.set_chat_section(section, !enabled, cx)
389 });
390 })
391 }
392
393 fn switch(enabled: bool) -> Div {
394 let thumb = div()
395 .size(px(SWITCH_THUMB))
396 .rounded_full()
397 .bg(theme::text_strong());
398 h_flex()
399 .w(px(SWITCH_WIDTH))
400 .h(px(SWITCH_HEIGHT))
401 .flex_none()
402 .p(px(SWITCH_PADDING))
403 .items_center()
404 .rounded_full()
405 .bg(if enabled {
406 theme::accent()
407 } else {
408 theme::badge_muted()
409 })
410 .when(enabled, |track| track.justify_end())
411 .child(thumb)
412 }
413
414 271 fn work_location_icon(kind: Option<WorkLocationKind>) -> gpui_kit::component::Icon {
415 272 menu_icon(match kind {
416 273 Some(WorkLocationKind::Office) => IconName::Building2,
@@ -7,17 +7,14 @@ use gpui_kit::component::{
7 menu::{DropdownMenu as _, PopupMenu, PopupMenuItem},
7 menu::{DropdownMenu as _, PopupMenu, PopupMenuItem},
8 v_flex,
8 v_flex,
9};
9};
10use gpui_kit::prelude::FluentBuilder as _;
11use gpui_kit::*;
10use gpui_kit::*;
12use teams_core::{
11use teams_core::{ForcedAvailability, ForcedKind, PresenceStatus, WorkLocationKind};
13 ChatSection, ForcedAvailability, ForcedKind, PresenceStatus, TranslationBehavior,
14 WorkLocationKind,
15};
16
12
17use super::avatar::{person_avatar, with_presence};
13use super::avatar::{person_avatar, with_presence};
18use super::widgets::{icon, symbol};
14use super::widgets::{icon, symbol};
19use crate::app_state::AppState;
15use crate::app_state::AppState;
20use crate::data::{Person, PresenceKind};
16use crate::data::{Person, PresenceKind};
17use crate::settings_section::SettingsSection;
21use crate::own_status::{
18use crate::own_status::{
22 STATUS_CHOICES, STATUS_DURATIONS, StateSummary, StatusDuration, choice_label, duration_target,
19 STATUS_CHOICES, STATUS_DURATIONS, StateSummary, StatusDuration, choice_label, duration_target,
23 presence_kind_for, state_summary, work_location_label,
20 presence_kind_for, state_summary, work_location_label,
@@ -33,12 +30,6 @@ const OWN_STATUS_BUTTON_SIZE: f32 = TITLE_AVATAR_SIZE + 2. * (1. + RING_WIDTH +
33const MENU_ICON_SIZE: f32 = 14.;
30const MENU_ICON_SIZE: f32 = 14.;
34const ICON_COLUMN: f32 = 16.;
31const ICON_COLUMN: f32 = 16.;
35const HEADER_INSET: f32 = 24.;
32const HEADER_INSET: f32 = 24.;
36const SWITCH_WIDTH: f32 = 28.;
37const SWITCH_HEIGHT: f32 = 16.;
38const SWITCH_THUMB: f32 = 12.;
39const SWITCH_PADDING: f32 = 2.;
40const TOGGLE_LABEL_WIDTH: f32 = 270.;
41const LANGUAGE_LIST_HEIGHT: f32 = 320.;
42
33
43#[derive(Clone)]
34#[derive(Clone)]
44struct MenuContext {
35struct MenuContext {
@@ -192,6 +183,9 @@ fn status_menu(
192 let header_context = context.clone();
183 let header_context = context.clone();
193 let message_app = context.app.clone();
184 let message_app = context.app.clone();
194 let settings_app = context.app.clone();
185 let settings_app = context.app.clone();
186 let chat_list_app = context.app.clone();
187 let translation_app = context.app.clone();
188 let general_app = context.app.clone();
195 let call_app = context.app.clone();
189 let call_app = context.app.clone();
196 let row_label = match &context.summary.until {
190 let row_label = match &context.summary.until {
197 Some(until) => format!("{} {until}", context.summary.label),
191 Some(until) => format!("{} {until}", context.summary.label),
@@ -222,8 +216,22 @@ fn status_menu(
222 }),
216 }),
223 )
217 )
224 .separator()
218 .separator()
225 .item(chat_list_item(context, window, cx))
219 .item(
226 .item(translation_item(context, window, cx))
220 PopupMenuItem::new("Chat list")
221 .icon(menu_icon(IconName::LayoutList))
222 .on_click(move |_, _, cx| {
223 chat_list_app
224 .update(cx, |state, cx| state.open_settings(SettingsSection::Chats, cx));
225 }),
226 )
227 .item(
228 PopupMenuItem::new("Translation")
229 .icon(menu_icon(IconName::Languages))
230 .on_click(move |_, _, cx| {
231 translation_app
232 .update(cx, |state, cx| state.open_settings(SettingsSection::General, cx));
233 }),
234 )
227 .item(
235 .item(
228 PopupMenuItem::new("Make a test call")
236 PopupMenuItem::new("Make a test call")
229 .icon(menu_icon(IconName::Phone))
237 .icon(menu_icon(IconName::Phone))
@@ -233,9 +241,19 @@ fn status_menu(
233 )
241 )
234 .item(
242 .item(
235 PopupMenuItem::new("Notification settings")
243 PopupMenuItem::new("Notification settings")
244 .icon(menu_icon(IconName::Bell))
245 .on_click(move |_, _, cx| {
246 settings_app.update(cx, |state, cx| {
247 state.open_settings(SettingsSection::Notifications, cx)
248 });
249 }),
250 )
251 .item(
252 PopupMenuItem::new("Settings")
236 .icon(menu_icon(IconName::Settings))
253 .icon(menu_icon(IconName::Settings))
237 .on_click(move |_, _, cx| {
254 .on_click(move |_, _, cx| {
238 settings_app.update(cx, |state, cx| state.open_notification_settings(cx));
255 general_app
256 .update(cx, |state, cx| state.open_settings(SettingsSection::General, cx));
239 }),
257 }),
240 );
258 );
241 if !demo {
259 if !demo {
@@ -250,167 +268,6 @@ fn status_menu(
250 )
268 )
251}
269}
252
270
253fn chat_list_item(
254 context: &MenuContext,
255 window: &mut Window,
256 cx: &mut Context<PopupMenu>,
257) -> PopupMenuItem {
258 let app = context.app.clone();
259 let submenu = PopupMenu::build(window, cx, move |menu, _, cx| {
260 let settings = app.read(cx).directory.section_settings;
261 menu.item(section_toggle(
262 &app,
263 ChatSection::Muted,
264 "Show muted chats in own section",
265 settings.enabled(ChatSection::Muted),
266 ))
267 });
268 PopupMenuItem::submenu("Chat list", submenu).icon(menu_icon(IconName::LayoutList))
269}
270
271fn translation_item(
272 context: &MenuContext,
273 window: &mut Window,
274 cx: &mut Context<PopupMenu>,
275) -> PopupMenuItem {
276 let app = context.app.clone();
277 let submenu = PopupMenu::build(window, cx, move |menu, window, cx| {
278 translation_menu(menu, window, cx, &app)
279 });
280 PopupMenuItem::submenu("Translation", submenu).icon(menu_icon(IconName::Languages))
281}
282
283fn translation_menu(
284 menu: PopupMenu,
285 window: &mut Window,
286 cx: &mut Context<PopupMenu>,
287 app: &Entity<AppState>,
288) -> PopupMenu {
289 let state = app.read(cx);
290 if state.translation.settings.is_none() {
291 return menu.item(PopupMenuItem::label("Translation settings not loaded yet"));
292 }
293 let target = state.translation.target();
294 let behavior = state.translation.behavior();
295 let languages = state.translation.languages.clone();
296 let never: Vec<(String, String)> = state
297 .translation
298 .display_codes()
299 .into_iter()
300 .filter(|code| *code != target)
301 .map(|code| {
302 let name = state.translation.language_name(&code);
303 (code, name)
304 })
305 .collect();
306 let target_label = format!("Translate to {}", state.translation.language_name(&target));
307 let target_app = app.clone();
308 let mut menu = menu
309 .check_side(Side::Right)
310 .min_w(px(MENU_WIDTH))
311 .submenu_with_icon(None, target_label, window, cx, move |submenu, _, _| {
312 languages.iter().fold(
313 submenu
314 .check_side(Side::Right)
315 .max_h(px(LANGUAGE_LIST_HEIGHT))
316 .scrollable(true),
317 |submenu, language| {
318 let (app, code) = (target_app.clone(), language.code.clone());
319 submenu.item(
320 PopupMenuItem::new(language.name.clone())
321 .checked(language.code == target)
322 .on_click(move |_, _, cx| {
323 app.update(cx, |state, cx| state.set_translation_target(&code, cx));
324 }),
325 )
326 },
327 )
328 });
329 menu = menu.separator();
330 for (label, choice) in [
331 ("Ask me before translating", TranslationBehavior::Ask),
332 ("Auto-translate all messages", TranslationBehavior::Auto),
333 ("Never translate", TranslationBehavior::Never),
334 ] {
335 let app = app.clone();
336 menu = menu.item(
337 PopupMenuItem::new(label)
338 .checked(behavior == choice)
339 .on_click(move |_, _, cx| {
340 app.update(cx, |state, cx| state.set_translation_behavior(choice, cx));
341 }),
342 );
343 }
344 menu = menu
345 .separator()
346 .item(PopupMenuItem::label("Never translate messages in"));
347 if never.is_empty() {
348 return menu.item(PopupMenuItem::label("No languages"));
349 }
350 for (code, name) in never {
351 let app = app.clone();
352 menu = menu.item(
353 PopupMenuItem::element(move |_, _| {
354 h_flex()
355 .w(px(TOGGLE_LABEL_WIDTH))
356 .gap(px(12.))
357 .items_center()
358 .justify_between()
359 .child(div().flex_1().min_w_0().truncate().child(name.clone()))
360 .child(menu_icon(IconName::X))
361 })
362 .on_click(move |_, _, cx| {
363 app.update(cx, |state, cx| state.allow_translating_language(&code, cx));
364 }),
365 );
366 }
367 menu
368}
369
370fn section_toggle(
371 app: &Entity<AppState>,
372 section: ChatSection,
373 label: &'static str,
374 enabled: bool,
375) -> PopupMenuItem {
376 let app = app.clone();
377 PopupMenuItem::element(move |_, _| {
378 h_flex()
379 .w(px(TOGGLE_LABEL_WIDTH))
380 .gap(px(12.))
381 .items_center()
382 .justify_between()
383 .child(div().flex_1().min_w_0().truncate().child(label))
384 .child(switch(enabled))
385 })
386 .on_click(move |_, _, cx| {
387 app.update(cx, |state, cx| {
388 state.set_chat_section(section, !enabled, cx)
389 });
390 })
391}
392
393fn switch(enabled: bool) -> Div {
394 let thumb = div()
395 .size(px(SWITCH_THUMB))
396 .rounded_full()
397 .bg(theme::text_strong());
398 h_flex()
399 .w(px(SWITCH_WIDTH))
400 .h(px(SWITCH_HEIGHT))
401 .flex_none()
402 .p(px(SWITCH_PADDING))
403 .items_center()
404 .rounded_full()
405 .bg(if enabled {
406 theme::accent()
407 } else {
408 theme::badge_muted()
409 })
410 .when(enabled, |track| track.justify_end())
411 .child(thumb)
412}
413
414fn work_location_icon(kind: Option<WorkLocationKind>) -> gpui_kit::component::Icon {
271fn work_location_icon(kind: Option<WorkLocationKind>) -> gpui_kit::component::Icon {
415 menu_icon(match kind {
272 menu_icon(match kind {
416 Some(WorkLocationKind::Office) => IconName::Building2,
273 Some(WorkLocationKind::Office) => IconName::Building2,