BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / views / shell.rs

shell.rs

shell.rs 36.1 KiB Download Raw
1use std::sync::Arc;
2
3use gpui_kit::component::{h_flex, v_flex};
4use gpui_kit::*;
5
6use super::activity_panel::{ActivityPanel, ActivityPanelEvent};
7use super::call_mini::CallMiniView;
8use super::call_stage::{render_call_overlay, render_stage_overlay};
9use super::call_view::{CHAT_PANEL_WIDTH, OVERLAY_BELOW as CALL_COLUMN_MIN, render_call_view};
10use super::conversation::{ConversationView, ReplyToHovered};
11use super::dialog_overlay::render_task_dialog;
12use super::forward_dialog::{ForwardDialog, ForwardDialogEvent};
13use super::image_viewer::{ImageViewer, ImageViewerEvent};
14use super::prejoin_view::PrejoinView;
15use super::profile_card::{ProfileCard, ProfileCardEvent};
16use gpui_kit::prelude::FluentBuilder as _;
17use super::rail::{RAIL_WIDTH, RailView};
18use super::saved_panel::{SavedPanel, SavedPanelEvent};
19use super::shortcuts::{
20 AcceptCall, DeclineCall, HangUpCall, JoinMeetingFromToast, NextConversation, OpenActivity,
21 OpenCallsTab, OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk,
22 Scope, ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,
23 ToggleCallHand, ToggleCallShare, ZoomShareIn, ZoomShareOut, ZoomShareReset,
24};
25use super::call_pop_out::zoom_listener;
26use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
27use super::sidebar::{SIDEBAR_WIDTH, SidebarView};
28use super::status_bar::render_status_bar;
29use super::status_menu::own_status_button;
30use super::status_message_dialog::{StatusMessageDialog, StatusMessageDialogEvent};
31use super::switcher::{Switcher, SwitcherEvent, candidates_from};
32use super::title_bar::render_title_bar;
33use crate::activity::ActivityCenter;
34use crate::agents::{AgentRunsEvent, StartDialog, StartDialogEvent, StartRequest};
35use crate::app_state::{AppEvent, AppState, Selection};
36use crate::call::{CallMedia, CallWindows, ZoomStep};
37use crate::notice::NoticeAction;
38use crate::notify::{NotificationCenter, selection_for};
39use crate::sidebar_model::Step;
40use crate::theme;
41use crate::updater::{self, IdleInputs, UpdateStatus};
42use crate::user_activity::{self, UserInput};
43
44actions!(teams, [OpenSwitcher, NewChat, ToggleCallMute]);
45
46pub fn bind_keys(cx: &mut App) {
47 super::composer::bind_keys(cx);
48 super::shortcuts::bind_scopes(
49 cx,
50 &[
51 Scope::Global,
52 Scope::OutsideComposer,
53 Scope::GlobalOverTextFields,
54 Scope::OutsideTextFields,
55 ],
56 );
57}
58
59#[derive(Debug, Clone, Copy)]
60pub enum OpenTarget {
61 Chat(usize),
62 Channel(usize),
63}
64
65#[derive(Default)]
66pub struct Startup {
67 pub switcher_query: Option<String>,
68 pub composer_text: Option<String>,
69 pub reply_to_last: bool,
70}
71
72pub const ISLAND_GAP: f32 = 6.;
73pub const SIDEBAR_HIDDEN_BELOW: f32 = 960.;
74
75pub fn sidebar_hidden_in_call(window_width: f32, panel_open: bool) -> bool {
76 let panel_width = if panel_open { CHAT_PANEL_WIDTH + ISLAND_GAP } else { 0. };
77 window_width < SIDEBAR_HIDDEN_BELOW
78 || window_width - RAIL_WIDTH - SIDEBAR_WIDTH - 2. * ISLAND_GAP - panel_width < CALL_COLUMN_MIN
79}
80
81pub struct UserInputHandle(pub Arc<UserInput>);
82
83impl Global for UserInputHandle {}
84
85pub fn install_globals(state: &Entity<AppState>, user_input: Arc<UserInput>, cx: &mut App) {
86 cx.set_global(crate::app_state::AppHandle(state.clone()));
87 cx.set_global(UserInputHandle(user_input));
88}
89
90pub struct AppShell {
91 state: Entity<AppState>,
92 rail: Entity<RailView>,
93 sidebar: Entity<SidebarView>,
94 conversation: Entity<ConversationView>,
95 call_chat: Option<(String, Entity<ConversationView>)>,
96 prejoin: Option<Entity<PrejoinView>>,
97 switcher: Option<Entity<Switcher>>,
98 notifications: Entity<NotificationCenter>,
99 _call_windows: Entity<CallWindows>,
100 forward_dialog: Option<Entity<ForwardDialog>>,
101 image_viewer: Option<Entity<ImageViewer>>,
102 status_dialog: Option<Entity<StatusMessageDialog>>,
103 shortcuts_dialog: Option<Entity<ShortcutsDialog>>,
104 agent_dialog: Option<Entity<StartDialog>>,
105 profile_card: Option<Entity<ProfileCard>>,
106 focus_handle: FocusHandle,
107 call_window_fullscreen: bool,
108 window_was_fullscreen: bool,
109 open_target: Option<OpenTarget>,
110 update: UpdateStatus,
111 user_input: Arc<UserInput>,
112 _subscription: Subscription,
113 call_mini: Entity<CallMiniView>,
114 _call_media_observation: Subscription,
115 _panel_subscriptions: [Subscription; 2],
116 _agent_subscription: Option<Subscription>,
117 _escape_observation: Subscription,
118 _activation_observation: Subscription,
119}
120
121impl AppShell {
122 fn sync_call_chat(
123 &mut self,
124 thread: Option<String>,
125 window: &mut Window,
126 cx: &mut Context<Self>,
127 ) {
128 match (thread, &self.call_chat) {
129 (Some(wanted), Some((open, _))) if &wanted == open => {}
130 (Some(wanted), _) => {
131 let app = self.state.clone();
132 let selection = Selection::Chat(wanted.clone());
133 let view = cx.new(|cx| ConversationView::pinned_to(app, selection, window, cx));
134 self.call_chat = Some((wanted, view));
135 }
136 (None, _) => self.call_chat = None,
137 }
138 }
139
140 fn sync_prejoin(&mut self, window: &mut Window, cx: &mut Context<Self>) {
141 let wanted = self.state.read(cx).prejoin.clone();
142 let open = self.prejoin.as_ref().map(|view| view.read(cx).pending_id());
143 match (wanted, open) {
144 (Some(pending), Some(id)) if pending.id == id => {}
145 (Some(pending), _) => {
146 let app = self.state.clone();
147 self.prejoin = Some(cx.new(|cx| PrejoinView::new(app, &pending, window, cx)));
148 }
149 (None, _) => self.prejoin = None,
150 }
151 }
152
153 pub fn new(
154 state: Entity<AppState>,
155 open_target: Option<OpenTarget>,
156 startup: Startup,
157 window: &mut Window,
158 cx: &mut Context<Self>,
159 ) -> Self {
160 let call_media = cx.new(|_| CallMedia);
161 state.update(cx, |state, _| state.call_media = Some(call_media.clone()));
162 let call_media_observation = cx.observe(&call_media, |this, _, cx| {
163 if this.state.read(cx).viewing_call() {
164 cx.notify();
165 }
166 });
167 let activity = cx.new(|cx| ActivityCenter::new(state.clone(), window, cx));
168 let activity_panel = cx.new(|cx| ActivityPanel::new(state.clone(), activity.clone(), cx));
169 let saved_panel = cx.new(|cx| SavedPanel::new(state.clone(), cx));
170 let panel_subscriptions = [
171 cx.subscribe(
172 &activity_panel,
173 |this, _, event: &ActivityPanelEvent, cx| match event {
174 ActivityPanelEvent::OpenSettings => this
175 .notifications
176 .update(cx, |center, cx| center.open_settings(cx)),
177 ActivityPanelEvent::Open {
178 conversation_id,
179 message_id,
180 } => this.open_message(conversation_id, message_id, cx),
181 },
182 ),
183 cx.subscribe(&saved_panel, |this, _, event: &SavedPanelEvent, cx| {
184 let SavedPanelEvent::Open {
185 conversation_id,
186 message_id,
187 } = event;
188 this.open_message(conversation_id, message_id, cx);
189 }),
190 ];
191 let agent_subscription = crate::agents::runs_handle(cx).map(|runs| {
192 cx.subscribe_in(
193 &runs,
194 window,
195 |this, _, event: &AgentRunsEvent, window, cx| match event {
196 AgentRunsEvent::StartRequested(request) => {
197 this.open_agent_dialog(request.clone(), window, cx)
198 }
199 AgentRunsEvent::OpenSettings => this
200 .notifications
201 .update(cx, |center, cx| center.open_agent_settings(cx)),
202 AgentRunsEvent::Finished(_) => {}
203 },
204 )
205 });
206 let sidebar = cx.new(|cx| SidebarView::new(state.clone(), activity_panel, saved_panel, cx));
207 let rail = cx.new(|cx| RailView::new(state.clone(), activity.clone(), sidebar.clone(), cx));
208 let conversation = cx.new(|cx| ConversationView::new(state.clone(), window, cx));
209 let timeline = conversation.read(cx).timeline_bounds();
210 let call_mini = cx.new(|cx| CallMiniView::new(state.clone(), timeline, cx));
211 let subscription =
212 cx.subscribe_in(&state, window, |this, _, event: &AppEvent, window, cx| {
213 if matches!(event, AppEvent::Sidebar | AppEvent::Status) {
214 this.apply_open_target(cx);
215 }
216 if matches!(event, AppEvent::Forward) {
217 this.open_forward_dialog(window, cx);
218 }
219 if matches!(event, AppEvent::ImageViewer) {
220 this.open_image_viewer(window, cx);
221 }
222 if matches!(event, AppEvent::StatusMessage) {
223 this.open_status_dialog(window, cx);
224 }
225 if matches!(event, AppEvent::NotificationSettings) {
226 this.notifications
227 .update(cx, |center, cx| center.open_settings(cx));
228 }
229 if matches!(event, AppEvent::Profile) {
230 this.open_profile_card(window, cx);
231 }
232 cx.notify();
233 });
234 let focus_handle = cx.focus_handle();
235 window.focus(&focus_handle, cx);
236 let notifications = cx.new(|cx| NotificationCenter::new(state.clone(), window, cx));
237 let call_windows = cx.new(|cx| CallWindows::new(state.clone(), window, cx));
238 let user_input = cx.global::<UserInputHandle>().0.clone();
239 let escape_observation = cx.observe_keystrokes(|this, event, _, cx| {
240 this.user_input.touch();
241 if event.keystroke.key == "escape" && event.action.is_none() {
242 this.state
243 .update(cx, |state, cx| state.escape_call_fullscreen(cx));
244 }
245 });
246 let activation_observation = cx.observe_window_activation(window, |this, window, cx| {
247 if window.is_window_active() {
248 this.state
249 .update(cx, |state, cx| state.refresh_calendar(cx));
250 } else {
251 this.state
252 .update(cx, |state, cx| state.release_push_to_talk(cx));
253 }
254 });
255 let closing = notifications.clone();
256 window.on_window_should_close(cx, move |_, cx| !closing.read(cx).intercept_close(cx));
257 let mut shell = AppShell {
258 state,
259 rail,
260 sidebar,
261 conversation,
262 call_chat: None,
263 prejoin: None,
264 switcher: None,
265 notifications,
266 _call_windows: call_windows,
267 forward_dialog: None,
268 image_viewer: None,
269 status_dialog: None,
270 shortcuts_dialog: None,
271 agent_dialog: None,
272 profile_card: None,
273 focus_handle,
274 call_window_fullscreen: false,
275 window_was_fullscreen: false,
276 open_target,
277 update: UpdateStatus::UpToDate,
278 user_input,
279 _subscription: subscription,
280 call_mini,
281 _call_media_observation: call_media_observation,
282 _panel_subscriptions: panel_subscriptions,
283 _agent_subscription: agent_subscription,
284 _escape_observation: escape_observation,
285 _activation_observation: activation_observation,
286 };
287 shell.apply_open_target(cx);
288 let Startup {
289 switcher_query,
290 composer_text,
291 reply_to_last,
292 } = startup;
293 if let Some(query) = switcher_query {
294 shell.toggle_switcher(&query, window, cx);
295 }
296 if composer_text.is_some() || reply_to_last {
297 cx.defer_in(window, move |this, window, cx| {
298 this.conversation.update(cx, |conversation, cx| {
299 if reply_to_last {
300 conversation.reply_to_latest_from_others(window, cx);
301 }
302 if let Some(text) = composer_text {
303 conversation.set_composer_text(&text, window, cx);
304 }
305 });
306 });
307 }
308 #[cfg(windows)]
309 cx.spawn_in(window, async move |this, cx| {
310 loop {
311 cx.background_executor().timer(updater::POLL_INTERVAL).await;
312 if this
313 .update_in(cx, |this, window, cx| this.poll_update(window, cx))
314 .is_err()
315 {
316 break;
317 }
318 }
319 })
320 .detach();
321 shell
322 }
323
324 #[cfg_attr(not(windows), allow(dead_code))]
325 fn poll_update(&mut self, window: &mut Window, cx: &mut Context<Self>) {
326 if matches!(
327 self.update,
328 UpdateStatus::Failed(_) | UpdateStatus::Installing
329 ) {
330 return;
331 }
332 let Some(paths) = updater::current_paths() else {
333 return;
334 };
335 if self.update == UpdateStatus::UpToDate {
336 if !updater::check(&paths) {
337 return;
338 }
339 self.update = UpdateStatus::Ready;
340 let update_exe = paths.update_exe.clone();
341 cx.background_spawn(async move { updater::prescan(&update_exe) })
342 .detach();
343 }
344 let conversation = self.conversation.read(cx);
345 let idle = updater::is_idle(IdleInputs {
346 window_active: window.is_window_active(),
347 composer_empty: conversation.composer_is_empty(cx),
348 send_in_flight: conversation.send_in_flight(),
349 });
350 if idle {
351 self.restart_into_update(cx);
352 }
353 cx.notify();
354 }
355
356 fn restart_into_update(&mut self, cx: &mut Context<Self>) {
357 if self.update == UpdateStatus::Installing {
358 return;
359 }
360 let Some(paths) = updater::current_paths() else {
361 return;
362 };
363 self.update = UpdateStatus::Installing;
364 cx.notify();
365 cx.spawn(async move |this, cx| {
366 let result = cx
367 .background_spawn(async move { updater::install_and_relaunch(&paths) })
368 .await;
369 let _ = this.update(cx, |this, cx| {
370 match result {
371 Ok(()) => cx.quit(),
372 Err(message) => this.update = UpdateStatus::Failed(message),
373 }
374 cx.notify();
375 });
376 })
377 .detach();
378 }
379
380 fn apply_open_target(&mut self, cx: &mut Context<Self>) {
381 let Some(target) = self.open_target else {
382 return;
383 };
384 let sidebar = &self.state.read(cx).sidebar;
385 let selection = match target {
386 OpenTarget::Chat(index) => sidebar
387 .chats
388 .get(index)
389 .map(|chat| Selection::Chat(chat.id.clone())),
390 OpenTarget::Channel(index) => sidebar
391 .teams
392 .iter()
393 .flat_map(|team| team.channels.iter())
394 .nth(index)
395 .map(|channel| Selection::Channel(channel.id.clone())),
396 };
397 if let Some(selection) = selection {
398 self.open_target = None;
399 self.state
400 .update(cx, |state, cx| state.select(selection, cx));
401 }
402 }
403
404 fn toggle_switcher(
405 &mut self,
406 initial_query: &str,
407 window: &mut Window,
408 cx: &mut Context<Self>,
409 ) {
410 if self.switcher.take().is_some() {
411 self.restore_focus(window, cx);
412 cx.notify();
413 return;
414 }
415 self.close_image_viewer(window, cx);
416 let candidates = candidates_from(self.state.read(cx));
417 let app = self.state.clone();
418 let switcher = cx.new(|cx| Switcher::new(app, candidates, initial_query, window, cx));
419 cx.subscribe_in(
420 &switcher,
421 window,
422 |this, _, event: &SwitcherEvent, window, cx| {
423 match event {
424 SwitcherEvent::Pick(selection) => {
425 let selection = selection.clone();
426 this.state
427 .update(cx, |state, cx| state.select(selection, cx));
428 }
429 SwitcherEvent::PickMessage {
430 selection,
431 message_id,
432 } => {
433 let (selection, message_id) = (selection.clone(), message_id.clone());
434 this.state.update(cx, |state, cx| {
435 state.jump_to_message(selection, message_id, cx)
436 });
437 }
438 SwitcherEvent::Close => {}
439 }
440 this.switcher = None;
441 this.restore_focus(window, cx);
442 cx.notify();
443 },
444 )
445 .detach();
446 self.switcher = Some(switcher);
447 cx.notify();
448 }
449
450 fn open_message(&mut self, conversation_id: &str, message_id: &str, cx: &mut Context<Self>) {
451 let Some(selection) = selection_for(&self.state.read(cx).sidebar, conversation_id) else {
452 return;
453 };
454 let message_id = message_id.to_owned();
455 self.state.update(cx, |state, cx| {
456 if message_id.is_empty() {
457 state.select(selection, cx)
458 } else {
459 state.jump_to_message(selection, message_id, cx)
460 }
461 });
462 }
463
464 fn open_status_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) {
465 if !self
466 .state
467 .update(cx, |state, _| state.take_status_message_request())
468 {
469 return;
470 }
471 self.close_image_viewer(window, cx);
472 self.switcher = None;
473 let app = self.state.clone();
474 let dialog = cx.new(|cx| StatusMessageDialog::new(app, window, cx));
475 cx.subscribe_in(
476 &dialog,
477 window,
478 |this, _, _: &StatusMessageDialogEvent, window, cx| {
479 this.status_dialog = None;
480 this.restore_focus(window, cx);
481 cx.notify();
482 },
483 )
484 .detach();
485 self.status_dialog = Some(dialog);
486 cx.notify();
487 }
488
489 fn open_agent_dialog(
490 &mut self,
491 request: StartRequest,
492 window: &mut Window,
493 cx: &mut Context<Self>,
494 ) {
495 let Some(runs) = crate::agents::runs_handle(cx) else {
496 return;
497 };
498 let settings = runs.read(cx).settings();
499 let Some(action) = settings
500 .actions
501 .iter()
502 .find(|action| action.id == request.action_id)
503 .cloned()
504 else {
505 return;
506 };
507 let agent_name = settings
508 .agents
509 .iter()
510 .find(|agent| agent.id == action.agent_id)
511 .map(|agent| agent.name.clone())
512 .unwrap_or_default();
513 self.switcher = None;
514 let app = self.state.clone();
515 let dialog = cx.new(|cx| StartDialog::new(app, request, action, &agent_name, window, cx));
516 cx.subscribe_in(
517 &dialog,
518 window,
519 |this, _, _: &StartDialogEvent, window, cx| {
520 this.agent_dialog = None;
521 window.focus(&this.focus_handle, cx);
522 cx.notify();
523 },
524 )
525 .detach();
526 self.agent_dialog = Some(dialog);
527 cx.notify();
528 }
529
530 fn toggle_shortcuts_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) {
531 if self.shortcuts_dialog.take().is_some() {
532 self.restore_focus(window, cx);
533 cx.notify();
534 return;
535 }
536 self.close_image_viewer(window, cx);
537 self.switcher = None;
538 let dialog = cx.new(|cx| ShortcutsDialog::new(window, cx));
539 cx.subscribe_in(
540 &dialog,
541 window,
542 |this, _, _: &ShortcutsDialogEvent, window, cx| {
543 this.shortcuts_dialog = None;
544 this.restore_focus(window, cx);
545 cx.notify();
546 },
547 )
548 .detach();
549 self.shortcuts_dialog = Some(dialog);
550 cx.notify();
551 }
552
553 fn open_profile_card(&mut self, window: &mut Window, cx: &mut Context<Self>) {
554 let Some(request) = self
555 .state
556 .update(cx, |state, _| state.take_profile_request())
557 else {
558 return;
559 };
560 self.close_image_viewer(window, cx);
561 if let Some(card) = &self.profile_card {
562 card.update(cx, |card, cx| {
563 card.move_to(request.user_id, request.anchor, cx)
564 });
565 return;
566 }
567 let app = self.state.clone();
568 let card = cx.new(|cx| ProfileCard::new(app, request.user_id, request.anchor, window, cx));
569 cx.subscribe_in(
570 &card,
571 window,
572 |this, _, _: &ProfileCardEvent, window, cx| {
573 this.profile_card = None;
574 this.restore_focus(window, cx);
575 cx.notify();
576 },
577 )
578 .detach();
579 self.profile_card = Some(card);
580 cx.notify();
581 }
582
583 fn open_image_viewer(&mut self, window: &mut Window, cx: &mut Context<Self>) {
584 let Some(request) = self
585 .state
586 .update(cx, |state, _| state.take_image_viewer_request())
587 else {
588 return;
589 };
590 self.switcher = None;
591 let app = self.state.clone();
592 let viewer = cx.new(|cx| ImageViewer::new(app, request, window, cx));
593 cx.subscribe_in(
594 &viewer,
595 window,
596 |this, _, _: &ImageViewerEvent, window, cx| {
597 this.image_viewer = None;
598 window.focus(&this.focus_handle, cx);
599 cx.notify();
600 },
601 )
602 .detach();
603 self.image_viewer = Some(viewer);
604 cx.notify();
605 }
606
607 fn start_call_in_open_chat(&mut self, with_video: bool, cx: &mut Context<Self>) {
608 self.state.update(cx, |state, cx| {
609 if let Some(Selection::Chat(chat_id)) = state.selection.clone() {
610 if with_video {
611 state.start_chat_video_call(&chat_id, cx);
612 } else {
613 state.start_chat_call(&chat_id, cx);
614 }
615 }
616 });
617 }
618
619 fn sync_window_fullscreen(&mut self, wanted: bool, window: &mut Window) {
620 if wanted == self.call_window_fullscreen {
621 return;
622 }
623 self.call_window_fullscreen = wanted;
624 if wanted {
625 self.window_was_fullscreen = window.is_fullscreen();
626 }
627 if wanted != window.is_fullscreen() && (wanted || !self.window_was_fullscreen) {
628 window.toggle_fullscreen();
629 }
630 }
631
632 fn close_image_viewer(&mut self, window: &mut Window, cx: &mut Context<Self>) {
633 if self.image_viewer.take().is_some() {
634 window.focus(&self.focus_handle, cx);
635 cx.notify();
636 }
637 }
638
639 fn restore_focus(&self, window: &mut Window, cx: &mut Context<Self>) {
640 match &self.image_viewer {
641 Some(viewer) => {
642 let handle = viewer.read(cx).focus_handle();
643 window.focus(&handle, cx)
644 }
645 None => window.focus(&self.focus_handle, cx),
646 }
647 }
648
649 fn open_forward_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) {
650 let Some(source) = self
651 .state
652 .update(cx, |state, _| state.take_forward_request())
653 else {
654 return;
655 };
656 self.switcher = None;
657 let candidates = candidates_from(self.state.read(cx));
658 let app = self.state.clone();
659 let dialog = cx.new(|cx| ForwardDialog::new(app, source, candidates, window, cx));
660 cx.subscribe_in(
661 &dialog,
662 window,
663 |this, _, event: &ForwardDialogEvent, window, cx| {
664 this.forward_dialog = None;
665 this.restore_focus(window, cx);
666 if let ForwardDialogEvent::Sent { target, title } = event {
667 let target = target.clone();
668 let open = NoticeAction::new("Open", move |state, cx| {
669 state.select(target.clone(), cx)
670 });
671 this.state.update(cx, |state, cx| {
672 state.raise_notice(format!("Forwarded to {title}"), Some(open), cx)
673 });
674 }
675 cx.notify();
676 },
677 )
678 .detach();
679 self.forward_dialog = Some(dialog);
680 cx.notify();
681 }
682}
683
684impl AppShell {
685 fn islands(&self, call_view: Option<AnyElement>, show_sidebar: bool) -> impl IntoElement {
686 h_flex()
687 .debug_selector(|| "shell/islands".into())
688 .flex_1()
689 .min_h_0()
690 .w_full()
691 .gap(px(ISLAND_GAP))
692 .pr(px(ISLAND_GAP))
693 .py(px(ISLAND_GAP))
694 .child(
695 h_flex()
696 .h_full()
697 .flex_none()
698 .child(self.rail.clone())
699 .when(show_sidebar, |group| {
700 group.child(
701 self.sidebar.clone().cached(
702 StyleRefinement::default()
703 .w(px(SIDEBAR_WIDTH))
704 .h_full()
705 .flex_none(),
706 ),
707 )
708 }),
709 )
710 .child(match (call_view, self.prejoin.clone()) {
711 (Some(call_view), _) => call_view,
712 (None, Some(prejoin)) => prejoin
713 .cached(StyleRefinement::default().flex_1().min_w_0().h_full())
714 .into_any_element(),
715 (None, None) => self
716 .conversation
717 .clone()
718 .cached(
719 StyleRefinement::default()
720 .flex_1()
721 .min_w_0()
722 .h_full()
723 .rounded(px(10.))
724 .bg(theme::surface())
725 .overflow_hidden(),
726 )
727 .into_any_element(),
728 })
729 }
730}
731
732impl Render for AppShell {
733 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
734 if let Some(dialog) = self
735 .state
736 .read(cx)
737 .task_dialog
738 .as_ref()
739 .map(|dialog| (dialog.scope.clone(), dialog.card.clone()))
740 {
741 self.state.update(cx, |state, cx| {
742 state.ensure_card_inputs(&dialog.0, &dialog.1, window, cx)
743 });
744 }
745 if let Some(me) = self.state.read(cx).directory.me.clone() {
746 let app = self.state.clone();
747 cx.defer(move |cx| {
748 app.update(cx, |state, cx| {
749 state.request_avatars(vec![me.user_id.clone()], cx);
750 state.request_presence(vec![me.user_id], cx);
751 });
752 });
753 }
754 let chat_thread = self.state.read(cx).call_chat_thread();
755 self.sync_call_chat(chat_thread, window, cx);
756 self.sync_prejoin(window, cx);
757 let chat_panel = self.call_chat.as_ref().map(|(_, view)| view.clone());
758 let state = self.state.read(cx);
759 let call_fullscreen = state.call_fullscreen();
760 let window_width = f32::from(window.viewport_size().width);
761 let panel_open = state
762 .call
763 .as_ref()
764 .is_some_and(|call| call.chat_open || call.people_open || call.transcript_open);
765 let show_sidebar = !(state.viewing_call()
766 && !call_fullscreen
767 && sidebar_hidden_in_call(window_width, panel_open));
768 let island_width = window_width
769 - RAIL_WIDTH
770 - if show_sidebar { SIDEBAR_WIDTH } else { 0. }
771 - 2. * ISLAND_GAP;
772 let call_view = render_call_view(&self.state, state, chat_panel, call_fullscreen, island_width)
773 .filter(|_| state.viewing_call());
774 let (call_view, call_overlay) = match call_view {
775 Some(view) if call_fullscreen => (None, Some(render_call_overlay(view))),
776 view => (view, None),
777 };
778 self.sync_window_fullscreen(call_fullscreen, window);
779 let call_mini = state
780 .call
781 .as_ref()
782 .is_some_and(|call| !call.viewing)
783 .then(|| self.call_mini.clone());
784 let stage_overlay = render_stage_overlay(&self.state, state);
785 let status = render_status_bar(
786 state,
787 &self.update,
788 cx.listener(|this, _, _, cx| this.restart_into_update(cx)),
789 cx.listener(|this, _, _, cx| {
790 this.state
791 .update(cx, |state, cx| state.run_notice_action(cx))
792 }),
793 );
794 let title_bar = render_title_bar(
795 own_status_button(&self.state, state),
796 cx.listener(|this, _, window, cx| this.toggle_switcher("", window, cx)),
797 );
798 div()
799 .id("app-shell")
800 .key_context("AppShell")
801 .track_focus(&self.focus_handle)
802 .on_action(cx.listener(|this, _: &OpenSwitcher, window, cx| {
803 this.toggle_switcher("", window, cx);
804 }))
805 .on_action(cx.listener(|this, _: &NewChat, window, cx| {
806 this.close_image_viewer(window, cx);
807 this.state.update(cx, |state, cx| state.start_new_chat(cx));
808 }))
809 .on_action(cx.listener(|this, _: &ToggleCallMute, _, cx| {
810 this.state
811 .update(cx, |state, cx| state.toggle_call_mute(cx));
812 }))
813 .on_action(cx.listener(|this, _: &PushToTalk, _, cx| {
814 this.state
815 .update(cx, |state, cx| state.press_push_to_talk(cx));
816 }))
817 .on_key_up(cx.listener(|this, event: &KeyUpEvent, _, cx| {
818 if event.keystroke.key == "space" {
819 this.state
820 .update(cx, |state, cx| state.release_push_to_talk(cx));
821 }
822 }))
823 .on_modifiers_changed(cx.listener(|this, event: &ModifiersChangedEvent, _, cx| {
824 if !event.modifiers.control {
825 this.state
826 .update(cx, |state, cx| state.release_push_to_talk(cx));
827 }
828 }))
829 .on_action(cx.listener(|this, _: &ShowShortcuts, window, cx| {
830 this.toggle_shortcuts_dialog(window, cx);
831 }))
832 .on_action(cx.listener(|this, _: &OpenActivity, window, cx| {
833 this.close_image_viewer(window, cx);
834 this.sidebar
835 .update(cx, |sidebar, cx| sidebar.show_activity(cx));
836 }))
837 .on_action(cx.listener(|this, _: &OpenSaved, window, cx| {
838 this.close_image_viewer(window, cx);
839 this.sidebar
840 .update(cx, |sidebar, cx| sidebar.show_saved(cx));
841 }))
842 .on_action(cx.listener(|this, _: &OpenChatsTab, window, cx| {
843 this.close_image_viewer(window, cx);
844 this.sidebar
845 .update(cx, |sidebar, cx| sidebar.show_chats(cx));
846 }))
847 .on_action(cx.listener(|this, _: &OpenChannelsTab, window, cx| {
848 this.close_image_viewer(window, cx);
849 this.sidebar
850 .update(cx, |sidebar, cx| sidebar.show_channels(cx));
851 }))
852 .on_action(cx.listener(|this, _: &OpenCallsTab, window, cx| {
853 this.close_image_viewer(window, cx);
854 this.sidebar
855 .update(cx, |sidebar, cx| sidebar.show_calls(cx));
856 }))
857 .on_action(cx.listener(|this, _: &PreviousConversation, window, cx| {
858 this.close_image_viewer(window, cx);
859 this.sidebar.update(cx, |sidebar, cx| {
860 sidebar.select_adjacent(Step::Previous, cx)
861 });
862 }))
863 .on_action(cx.listener(|this, _: &NextConversation, window, cx| {
864 this.close_image_viewer(window, cx);
865 this.sidebar
866 .update(cx, |sidebar, cx| sidebar.select_adjacent(Step::Next, cx));
867 }))
868 .on_action(cx.listener(|this, _: &AcceptCall, _, cx| {
869 this.state
870 .update(cx, |state, cx| state.accept_ringing_call(cx));
871 }))
872 .on_action(cx.listener(|this, _: &DeclineCall, _, cx| {
873 this.state
874 .update(cx, |state, cx| state.decline_ringing_call(cx));
875 }))
876 .on_action(cx.listener(|this, _: &JoinMeetingFromToast, _, cx| {
877 this.state
878 .update(cx, |state, cx| state.join_latest_meeting_toast(cx));
879 }))
880 .on_action(cx.listener(|this, _: &HangUpCall, _, cx| {
881 this.state.update(cx, |state, cx| state.leave_call(cx));
882 }))
883 .on_action(cx.listener(|this, _: &ToggleCallCamera, _, cx| {
884 this.state
885 .update(cx, |state, cx| state.toggle_call_camera(cx));
886 }))
887 .on_action(cx.listener(|this, _: &ToggleCallShare, _, cx| {
888 this.state
889 .update(cx, |state, cx| state.toggle_call_share(cx));
890 }))
891 .on_action(cx.listener(|this, _: &ToggleCallHand, _, cx| {
892 this.state
893 .update(cx, |state, cx| state.toggle_call_hand(cx));
894 }))
895 .on_action(cx.listener(|this, _: &OpenLobbyList, _, cx| {
896 this.state
897 .update(cx, |state, cx| state.open_call_lobby_list(cx));
898 }))
899 .on_action(cx.listener(|this, _: &StartAudioCall, _, cx| {
900 this.start_call_in_open_chat(false, cx);
901 }))
902 .on_action(cx.listener(|this, _: &StartVideoCall, _, cx| {
903 this.start_call_in_open_chat(true, cx);
904 }))
905 .on_action(cx.listener(|this, _: &ToggleCallFullscreen, _, cx| {
906 if this.image_viewer.is_some() || !this.state.read(cx).viewing_call() {
907 cx.propagate();
908 return;
909 }
910 this.state
911 .update(cx, |state, cx| state.toggle_call_fullscreen(cx));
912 }))
913 .on_action(zoom_listener::<ZoomShareIn>(&self.state, ZoomStep::In))
914 .on_action(zoom_listener::<ZoomShareOut>(&self.state, ZoomStep::Out))
915 .on_action(zoom_listener::<ZoomShareReset>(&self.state, ZoomStep::Reset))
916 .on_action(cx.listener(|this, _: &ReplyToHovered, window, cx| {
917 this.close_image_viewer(window, cx);
918 this.conversation.update(cx, |conversation, cx| {
919 conversation.reply_to_hovered(window, cx)
920 });
921 }))
922 .relative()
923 .size_full()
924 .bg(theme::background())
925 .text_color(theme::text())
926 .text_size(px(14.))
927 .child(crate::frame_log::probe("first"))
928 .child(user_activity::input_probe(self.user_input.clone()))
929 .child(
930 v_flex()
931 .debug_selector(|| "shell".into())
932 .size_full()
933 .child(title_bar)
934 .child(self.islands(call_view, show_sidebar))
935 .child(status),
936 )
937 .children(call_mini)
938 .children(call_overlay)
939 .children(stage_overlay)
940 .children(self.image_viewer.clone())
941 .children(self.switcher.clone())
942 .children(render_task_dialog(self.state.read(cx), cx))
943 .children(self.forward_dialog.clone())
944 .children(self.status_dialog.clone())
945 .children(self.shortcuts_dialog.clone())
946 .children(self.agent_dialog.clone())
947 .children(self.profile_card.clone())
948 .child(crate::frame_log::probe("last"))
949 }
950}