BlueGit

ict rusty-teams

Files

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

shell.rs

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