BlueGit

ict rusty-teams

Files

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

shell.rs

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