BlueGit

ict rusty-teams

Files

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

shell.rs

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