BlueGit

ict rusty-teams

Files

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

shell.rs

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