BlueGit

ict rusty-teams

Files

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

shell.rs

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