BlueGit

ict rusty-teams

Files

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

shell.rs

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