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