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