BlueGit

ict rusty-teams

Files

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

shell.rs

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