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