BlueGit

ict rusty-teams

Files

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

shell.rs

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