| 1 | use gpui_kit::component::{h_flex, v_flex}; |
| 2 | use gpui_kit::*; |
| 3 | |
| 4 | use super::activity_panel::{ActivityPanel, ActivityPanelEvent}; |
| 5 | use super::call_mini::render_call_mini; |
| 6 | use super::call_stage::render_stage_overlay; |
| 7 | use super::call_view::render_call_view; |
| 8 | use super::conversation::{ConversationView, ReplyToHovered}; |
| 9 | use super::dialog_overlay::render_task_dialog; |
| 10 | use super::forward_dialog::{ForwardDialog, ForwardDialogEvent}; |
| 11 | use super::profile_card::{ProfileCard, ProfileCardEvent}; |
| 12 | use super::saved_panel::{SavedPanel, SavedPanelEvent}; |
| 13 | use super::shortcuts::{ |
| 14 | AcceptCall, DeclineCall, HangUpCall, NextConversation, OpenActivity, OpenChannelsTab, |
| 15 | OpenCallsTab, OpenChatsTab, OpenSaved, PreviousConversation, Scope, ShowShortcuts, ToggleCallCamera, |
| 16 | ToggleCallShare, |
| 17 | }; |
| 18 | use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent}; |
| 19 | use super::sidebar::{SIDEBAR_WIDTH, SidebarView}; |
| 20 | use super::status_bar::render_status_bar; |
| 21 | use super::status_menu::own_status_button; |
| 22 | use super::status_message_dialog::{StatusMessageDialog, StatusMessageDialogEvent}; |
| 23 | use super::switcher::{Switcher, SwitcherEvent, candidates_from}; |
| 24 | use super::title_bar::render_title_bar; |
| 25 | use crate::activity::ActivityCenter; |
| 26 | use crate::app_state::{AppEvent, AppState, Selection}; |
| 27 | use crate::call::{CallMedia, CallWindows}; |
| 28 | use crate::embedded_web::{Overlays, RootFocus}; |
| 29 | use crate::notice::NoticeAction; |
| 30 | use crate::notify::{NotificationCenter, selection_for}; |
| 31 | use crate::sidebar_model::Step; |
| 32 | use crate::theme; |
| 33 | use crate::updater::{self, IdleInputs, UpdateStatus}; |
| 34 | |
| 35 | actions!(teams, [OpenSwitcher, NewChat, ToggleCallMute]); |
| 36 | |
| 37 | pub fn bind_keys(cx: &mut App) { |
| 38 | super::composer::bind_keys(cx); |
| 39 | super::shortcuts::bind_scopes(cx, &[Scope::Global, Scope::OutsideComposer, Scope::GlobalOverTextFields]); |
| 40 | } |
| 41 | |
| 42 | #[derive(Debug, Clone, Copy)] |
| 43 | pub enum OpenTarget { |
| 44 | Chat(usize), |
| 45 | Channel(usize), |
| 46 | } |
| 47 | |
| 48 | #[derive(Default)] |
| 49 | pub struct Startup { |
| 50 | pub switcher_query: Option<String>, |
| 51 | pub composer_text: Option<String>, |
| 52 | pub reply_to_last: bool, |
| 53 | } |
| 54 | |
| 55 | pub struct AppShell { |
| 56 | state: Entity<AppState>, |
| 57 | sidebar: Entity<SidebarView>, |
| 58 | conversation: Entity<ConversationView>, |
| 59 | call_chat: Option<(String, Entity<ConversationView>)>, |
| 60 | switcher: Option<Entity<Switcher>>, |
| 61 | notifications: Entity<NotificationCenter>, |
| 62 | _call_windows: Entity<CallWindows>, |
| 63 | activity: Entity<ActivityCenter>, |
| 64 | activity_panel: Option<Entity<ActivityPanel>>, |
| 65 | saved_panel: Option<Entity<SavedPanel>>, |
| 66 | forward_dialog: Option<Entity<ForwardDialog>>, |
| 67 | status_dialog: Option<Entity<StatusMessageDialog>>, |
| 68 | shortcuts_dialog: Option<Entity<ShortcutsDialog>>, |
| 69 | profile_card: Option<Entity<ProfileCard>>, |
| 70 | focus_handle: FocusHandle, |
| 71 | open_target: Option<OpenTarget>, |
| 72 | update: UpdateStatus, |
| 73 | _subscription: Subscription, |
| 74 | _call_media_observation: Subscription, |
| 75 | _activity_observation: Subscription, |
| 76 | _escape_observation: Subscription, |
| 77 | _activation_observation: Subscription, |
| 78 | } |
| 79 | |
| 80 | impl AppShell { |
| 81 | fn sync_call_chat(&mut self, thread: Option<String>, window: &mut Window, cx: &mut Context<Self>) { |
| 82 | match (thread, &self.call_chat) { |
| 83 | (Some(wanted), Some((open, _))) if &wanted == open => {} |
| 84 | (Some(wanted), _) => { |
| 85 | let app = self.state.clone(); |
| 86 | let selection = Selection::Chat(wanted.clone()); |
| 87 | let view = cx.new(|cx| ConversationView::pinned_to(app, selection, window, cx)); |
| 88 | self.call_chat = Some((wanted, view)); |
| 89 | } |
| 90 | (None, _) => self.call_chat = None, |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | pub fn new( |
| 95 | state: Entity<AppState>, |
| 96 | open_target: Option<OpenTarget>, |
| 97 | startup: Startup, |
| 98 | window: &mut Window, |
| 99 | cx: &mut Context<Self>, |
| 100 | ) -> Self { |
| 101 | let call_media = cx.new(|_| CallMedia); |
| 102 | state.update(cx, |state, _| state.call_media = Some(call_media.clone())); |
| 103 | let call_media_observation = cx.observe(&call_media, |_, _, cx| cx.notify()); |
| 104 | let sidebar = cx.new(|cx| SidebarView::new(state.clone(), cx)); |
| 105 | let conversation = cx.new(|cx| ConversationView::new(state.clone(), window, cx)); |
| 106 | let subscription = |
| 107 | cx.subscribe_in(&state, window, |this, _, event: &AppEvent, window, cx| { |
| 108 | if matches!(event, AppEvent::Sidebar | AppEvent::Status) { |
| 109 | this.apply_open_target(cx); |
| 110 | } |
| 111 | if matches!(event, AppEvent::Forward) { |
| 112 | this.open_forward_dialog(window, cx); |
| 113 | } |
| 114 | if matches!(event, AppEvent::StatusMessage) { |
| 115 | this.open_status_dialog(window, cx); |
| 116 | } |
| 117 | if matches!(event, AppEvent::NotificationSettings) { |
| 118 | this.notifications |
| 119 | .update(cx, |center, cx| center.open_settings(cx)); |
| 120 | } |
| 121 | if matches!(event, AppEvent::Profile) { |
| 122 | this.open_profile_card(window, cx); |
| 123 | } |
| 124 | cx.notify(); |
| 125 | }); |
| 126 | let focus_handle = cx.focus_handle(); |
| 127 | window.focus(&focus_handle, cx); |
| 128 | cx.set_global(RootFocus(focus_handle.clone())); |
| 129 | let notifications = cx.new(|cx| NotificationCenter::new(state.clone(), window, cx)); |
| 130 | let call_windows = cx.new(|cx| CallWindows::new(state.clone(), window, cx)); |
| 131 | let activity = cx.new(|cx| ActivityCenter::new(state.clone(), window, cx)); |
| 132 | let activity_observation = cx.observe(&activity, |_, _, cx| cx.notify()); |
| 133 | let escape_observation = cx.observe_keystrokes(|this, event, _, cx| { |
| 134 | if event.keystroke.key == "escape" { |
| 135 | this.state.update(cx, |state, cx| state.leave_stage_fullscreen(cx)); |
| 136 | } |
| 137 | }); |
| 138 | let activation_observation = cx.observe_window_activation(window, |this, window, cx| { |
| 139 | if window.is_window_active() { |
| 140 | this.state.update(cx, |state, cx| state.refresh_calendar(cx)); |
| 141 | } |
| 142 | }); |
| 143 | let closing = notifications.clone(); |
| 144 | window.on_window_should_close(cx, move |_, cx| !closing.read(cx).intercept_close(cx)); |
| 145 | let mut shell = AppShell { |
| 146 | state, |
| 147 | sidebar, |
| 148 | conversation, |
| 149 | call_chat: None, |
| 150 | switcher: None, |
| 151 | notifications, |
| 152 | _call_windows: call_windows, |
| 153 | activity, |
| 154 | activity_panel: None, |
| 155 | saved_panel: None, |
| 156 | forward_dialog: None, |
| 157 | status_dialog: None, |
| 158 | shortcuts_dialog: None, |
| 159 | profile_card: None, |
| 160 | focus_handle, |
| 161 | open_target, |
| 162 | update: UpdateStatus::UpToDate, |
| 163 | _subscription: subscription, |
| 164 | _call_media_observation: call_media_observation, |
| 165 | _activity_observation: activity_observation, |
| 166 | _escape_observation: escape_observation, |
| 167 | _activation_observation: activation_observation, |
| 168 | }; |
| 169 | shell.apply_open_target(cx); |
| 170 | let Startup { |
| 171 | switcher_query, |
| 172 | composer_text, |
| 173 | reply_to_last, |
| 174 | } = startup; |
| 175 | if let Some(query) = switcher_query { |
| 176 | shell.toggle_switcher(&query, window, cx); |
| 177 | } |
| 178 | if composer_text.is_some() || reply_to_last { |
| 179 | cx.defer_in(window, move |this, window, cx| { |
| 180 | this.conversation.update(cx, |conversation, cx| { |
| 181 | if reply_to_last { |
| 182 | conversation.reply_to_latest_from_others(window, cx); |
| 183 | } |
| 184 | if let Some(text) = composer_text { |
| 185 | conversation.set_composer_text(&text, window, cx); |
| 186 | } |
| 187 | }); |
| 188 | }); |
| 189 | } |
| 190 | #[cfg(windows)] |
| 191 | cx.spawn_in(window, async move |this, cx| { |
| 192 | loop { |
| 193 | cx.background_executor().timer(updater::POLL_INTERVAL).await; |
| 194 | if this |
| 195 | .update_in(cx, |this, window, cx| this.poll_update(window, cx)) |
| 196 | .is_err() |
| 197 | { |
| 198 | break; |
| 199 | } |
| 200 | } |
| 201 | }) |
| 202 | .detach(); |
| 203 | shell |
| 204 | } |
| 205 | |
| 206 | #[cfg_attr(not(windows), allow(dead_code))] |
| 207 | fn poll_update(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 208 | if matches!(self.update, UpdateStatus::Failed(_) | UpdateStatus::Installing) { |
| 209 | return; |
| 210 | } |
| 211 | let Some(paths) = updater::current_paths() else { |
| 212 | return; |
| 213 | }; |
| 214 | if self.update == UpdateStatus::UpToDate { |
| 215 | if !updater::check(&paths) { |
| 216 | return; |
| 217 | } |
| 218 | self.update = UpdateStatus::Ready; |
| 219 | let update_exe = paths.update_exe.clone(); |
| 220 | cx.background_spawn(async move { updater::prescan(&update_exe) }) |
| 221 | .detach(); |
| 222 | } |
| 223 | let conversation = self.conversation.read(cx); |
| 224 | let idle = updater::is_idle(IdleInputs { |
| 225 | window_active: window.is_window_active(), |
| 226 | composer_empty: conversation.composer_is_empty(cx), |
| 227 | send_in_flight: conversation.send_in_flight(), |
| 228 | }); |
| 229 | if idle { |
| 230 | self.restart_into_update(cx); |
| 231 | } |
| 232 | cx.notify(); |
| 233 | } |
| 234 | |
| 235 | fn restart_into_update(&mut self, cx: &mut Context<Self>) { |
| 236 | if self.update == UpdateStatus::Installing { |
| 237 | return; |
| 238 | } |
| 239 | let Some(paths) = updater::current_paths() else { |
| 240 | return; |
| 241 | }; |
| 242 | self.update = UpdateStatus::Installing; |
| 243 | cx.notify(); |
| 244 | cx.spawn(async move |this, cx| { |
| 245 | let result = cx |
| 246 | .background_spawn(async move { updater::install_and_relaunch(&paths) }) |
| 247 | .await; |
| 248 | let _ = this.update(cx, |this, cx| { |
| 249 | match result { |
| 250 | Ok(()) => cx.quit(), |
| 251 | Err(message) => this.update = UpdateStatus::Failed(message), |
| 252 | } |
| 253 | cx.notify(); |
| 254 | }); |
| 255 | }) |
| 256 | .detach(); |
| 257 | } |
| 258 | |
| 259 | fn apply_open_target(&mut self, cx: &mut Context<Self>) { |
| 260 | let Some(target) = self.open_target else { |
| 261 | return; |
| 262 | }; |
| 263 | let sidebar = &self.state.read(cx).sidebar; |
| 264 | let selection = match target { |
| 265 | OpenTarget::Chat(index) => sidebar |
| 266 | .chats |
| 267 | .get(index) |
| 268 | .map(|chat| Selection::Chat(chat.id.clone())), |
| 269 | OpenTarget::Channel(index) => sidebar |
| 270 | .teams |
| 271 | .iter() |
| 272 | .flat_map(|team| team.channels.iter()) |
| 273 | .nth(index) |
| 274 | .map(|channel| Selection::Channel(channel.id.clone())), |
| 275 | }; |
| 276 | if let Some(selection) = selection { |
| 277 | self.open_target = None; |
| 278 | self.state |
| 279 | .update(cx, |state, cx| state.select(selection, cx)); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | fn toggle_switcher( |
| 284 | &mut self, |
| 285 | initial_query: &str, |
| 286 | window: &mut Window, |
| 287 | cx: &mut Context<Self>, |
| 288 | ) { |
| 289 | if self.switcher.take().is_some() { |
| 290 | window.focus(&self.focus_handle, cx); |
| 291 | cx.notify(); |
| 292 | return; |
| 293 | } |
| 294 | self.activity_panel = None; |
| 295 | self.saved_panel = None; |
| 296 | let candidates = candidates_from(self.state.read(cx)); |
| 297 | let app = self.state.clone(); |
| 298 | let switcher = cx.new(|cx| Switcher::new(app, candidates, initial_query, window, cx)); |
| 299 | cx.subscribe_in( |
| 300 | &switcher, |
| 301 | window, |
| 302 | |this, _, event: &SwitcherEvent, window, cx| { |
| 303 | match event { |
| 304 | SwitcherEvent::Pick(selection) => { |
| 305 | let selection = selection.clone(); |
| 306 | this.state |
| 307 | .update(cx, |state, cx| state.select(selection, cx)); |
| 308 | } |
| 309 | SwitcherEvent::PickMessage { |
| 310 | selection, |
| 311 | message_id, |
| 312 | } => { |
| 313 | let (selection, message_id) = (selection.clone(), message_id.clone()); |
| 314 | this.state.update(cx, |state, cx| { |
| 315 | state.jump_to_message(selection, message_id, cx) |
| 316 | }); |
| 317 | } |
| 318 | SwitcherEvent::Close => {} |
| 319 | } |
| 320 | this.switcher = None; |
| 321 | window.focus(&this.focus_handle, cx); |
| 322 | cx.notify(); |
| 323 | }, |
| 324 | ) |
| 325 | .detach(); |
| 326 | self.switcher = Some(switcher); |
| 327 | cx.notify(); |
| 328 | } |
| 329 | |
| 330 | fn toggle_activity_panel(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 331 | if self.activity_panel.take().is_some() { |
| 332 | window.focus(&self.focus_handle, cx); |
| 333 | cx.notify(); |
| 334 | return; |
| 335 | } |
| 336 | self.switcher = None; |
| 337 | self.saved_panel = None; |
| 338 | let (app, activity) = (self.state.clone(), self.activity.clone()); |
| 339 | let panel = cx.new(|cx| ActivityPanel::new(app, activity, window, cx)); |
| 340 | cx.subscribe_in( |
| 341 | &panel, |
| 342 | window, |
| 343 | |this, _, event: &ActivityPanelEvent, window, cx| { |
| 344 | this.activity_panel = None; |
| 345 | window.focus(&this.focus_handle, cx); |
| 346 | match event { |
| 347 | ActivityPanelEvent::Close => {} |
| 348 | ActivityPanelEvent::OpenSettings => this |
| 349 | .notifications |
| 350 | .update(cx, |center, cx| center.open_settings(cx)), |
| 351 | ActivityPanelEvent::Open { |
| 352 | conversation_id, |
| 353 | message_id, |
| 354 | } => { |
| 355 | let selection = |
| 356 | selection_for(&this.state.read(cx).sidebar, conversation_id); |
| 357 | if let Some(selection) = selection { |
| 358 | let message_id = message_id.clone(); |
| 359 | this.state.update(cx, |state, cx| { |
| 360 | if message_id.is_empty() { |
| 361 | state.select(selection, cx) |
| 362 | } else { |
| 363 | state.jump_to_message(selection, message_id, cx) |
| 364 | } |
| 365 | }); |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | cx.notify(); |
| 370 | }, |
| 371 | ) |
| 372 | .detach(); |
| 373 | self.activity_panel = Some(panel); |
| 374 | cx.notify(); |
| 375 | } |
| 376 | fn toggle_saved_panel(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 377 | if self.saved_panel.take().is_some() { |
| 378 | window.focus(&self.focus_handle, cx); |
| 379 | cx.notify(); |
| 380 | return; |
| 381 | } |
| 382 | self.switcher = None; |
| 383 | self.activity_panel = None; |
| 384 | let app = self.state.clone(); |
| 385 | let panel = cx.new(|cx| SavedPanel::new(app, window, cx)); |
| 386 | cx.subscribe_in( |
| 387 | &panel, |
| 388 | window, |
| 389 | |this, _, event: &SavedPanelEvent, window, cx| { |
| 390 | this.saved_panel = None; |
| 391 | window.focus(&this.focus_handle, cx); |
| 392 | if let SavedPanelEvent::Open { |
| 393 | conversation_id, |
| 394 | message_id, |
| 395 | } = event |
| 396 | { |
| 397 | let selection = selection_for(&this.state.read(cx).sidebar, conversation_id); |
| 398 | if let Some(selection) = selection { |
| 399 | let message_id = message_id.clone(); |
| 400 | this.state.update(cx, |state, cx| { |
| 401 | state.jump_to_message(selection, message_id, cx) |
| 402 | }); |
| 403 | } |
| 404 | } |
| 405 | cx.notify(); |
| 406 | }, |
| 407 | ) |
| 408 | .detach(); |
| 409 | self.saved_panel = Some(panel); |
| 410 | cx.notify(); |
| 411 | } |
| 412 | |
| 413 | fn open_status_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 414 | if !self |
| 415 | .state |
| 416 | .update(cx, |state, _| state.take_status_message_request()) |
| 417 | { |
| 418 | return; |
| 419 | } |
| 420 | self.switcher = None; |
| 421 | self.activity_panel = None; |
| 422 | self.saved_panel = None; |
| 423 | let app = self.state.clone(); |
| 424 | let dialog = cx.new(|cx| StatusMessageDialog::new(app, window, cx)); |
| 425 | cx.subscribe_in( |
| 426 | &dialog, |
| 427 | window, |
| 428 | |this, _, _: &StatusMessageDialogEvent, window, cx| { |
| 429 | this.status_dialog = None; |
| 430 | window.focus(&this.focus_handle, cx); |
| 431 | cx.notify(); |
| 432 | }, |
| 433 | ) |
| 434 | .detach(); |
| 435 | self.status_dialog = Some(dialog); |
| 436 | cx.notify(); |
| 437 | } |
| 438 | |
| 439 | fn toggle_shortcuts_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 440 | if self.shortcuts_dialog.take().is_some() { |
| 441 | window.focus(&self.focus_handle, cx); |
| 442 | cx.notify(); |
| 443 | return; |
| 444 | } |
| 445 | self.switcher = None; |
| 446 | self.activity_panel = None; |
| 447 | self.saved_panel = None; |
| 448 | let dialog = cx.new(|cx| ShortcutsDialog::new(window, cx)); |
| 449 | cx.subscribe_in( |
| 450 | &dialog, |
| 451 | window, |
| 452 | |this, _, _: &ShortcutsDialogEvent, window, cx| { |
| 453 | this.shortcuts_dialog = None; |
| 454 | window.focus(&this.focus_handle, cx); |
| 455 | cx.notify(); |
| 456 | }, |
| 457 | ) |
| 458 | .detach(); |
| 459 | self.shortcuts_dialog = Some(dialog); |
| 460 | cx.notify(); |
| 461 | } |
| 462 | |
| 463 | fn open_profile_card(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 464 | let Some(request) = self |
| 465 | .state |
| 466 | .update(cx, |state, _| state.take_profile_request()) |
| 467 | else { |
| 468 | return; |
| 469 | }; |
| 470 | if let Some(card) = &self.profile_card { |
| 471 | card.update(cx, |card, cx| { |
| 472 | card.move_to(request.user_id, request.anchor, cx) |
| 473 | }); |
| 474 | return; |
| 475 | } |
| 476 | let app = self.state.clone(); |
| 477 | let card = cx.new(|cx| ProfileCard::new(app, request.user_id, request.anchor, window, cx)); |
| 478 | cx.subscribe_in( |
| 479 | &card, |
| 480 | window, |
| 481 | |this, _, _: &ProfileCardEvent, window, cx| { |
| 482 | this.profile_card = None; |
| 483 | window.focus(&this.focus_handle, cx); |
| 484 | cx.notify(); |
| 485 | }, |
| 486 | ) |
| 487 | .detach(); |
| 488 | self.profile_card = Some(card); |
| 489 | cx.notify(); |
| 490 | } |
| 491 | |
| 492 | fn open_forward_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 493 | let Some(source) = self |
| 494 | .state |
| 495 | .update(cx, |state, _| state.take_forward_request()) |
| 496 | else { |
| 497 | return; |
| 498 | }; |
| 499 | self.switcher = None; |
| 500 | self.activity_panel = None; |
| 501 | self.saved_panel = None; |
| 502 | let candidates = candidates_from(self.state.read(cx)); |
| 503 | let app = self.state.clone(); |
| 504 | let dialog = cx.new(|cx| ForwardDialog::new(app, source, candidates, window, cx)); |
| 505 | cx.subscribe_in( |
| 506 | &dialog, |
| 507 | window, |
| 508 | |this, _, event: &ForwardDialogEvent, window, cx| { |
| 509 | this.forward_dialog = None; |
| 510 | window.focus(&this.focus_handle, cx); |
| 511 | if let ForwardDialogEvent::Sent { target, title } = event { |
| 512 | let target = target.clone(); |
| 513 | let open = NoticeAction::new("Open", move |state, cx| { |
| 514 | state.select(target.clone(), cx) |
| 515 | }); |
| 516 | this.state.update(cx, |state, cx| { |
| 517 | state.raise_notice(format!("Forwarded to {title}"), Some(open), cx) |
| 518 | }); |
| 519 | } |
| 520 | cx.notify(); |
| 521 | }, |
| 522 | ) |
| 523 | .detach(); |
| 524 | self.forward_dialog = Some(dialog); |
| 525 | cx.notify(); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | impl Render for AppShell { |
| 530 | fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { |
| 531 | if let Some(dialog) = self |
| 532 | .state |
| 533 | .read(cx) |
| 534 | .task_dialog |
| 535 | .as_ref() |
| 536 | .map(|dialog| (dialog.scope.clone(), dialog.card.clone())) |
| 537 | { |
| 538 | self.state.update(cx, |state, cx| { |
| 539 | state.ensure_card_inputs(&dialog.0, &dialog.1, window, cx) |
| 540 | }); |
| 541 | } |
| 542 | if let Some(me) = self.state.read(cx).directory.me.clone() { |
| 543 | let app = self.state.clone(); |
| 544 | cx.defer(move |cx| { |
| 545 | app.update(cx, |state, cx| { |
| 546 | state.request_avatars(vec![me.user_id.clone()], cx); |
| 547 | state.request_presence(vec![me.user_id], cx); |
| 548 | }); |
| 549 | }); |
| 550 | } |
| 551 | let panels = self.switcher.is_some() |
| 552 | || self.activity_panel.is_some() |
| 553 | || self.saved_panel.is_some() |
| 554 | || self.forward_dialog.is_some() |
| 555 | || self.status_dialog.is_some() |
| 556 | || self.shortcuts_dialog.is_some() |
| 557 | || self.profile_card.is_some() |
| 558 | || { |
| 559 | let state = self.state.read(cx); |
| 560 | state.task_dialog.is_some() || state.status_menu_open |
| 561 | }; |
| 562 | Overlays::update(cx, |overlays| overlays.panels = panels); |
| 563 | let chat_thread = self.state.read(cx).call_chat_thread(); |
| 564 | self.sync_call_chat(chat_thread, window, cx); |
| 565 | let chat_panel = self.call_chat.as_ref().map(|(_, view)| view.clone()); |
| 566 | let state = self.state.read(cx); |
| 567 | let call_view = render_call_view(&self.state, state, chat_panel).filter(|_| state.viewing_call()); |
| 568 | let call_mini = render_call_mini(&self.state, state); |
| 569 | let stage_overlay = render_stage_overlay(&self.state, state); |
| 570 | let status = render_status_bar( |
| 571 | state, |
| 572 | &self.update, |
| 573 | cx.listener(|this, _, _, cx| this.restart_into_update(cx)), |
| 574 | cx.listener(|this, _, _, cx| { |
| 575 | this.state |
| 576 | .update(cx, |state, cx| state.run_notice_action(cx)) |
| 577 | }), |
| 578 | ); |
| 579 | let title_bar = render_title_bar( |
| 580 | own_status_button(&self.state, state), |
| 581 | self.activity.read(cx).feed().unread_count(), |
| 582 | cx.listener(|this, _, window, cx| this.toggle_switcher("", window, cx)), |
| 583 | cx.listener(|this, _, window, cx| this.toggle_saved_panel(window, cx)), |
| 584 | cx.listener(|this, _, window, cx| this.toggle_activity_panel(window, cx)), |
| 585 | ); |
| 586 | div() |
| 587 | .id("app-shell") |
| 588 | .key_context("AppShell") |
| 589 | .track_focus(&self.focus_handle) |
| 590 | .on_action(cx.listener(|this, _: &OpenSwitcher, window, cx| { |
| 591 | this.toggle_switcher("", window, cx); |
| 592 | })) |
| 593 | .on_action(cx.listener(|this, _: &NewChat, _, cx| { |
| 594 | this.state.update(cx, |state, cx| state.start_new_chat(cx)); |
| 595 | })) |
| 596 | .on_action(cx.listener(|this, _: &ToggleCallMute, _, cx| { |
| 597 | this.state.update(cx, |state, cx| state.toggle_call_mute(cx)); |
| 598 | })) |
| 599 | .on_action(cx.listener(|this, _: &ShowShortcuts, window, cx| { |
| 600 | this.toggle_shortcuts_dialog(window, cx); |
| 601 | })) |
| 602 | .on_action(cx.listener(|this, _: &OpenActivity, window, cx| { |
| 603 | this.toggle_activity_panel(window, cx); |
| 604 | })) |
| 605 | .on_action(cx.listener(|this, _: &OpenSaved, window, cx| { |
| 606 | this.toggle_saved_panel(window, cx); |
| 607 | })) |
| 608 | .on_action(cx.listener(|this, _: &OpenChatsTab, _, cx| { |
| 609 | this.sidebar.update(cx, |sidebar, cx| sidebar.show_chats(cx)); |
| 610 | })) |
| 611 | .on_action(cx.listener(|this, _: &OpenChannelsTab, _, cx| { |
| 612 | this.sidebar.update(cx, |sidebar, cx| sidebar.show_channels(cx)); |
| 613 | })) |
| 614 | .on_action(cx.listener(|this, _: &OpenCallsTab, _, cx| { |
| 615 | this.sidebar.update(cx, |sidebar, cx| sidebar.show_calls(cx)); |
| 616 | })) |
| 617 | .on_action(cx.listener(|this, _: &PreviousConversation, _, cx| { |
| 618 | this.sidebar |
| 619 | .update(cx, |sidebar, cx| sidebar.select_adjacent(Step::Previous, cx)); |
| 620 | })) |
| 621 | .on_action(cx.listener(|this, _: &NextConversation, _, cx| { |
| 622 | this.sidebar |
| 623 | .update(cx, |sidebar, cx| sidebar.select_adjacent(Step::Next, cx)); |
| 624 | })) |
| 625 | .on_action(cx.listener(|this, _: &AcceptCall, _, cx| { |
| 626 | this.state.update(cx, |state, cx| state.accept_ringing_call(cx)); |
| 627 | })) |
| 628 | .on_action(cx.listener(|this, _: &DeclineCall, _, cx| { |
| 629 | this.state.update(cx, |state, cx| state.decline_ringing_call(cx)); |
| 630 | })) |
| 631 | .on_action(cx.listener(|this, _: &HangUpCall, _, cx| { |
| 632 | this.state.update(cx, |state, cx| state.leave_call(cx)); |
| 633 | })) |
| 634 | .on_action(cx.listener(|this, _: &ToggleCallCamera, _, cx| { |
| 635 | this.state.update(cx, |state, cx| state.toggle_call_camera(cx)); |
| 636 | })) |
| 637 | .on_action(cx.listener(|this, _: &ToggleCallShare, _, cx| { |
| 638 | this.state.update(cx, |state, cx| state.toggle_call_share(cx)); |
| 639 | })) |
| 640 | .on_action(cx.listener(|this, _: &ReplyToHovered, window, cx| { |
| 641 | this.conversation.update(cx, |conversation, cx| { |
| 642 | conversation.reply_to_hovered(window, cx) |
| 643 | }); |
| 644 | })) |
| 645 | .relative() |
| 646 | .size_full() |
| 647 | .bg(theme::background()) |
| 648 | .text_color(theme::text()) |
| 649 | .text_size(px(14.)) |
| 650 | .child(crate::frame_log::probe("first")) |
| 651 | .child( |
| 652 | v_flex() |
| 653 | .size_full() |
| 654 | .child(title_bar) |
| 655 | .child( |
| 656 | h_flex() |
| 657 | .flex_1() |
| 658 | .min_h_0() |
| 659 | .w_full() |
| 660 | .child(self.sidebar.clone().cached(StyleRefinement::default().w(px(SIDEBAR_WIDTH)).h_full().flex_none())) |
| 661 | .child(match call_view { |
| 662 | Some(call_view) => call_view, |
| 663 | None => self |
| 664 | .conversation |
| 665 | .clone() |
| 666 | .cached(StyleRefinement::default().flex_1().min_w_0().h_full()) |
| 667 | .into_any_element(), |
| 668 | }), |
| 669 | ) |
| 670 | .child(status), |
| 671 | ) |
| 672 | .children(call_mini) |
| 673 | .children(stage_overlay) |
| 674 | .children(self.activity_panel.clone()) |
| 675 | .children(self.saved_panel.clone()) |
| 676 | .children(self.switcher.clone()) |
| 677 | .children(render_task_dialog(self.state.read(cx), cx)) |
| 678 | .children(self.forward_dialog.clone()) |
| 679 | .children(self.status_dialog.clone()) |
| 680 | .children(self.shortcuts_dialog.clone()) |
| 681 | .children(self.profile_card.clone()) |
| 682 | .child(crate::frame_log::probe("last")) |
| 683 | } |
| 684 | } |