BlueGit

ict rusty-teams

Files

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

shell.rs

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