BlueGit

ict rusty-teams

Files

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

shell.rs

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