BlueGit

ict rusty-teams

Files

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

shell.rs

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