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