BlueGit

ict rusty-teams

Files

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

shell.rs

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