| 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::actions::{NewChat, OpenSwitcher, ReplyToHovered, ToggleCallMute}; |
| 9 | use super::activity_panel::{ActivityPanel, ActivityPanelEvent}; |
| 10 | use super::calendar_view::CalendarView; |
| 11 | use super::call_pop_out::zoom_listener; |
| 12 | use super::calls_page::CallsPage; |
| 13 | use super::chat_pop_out; |
| 14 | use super::connection_banner::render_connection_banner; |
| 15 | use super::conversation::ConversationView; |
| 16 | use super::dialog_overlay::render_task_dialog; |
| 17 | use super::forward_dialog::{ForwardDialog, ForwardDialogEvent}; |
| 18 | use super::image_viewer::{ImageViewer, ImageViewerEvent}; |
| 19 | use super::manage_team_page::ManageTeamPage; |
| 20 | use super::notice_toast::NoticeToasts; |
| 21 | use super::profile_card::{ProfileCard, ProfileCardEvent}; |
| 22 | use super::quick_view_pane::{QuickViewEvent, QuickViewPane}; |
| 23 | use super::rail::RailView; |
| 24 | use super::shortcuts::{ |
| 25 | ClearChatFilters, DeclineCall, FilterMeetingChats, FilterMutedChats, FilterNonMeetingChats, |
| 26 | FilterUnreadChats, FindInChat, HangUpCall, JoinMeetingFromToast, JumpToLastReadOrNewest, |
| 27 | NextConversation, OpenActivity, OpenAgents, OpenCalendar, OpenCallsTab, OpenChannelsTab, |
| 28 | OpenChatFilter, OpenChatsTab, OpenLobbyList, OpenSaved, OpenSettings, PopOutSelectedChat, |
| 29 | PreviousConversation, PushToTalk, Scope, ShowShortcuts, StartAudioCall, StartVideoCall, |
| 30 | ToggleCallCamera, ToggleCallHand, ToggleCallShare, ZoomIn, ZoomOut, ZoomReset, ZoomShareIn, |
| 31 | ZoomShareOut, ZoomShareReset, |
| 32 | }; |
| 33 | use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent}; |
| 34 | use super::sidebar::{SidebarEvent, SidebarTab, SidebarView}; |
| 35 | use super::splash::{self, Phase, Splash, StartupFacts}; |
| 36 | use super::status_menu::{own_status_button, settings_more_button}; |
| 37 | use super::status_message_dialog::{StatusMessageDialog, StatusMessageDialogEvent}; |
| 38 | use super::switcher::{Switcher, SwitcherEvent, candidates_from}; |
| 39 | use super::title_bar::{mode_label, render_title_bar, update_button}; |
| 40 | use super::window_zoom::{WindowZoom, change_zoom}; |
| 41 | use crate::activity::ActivityCenter; |
| 42 | use crate::agents::{AgentRunsEvent, StartDialog, StartDialogEvent, StartRequest}; |
| 43 | use crate::app_state::{AppEvent, AppState, QuickView, Selection, selection_for}; |
| 44 | use crate::call::{CallMedia, CallWindows, ZoomStep}; |
| 45 | use crate::chat_filter::ChatFilterPill; |
| 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 | use app_ui_kit::layout::{ISLAND_GAP, SIDEBAR_WIDTH}; |
| 55 | use app_ui_kit::render::hooks::RenderHooks; |
| 56 | use gpui_kit::prelude::FluentBuilder as _; |
| 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 struct UserInputHandle(pub Arc<UserInput>); |
| 86 | |
| 87 | impl Global for UserInputHandle {} |
| 88 | |
| 89 | pub fn install_globals(state: &Entity<AppState>, user_input: Arc<UserInput>, cx: &mut App) { |
| 90 | cx.set_global(crate::app_state::AppHandle(state.clone())); |
| 91 | cx.set_global(UserInputHandle(user_input)); |
| 92 | cx.set_global(RenderHooks { |
| 93 | open_profile_link: super::profile_card::open_profile_link, |
| 94 | jump_to_quoted, |
| 95 | inline_image, |
| 96 | open_link, |
| 97 | }); |
| 98 | } |
| 99 | |
| 100 | fn open_link(url: &str, cx: &mut App) { |
| 101 | if let Some(handle) = cx.try_global::<crate::app_state::AppHandle>() { |
| 102 | let text = opening_link_text(url); |
| 103 | handle |
| 104 | .0 |
| 105 | .clone() |
| 106 | .update(cx, |state, cx| state.raise_notice(text, None, cx)); |
| 107 | } |
| 108 | cx.open_url(url); |
| 109 | } |
| 110 | |
| 111 | fn opening_link_text(url: &str) -> String { |
| 112 | let host = url |
| 113 | .split_once("://") |
| 114 | .map_or(url, |(_, rest)| rest) |
| 115 | .split(['/', '?', '#']) |
| 116 | .next() |
| 117 | .unwrap_or_default(); |
| 118 | if host.is_empty() { |
| 119 | "Opening link...".to_owned() |
| 120 | } else { |
| 121 | format!("Opening {host}...") |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | fn inline_image(url: &str, cx: &App) -> Option<std::path::PathBuf> { |
| 126 | let handle = cx.try_global::<crate::app_state::AppHandle>()?; |
| 127 | let entry = handle.0.read(cx).directory.image(url)?; |
| 128 | Some(entry.path.clone()) |
| 129 | } |
| 130 | |
| 131 | fn jump_to_quoted(message_id: String, cx: &mut App) { |
| 132 | let Some(handle) = cx.try_global::<crate::app_state::AppHandle>() else { |
| 133 | return; |
| 134 | }; |
| 135 | handle.0.clone().update(cx, |state, cx| { |
| 136 | if let Some(selection) = state.selection.clone() { |
| 137 | state.jump_to_message(selection, message_id, cx); |
| 138 | } |
| 139 | }); |
| 140 | } |
| 141 | |
| 142 | #[cfg(windows)] |
| 143 | fn watch_releases(running_tag: &'static str, cx: &mut App) { |
| 144 | use app_base::release_feed; |
| 145 | cx.spawn(async move |cx| { |
| 146 | cx.background_executor() |
| 147 | .timer(release_feed::FIRST_CHECK_DELAY) |
| 148 | .await; |
| 149 | loop { |
| 150 | let Some(paths) = updater::current_paths() else { |
| 151 | return; |
| 152 | }; |
| 153 | let fetch = cx.update(|cx| release_feed::fetch_update(running_tag, paths, cx)); |
| 154 | match fetch.await { |
| 155 | Ok(Some(tag)) => log::info!("release {tag} downloaded for the next restart"), |
| 156 | Ok(None) => {} |
| 157 | Err(error) => log::warn!("release check failed: {error}"), |
| 158 | } |
| 159 | cx.background_executor() |
| 160 | .timer(release_feed::CHECK_INTERVAL) |
| 161 | .await; |
| 162 | } |
| 163 | }) |
| 164 | .detach(); |
| 165 | } |
| 166 | |
| 167 | const DEMO_UPDATE_VARIABLE: &str = "TEAMS_DEMO_UPDATE"; |
| 168 | |
| 169 | /// Entities created with the first main window that a reopened one takes over. |
| 170 | #[derive(Clone)] |
| 171 | struct KeptParts { |
| 172 | activity: Entity<ActivityCenter>, |
| 173 | notifications: Entity<NotificationCenter>, |
| 174 | call_windows: Entity<CallWindows>, |
| 175 | } |
| 176 | |
| 177 | impl Global for KeptParts {} |
| 178 | |
| 179 | /// Re-applies the app icon to the tray and window, e.g. after the Teams icon arrived. |
| 180 | pub fn refresh_app_icon(cx: &mut App) { |
| 181 | if let Some(kept) = cx.try_global::<KeptParts>().cloned() { |
| 182 | kept.notifications |
| 183 | .update(cx, |notifications, cx| notifications.reapply_app_icon(cx)); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | pub struct AppShell { |
| 188 | state: Entity<AppState>, |
| 189 | rail: Entity<RailView>, |
| 190 | sidebar: Entity<SidebarView>, |
| 191 | calendar: Entity<CalendarView>, |
| 192 | quick_pane: Entity<QuickViewPane>, |
| 193 | manage_team_page: Entity<ManageTeamPage>, |
| 194 | calls_page: Entity<CallsPage>, |
| 195 | shown_quick_view: Option<QuickView>, |
| 196 | conversation: Entity<ConversationView>, |
| 197 | switcher: Option<Entity<Switcher>>, |
| 198 | notifications: Entity<NotificationCenter>, |
| 199 | _call_windows: Entity<CallWindows>, |
| 200 | forward_dialog: Option<Entity<ForwardDialog>>, |
| 201 | image_viewer: Option<Entity<ImageViewer>>, |
| 202 | status_dialog: Option<Entity<StatusMessageDialog>>, |
| 203 | shortcuts_dialog: Option<Entity<ShortcutsDialog>>, |
| 204 | agent_dialog: Option<Entity<StartDialog>>, |
| 205 | settings_dialog: Option<Entity<SettingsDialog>>, |
| 206 | profile_card: Option<Entity<ProfileCard>>, |
| 207 | focus_handle: FocusHandle, |
| 208 | open_target: Option<OpenTarget>, |
| 209 | update: UpdateStatus, |
| 210 | splash: Splash, |
| 211 | toasts: NoticeToasts, |
| 212 | user_input: Arc<UserInput>, |
| 213 | _subscription: Subscription, |
| 214 | _panel_subscriptions: [Subscription; 2], |
| 215 | _sidebar_subscription: Subscription, |
| 216 | _agents_subscription: Option<Subscription>, |
| 217 | _agent_subscription: Option<Subscription>, |
| 218 | _escape_observation: Subscription, |
| 219 | _activation_observation: Subscription, |
| 220 | _appearance_observation: Subscription, |
| 221 | } |
| 222 | |
| 223 | impl AppShell { |
| 224 | #[cfg(test)] |
| 225 | pub(crate) fn set_update_status(&mut self, update: UpdateStatus, cx: &mut Context<Self>) { |
| 226 | self.update = update; |
| 227 | cx.notify(); |
| 228 | } |
| 229 | |
| 230 | fn focus_opened_quick_view(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 231 | let quick_view = self.state.read(cx).quick_view; |
| 232 | if std::mem::replace(&mut self.shown_quick_view, quick_view) != quick_view |
| 233 | && quick_view.is_some() |
| 234 | { |
| 235 | self.restore_focus(window, cx); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | fn leave_calendar_on_selection(&mut self, cx: &mut Context<Self>) { |
| 240 | if self.sidebar.read(cx).tab() != SidebarTab::Calendar { |
| 241 | return; |
| 242 | } |
| 243 | let selection = self.state.read(cx).selection.clone(); |
| 244 | let sidebar = self.sidebar.clone(); |
| 245 | cx.defer(move |cx| { |
| 246 | sidebar.update(cx, |sidebar, cx| match selection { |
| 247 | Some(Selection::Channel(_)) => sidebar.show_channels(cx), |
| 248 | Some(Selection::Chat(_)) => sidebar.show_chats(cx), |
| 249 | None => {} |
| 250 | }) |
| 251 | }); |
| 252 | } |
| 253 | |
| 254 | pub fn new( |
| 255 | state: Entity<AppState>, |
| 256 | open_target: Option<OpenTarget>, |
| 257 | startup: Startup, |
| 258 | window: &mut Window, |
| 259 | cx: &mut Context<Self>, |
| 260 | ) -> Self { |
| 261 | let kept = cx.try_global::<KeptParts>().cloned(); |
| 262 | let reopened = kept.is_some(); |
| 263 | let activity = match &kept { |
| 264 | Some(kept) => { |
| 265 | kept.activity |
| 266 | .update(cx, |activity, _| activity.attach_main_window(window)); |
| 267 | kept.activity.clone() |
| 268 | } |
| 269 | None => { |
| 270 | let call_media = cx.new(|_| CallMedia); |
| 271 | state.update(cx, |state, _| state.call_media = Some(call_media.clone())); |
| 272 | cx.new(|cx| ActivityCenter::new(state.clone(), window, cx)) |
| 273 | } |
| 274 | }; |
| 275 | let activity_panel = cx.new(|cx| ActivityPanel::new(state.clone(), activity.clone(), cx)); |
| 276 | let quick_pane = cx.new(|cx| QuickViewPane::new(state.clone(), activity.clone(), cx)); |
| 277 | let manage_team_page = cx.new(|cx| ManageTeamPage::new(state.clone(), window, cx)); |
| 278 | let calls_page = cx.new(|cx| CallsPage::new(state.clone(), window, cx)); |
| 279 | let agents_panel = crate::agents::runs_handle(cx) |
| 280 | .map(|runs| cx.new(|cx| crate::agents::AgentsPanel::new(runs, cx))); |
| 281 | let agents_subscription = agents_panel.as_ref().map(|panel| { |
| 282 | cx.subscribe( |
| 283 | panel, |
| 284 | |this, _, event: &crate::agents::AgentsPanelEvent, cx| { |
| 285 | let crate::agents::AgentsPanelEvent::Open { |
| 286 | conversation_id, |
| 287 | message_id, |
| 288 | } = event; |
| 289 | this.open_message(conversation_id, message_id, cx); |
| 290 | }, |
| 291 | ) |
| 292 | }); |
| 293 | let panel_subscriptions = [ |
| 294 | cx.subscribe( |
| 295 | &activity_panel, |
| 296 | |this, _, event: &ActivityPanelEvent, cx| match event { |
| 297 | ActivityPanelEvent::OpenSettings => this.state.update(cx, |state, cx| { |
| 298 | state.open_settings(SettingsSection::Notifications, cx) |
| 299 | }), |
| 300 | ActivityPanelEvent::Open { |
| 301 | conversation_id, |
| 302 | message_id, |
| 303 | link, |
| 304 | } => { |
| 305 | if !this.open_message(conversation_id, message_id, cx) |
| 306 | && let Some(link) = link |
| 307 | { |
| 308 | cx.open_url(link); |
| 309 | } |
| 310 | } |
| 311 | }, |
| 312 | ), |
| 313 | cx.subscribe(&quick_pane, |this, _, event: &QuickViewEvent, cx| { |
| 314 | let QuickViewEvent::Open { |
| 315 | conversation_id, |
| 316 | message_id, |
| 317 | } = event; |
| 318 | this.state |
| 319 | .update(cx, |state, cx| state.close_quick_view(cx)); |
| 320 | this.open_message( |
| 321 | conversation_id, |
| 322 | message_id.as_deref().unwrap_or_default(), |
| 323 | cx, |
| 324 | ); |
| 325 | }), |
| 326 | ]; |
| 327 | let agent_subscription = crate::agents::runs_handle(cx).map(|runs| { |
| 328 | cx.subscribe_in( |
| 329 | &runs, |
| 330 | window, |
| 331 | |this, _, event: &AgentRunsEvent, window, cx| match event { |
| 332 | AgentRunsEvent::StartRequested(request) => { |
| 333 | this.open_agent_dialog(request.clone(), window, cx) |
| 334 | } |
| 335 | AgentRunsEvent::OpenSettings => { |
| 336 | this.open_settings(SettingsSection::Agents, window, cx) |
| 337 | } |
| 338 | AgentRunsEvent::Finished(_) => {} |
| 339 | }, |
| 340 | ) |
| 341 | }); |
| 342 | let sidebar = |
| 343 | cx.new(|cx| SidebarView::new(state.clone(), activity_panel, agents_panel, cx)); |
| 344 | let sidebar_subscription = cx.subscribe_in( |
| 345 | &sidebar, |
| 346 | window, |
| 347 | |this, _, event: &SidebarEvent, window, cx| match event { |
| 348 | SidebarEvent::RestoreFocus => this.restore_focus(window, cx), |
| 349 | SidebarEvent::TabChanged => { |
| 350 | if this.sidebar.read(cx).tab() == SidebarTab::Calendar { |
| 351 | this.restore_focus(window, cx); |
| 352 | } |
| 353 | cx.notify(); |
| 354 | } |
| 355 | SidebarEvent::NewChannelPost => this.conversation.update(cx, |conversation, cx| { |
| 356 | conversation.start_channel_post(window, cx) |
| 357 | }), |
| 358 | }, |
| 359 | ); |
| 360 | let calendar = cx.new(|cx| CalendarView::new(state.clone(), cx)); |
| 361 | let rail = cx.new(|cx| RailView::new(state.clone(), activity.clone(), sidebar.clone(), cx)); |
| 362 | let conversation = cx.new(|cx| ConversationView::new(state.clone(), window, cx)); |
| 363 | let subscription = |
| 364 | cx.subscribe_in(&state, window, |this, _, event: &AppEvent, window, cx| { |
| 365 | if matches!(event, AppEvent::Sidebar | AppEvent::Status) { |
| 366 | this.apply_open_target(cx); |
| 367 | } |
| 368 | if matches!(event, AppEvent::Sidebar) { |
| 369 | this.focus_opened_quick_view(window, cx); |
| 370 | } |
| 371 | if matches!(event, AppEvent::Selection) { |
| 372 | this.leave_calendar_on_selection(cx); |
| 373 | } |
| 374 | if matches!(event, AppEvent::Forward) { |
| 375 | this.open_forward_dialog(window, cx); |
| 376 | } |
| 377 | if matches!(event, AppEvent::ImageViewer) { |
| 378 | this.open_image_viewer(window, cx); |
| 379 | } |
| 380 | if matches!(event, AppEvent::StatusMessage) { |
| 381 | this.open_status_dialog(window, cx); |
| 382 | } |
| 383 | if let AppEvent::Settings(section) = event { |
| 384 | this.open_settings(*section, window, cx); |
| 385 | } |
| 386 | if matches!(event, AppEvent::Profile) { |
| 387 | this.open_profile_card(window, cx); |
| 388 | } |
| 389 | cx.notify(); |
| 390 | }); |
| 391 | let focus_handle = cx.focus_handle(); |
| 392 | window.focus(&focus_handle, cx); |
| 393 | // The tray, notifications and calls outlive a main window closed into the tray. |
| 394 | let (notifications, call_windows) = match kept { |
| 395 | Some(kept) => { |
| 396 | kept.notifications.update(cx, |notifications, _| { |
| 397 | notifications.attach_main_window(window) |
| 398 | }); |
| 399 | kept.call_windows.update(cx, |call_windows, _| { |
| 400 | call_windows.attach_main_window(window) |
| 401 | }); |
| 402 | (kept.notifications, kept.call_windows) |
| 403 | } |
| 404 | None => { |
| 405 | let notifications = cx |
| 406 | .new(|cx| NotificationCenter::new(state.clone(), activity.clone(), window, cx)); |
| 407 | let call_windows = cx.new(|cx| CallWindows::new(state.clone(), window, cx)); |
| 408 | cx.set_global(KeptParts { |
| 409 | activity: activity.clone(), |
| 410 | notifications: notifications.clone(), |
| 411 | call_windows: call_windows.clone(), |
| 412 | }); |
| 413 | (notifications, call_windows) |
| 414 | } |
| 415 | }; |
| 416 | let user_input = cx.global::<UserInputHandle>().0.clone(); |
| 417 | let escape_observation = cx.observe_keystrokes(|this, event, _, cx| { |
| 418 | this.user_input.touch(); |
| 419 | if event.keystroke.key == "escape" && event.action.is_none() { |
| 420 | this.state |
| 421 | .update(cx, |state, cx| state.escape_call_fullscreen(cx)); |
| 422 | } |
| 423 | }); |
| 424 | let appearance_observation = cx.observe_window_appearance(window, |_, window, cx| { |
| 425 | crate::active_appearance::system_appearance_changed(window.appearance(), cx); |
| 426 | }); |
| 427 | let activation_observation = cx.observe_window_activation(window, |this, window, cx| { |
| 428 | if window.is_window_active() { |
| 429 | this.state |
| 430 | .update(cx, |state, cx| state.refresh_calendar(cx)); |
| 431 | } else { |
| 432 | this.state |
| 433 | .update(cx, |state, cx| state.release_push_to_talk(cx)); |
| 434 | } |
| 435 | }); |
| 436 | let closing = notifications.clone(); |
| 437 | window.on_window_should_close(cx, move |_, cx| { |
| 438 | !closing.update(cx, |notifications, cx| notifications.intercept_close(cx)) |
| 439 | }); |
| 440 | let mut shell = AppShell { |
| 441 | state, |
| 442 | rail, |
| 443 | sidebar, |
| 444 | calendar, |
| 445 | quick_pane, |
| 446 | manage_team_page, |
| 447 | calls_page, |
| 448 | shown_quick_view: None, |
| 449 | conversation, |
| 450 | switcher: None, |
| 451 | notifications, |
| 452 | _call_windows: call_windows, |
| 453 | forward_dialog: None, |
| 454 | image_viewer: None, |
| 455 | status_dialog: None, |
| 456 | shortcuts_dialog: None, |
| 457 | agent_dialog: None, |
| 458 | settings_dialog: None, |
| 459 | profile_card: None, |
| 460 | focus_handle, |
| 461 | open_target, |
| 462 | update: UpdateStatus::UpToDate, |
| 463 | splash: Splash::default(), |
| 464 | toasts: NoticeToasts::default(), |
| 465 | user_input, |
| 466 | _subscription: subscription, |
| 467 | _panel_subscriptions: panel_subscriptions, |
| 468 | _sidebar_subscription: sidebar_subscription, |
| 469 | _agents_subscription: agents_subscription, |
| 470 | _agent_subscription: agent_subscription, |
| 471 | _escape_observation: escape_observation, |
| 472 | _activation_observation: activation_observation, |
| 473 | _appearance_observation: appearance_observation, |
| 474 | }; |
| 475 | shell.apply_open_target(cx); |
| 476 | shell |
| 477 | .state |
| 478 | .update(cx, |state, cx| state.refresh_connection_banner(cx)); |
| 479 | if shell.state.read(cx).mode.demo && std::env::var_os(DEMO_UPDATE_VARIABLE).is_some() { |
| 480 | shell.update = UpdateStatus::Ready; |
| 481 | } |
| 482 | let Startup { |
| 483 | switcher_query, |
| 484 | composer_text, |
| 485 | reply_to_last, |
| 486 | launched_by_autostart, |
| 487 | } = startup; |
| 488 | if !reopened |
| 489 | && shell |
| 490 | .notifications |
| 491 | .read(cx) |
| 492 | .startup() |
| 493 | .starts_hidden(launched_by_autostart) |
| 494 | { |
| 495 | cx.defer_in(window, |this, window, cx| { |
| 496 | this.notifications.update(cx, |notifications, cx| { |
| 497 | notifications.start_in_background(window, cx) |
| 498 | }) |
| 499 | }); |
| 500 | } |
| 501 | if let Some(query) = switcher_query { |
| 502 | shell.toggle_switcher(&query, window, cx); |
| 503 | } |
| 504 | if composer_text.is_some() || reply_to_last { |
| 505 | cx.defer_in(window, move |this, window, cx| { |
| 506 | this.conversation.update(cx, |conversation, cx| { |
| 507 | if reply_to_last { |
| 508 | conversation.reply_to_latest_from_others(window, cx); |
| 509 | } |
| 510 | if let Some(text) = composer_text { |
| 511 | conversation.set_composer_text(&text, window, cx); |
| 512 | } |
| 513 | }); |
| 514 | }); |
| 515 | } |
| 516 | #[cfg(any(windows, target_os = "linux"))] |
| 517 | cx.spawn_in(window, async move |this, cx| { |
| 518 | loop { |
| 519 | cx.background_executor().timer(updater::POLL_INTERVAL).await; |
| 520 | if this |
| 521 | .update_in(cx, |this, window, cx| this.poll_update(window, cx)) |
| 522 | .is_err() |
| 523 | { |
| 524 | break; |
| 525 | } |
| 526 | } |
| 527 | }) |
| 528 | .detach(); |
| 529 | // Linux asks before downloading (`linux_update`); Windows downloads quietly. |
| 530 | #[cfg(windows)] |
| 531 | if let Some(running_tag) = app_base::version::release_tag() { |
| 532 | watch_releases(running_tag, cx); |
| 533 | } |
| 534 | shell |
| 535 | } |
| 536 | |
| 537 | #[cfg_attr(not(any(windows, target_os = "linux")), allow(dead_code))] |
| 538 | fn poll_update(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 539 | if matches!( |
| 540 | self.update, |
| 541 | UpdateStatus::Failed(_) | UpdateStatus::Installing |
| 542 | ) { |
| 543 | return; |
| 544 | } |
| 545 | let Some(paths) = updater::current_paths() else { |
| 546 | return; |
| 547 | }; |
| 548 | if self.update == UpdateStatus::UpToDate { |
| 549 | if !updater::check(&paths) { |
| 550 | return; |
| 551 | } |
| 552 | self.update = UpdateStatus::Ready; |
| 553 | let update_exe = paths.update_exe.clone(); |
| 554 | cx.background_spawn(async move { updater::prescan(&update_exe) }) |
| 555 | .detach(); |
| 556 | } |
| 557 | let conversation = self.conversation.read(cx); |
| 558 | let idle = updater::is_idle(IdleInputs { |
| 559 | window_active: window.is_window_active(), |
| 560 | composer_empty: conversation.composer_is_empty(cx), |
| 561 | send_in_flight: conversation.send_in_flight(), |
| 562 | }); |
| 563 | // On Linux only the user restarts: the update dialog or the title bar button. |
| 564 | if idle && cfg!(not(target_os = "linux")) { |
| 565 | self.restart_into_update(cx); |
| 566 | } |
| 567 | cx.notify(); |
| 568 | } |
| 569 | |
| 570 | fn restart_into_update(&mut self, cx: &mut Context<Self>) { |
| 571 | if self.update == UpdateStatus::Installing { |
| 572 | return; |
| 573 | } |
| 574 | let Some(paths) = updater::current_paths() else { |
| 575 | return; |
| 576 | }; |
| 577 | self.update = UpdateStatus::Installing; |
| 578 | cx.notify(); |
| 579 | cx.spawn(async move |this, cx| { |
| 580 | let result = cx |
| 581 | .background_spawn(async move { updater::install_and_relaunch(&paths) }) |
| 582 | .await; |
| 583 | let _ = this.update(cx, |this, cx| { |
| 584 | match result { |
| 585 | Ok(()) => cx.quit(), |
| 586 | Err(message) => this.update = UpdateStatus::Failed(message), |
| 587 | } |
| 588 | cx.notify(); |
| 589 | }); |
| 590 | }) |
| 591 | .detach(); |
| 592 | } |
| 593 | |
| 594 | fn apply_open_target(&mut self, cx: &mut Context<Self>) { |
| 595 | let Some(target) = self.open_target else { |
| 596 | return; |
| 597 | }; |
| 598 | let sidebar = &self.state.read(cx).sidebar; |
| 599 | let selection = match target { |
| 600 | OpenTarget::Chat(index) => sidebar |
| 601 | .chats |
| 602 | .get(index) |
| 603 | .map(|chat| Selection::Chat(chat.id.clone())), |
| 604 | OpenTarget::Channel(index) => sidebar |
| 605 | .teams |
| 606 | .iter() |
| 607 | .flat_map(|team| team.channels.iter()) |
| 608 | .nth(index) |
| 609 | .map(|channel| Selection::Channel(channel.id.clone())), |
| 610 | }; |
| 611 | if let Some(selection) = selection { |
| 612 | self.open_target = None; |
| 613 | self.state |
| 614 | .update(cx, |state, cx| state.select(selection, cx)); |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | fn toggle_switcher( |
| 619 | &mut self, |
| 620 | initial_query: &str, |
| 621 | window: &mut Window, |
| 622 | cx: &mut Context<Self>, |
| 623 | ) { |
| 624 | if self.switcher.take().is_some() { |
| 625 | self.restore_focus(window, cx); |
| 626 | cx.notify(); |
| 627 | return; |
| 628 | } |
| 629 | self.close_image_viewer(window, cx); |
| 630 | let candidates = candidates_from(self.state.read(cx)); |
| 631 | let app = self.state.clone(); |
| 632 | let switcher = cx.new(|cx| Switcher::new(app, candidates, initial_query, window, cx)); |
| 633 | cx.subscribe_in( |
| 634 | &switcher, |
| 635 | window, |
| 636 | |this, _, event: &SwitcherEvent, window, cx| { |
| 637 | match event { |
| 638 | SwitcherEvent::Pick(selection) => { |
| 639 | let selection = selection.clone(); |
| 640 | this.state |
| 641 | .update(cx, |state, cx| state.select(selection, cx)); |
| 642 | } |
| 643 | SwitcherEvent::PickMessage { |
| 644 | selection, |
| 645 | message_id, |
| 646 | } => { |
| 647 | let (selection, message_id) = (selection.clone(), message_id.clone()); |
| 648 | this.state.update(cx, |state, cx| { |
| 649 | state.jump_to_message(selection, message_id, cx) |
| 650 | }); |
| 651 | } |
| 652 | SwitcherEvent::PickPerson { user_id } => { |
| 653 | let user_id = user_id.clone(); |
| 654 | this.state |
| 655 | .update(cx, |state, cx| state.open_chat_with(&user_id, cx)); |
| 656 | } |
| 657 | SwitcherEvent::Close => {} |
| 658 | } |
| 659 | this.switcher = None; |
| 660 | this.restore_focus(window, cx); |
| 661 | cx.notify(); |
| 662 | }, |
| 663 | ) |
| 664 | .detach(); |
| 665 | self.switcher = Some(switcher); |
| 666 | cx.notify(); |
| 667 | } |
| 668 | |
| 669 | fn open_message( |
| 670 | &mut self, |
| 671 | conversation_id: &str, |
| 672 | message_id: &str, |
| 673 | cx: &mut Context<Self>, |
| 674 | ) -> bool { |
| 675 | let Some(selection) = selection_for(&self.state.read(cx).sidebar, conversation_id) else { |
| 676 | return false; |
| 677 | }; |
| 678 | let message_id = message_id.to_owned(); |
| 679 | self.state.update(cx, |state, cx| { |
| 680 | if message_id.is_empty() { |
| 681 | state.select(selection, cx) |
| 682 | } else { |
| 683 | state.jump_to_message(selection, message_id, cx) |
| 684 | } |
| 685 | }); |
| 686 | true |
| 687 | } |
| 688 | |
| 689 | fn open_status_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 690 | if !self |
| 691 | .state |
| 692 | .update(cx, |state, _| state.take_status_message_request()) |
| 693 | { |
| 694 | return; |
| 695 | } |
| 696 | self.close_image_viewer(window, cx); |
| 697 | self.switcher = None; |
| 698 | let app = self.state.clone(); |
| 699 | let dialog = cx.new(|cx| StatusMessageDialog::new(app, window, cx)); |
| 700 | cx.subscribe_in( |
| 701 | &dialog, |
| 702 | window, |
| 703 | |this, _, _: &StatusMessageDialogEvent, window, cx| { |
| 704 | this.status_dialog = None; |
| 705 | this.restore_focus(window, cx); |
| 706 | cx.notify(); |
| 707 | }, |
| 708 | ) |
| 709 | .detach(); |
| 710 | self.status_dialog = Some(dialog); |
| 711 | cx.notify(); |
| 712 | } |
| 713 | |
| 714 | fn open_agent_dialog( |
| 715 | &mut self, |
| 716 | request: StartRequest, |
| 717 | window: &mut Window, |
| 718 | cx: &mut Context<Self>, |
| 719 | ) { |
| 720 | let Some(runs) = crate::agents::runs_handle(cx) else { |
| 721 | return; |
| 722 | }; |
| 723 | let settings = runs.read(cx).settings(); |
| 724 | let Some(action) = settings |
| 725 | .actions |
| 726 | .iter() |
| 727 | .find(|action| action.id == request.action_id) |
| 728 | .cloned() |
| 729 | else { |
| 730 | return; |
| 731 | }; |
| 732 | let agent_name = settings |
| 733 | .agents |
| 734 | .iter() |
| 735 | .find(|agent| agent.id == action.agent_id) |
| 736 | .map(|agent| agent.name.clone()) |
| 737 | .unwrap_or_default(); |
| 738 | self.switcher = None; |
| 739 | let app = self.state.clone(); |
| 740 | let dialog = cx.new(|cx| StartDialog::new(app, request, action, &agent_name, window, cx)); |
| 741 | cx.subscribe_in( |
| 742 | &dialog, |
| 743 | window, |
| 744 | |this, _, _: &StartDialogEvent, window, cx| { |
| 745 | this.agent_dialog = None; |
| 746 | window.focus(&this.focus_handle, cx); |
| 747 | cx.notify(); |
| 748 | }, |
| 749 | ) |
| 750 | .detach(); |
| 751 | self.agent_dialog = Some(dialog); |
| 752 | cx.notify(); |
| 753 | } |
| 754 | |
| 755 | fn open_settings( |
| 756 | &mut self, |
| 757 | section: SettingsSection, |
| 758 | window: &mut Window, |
| 759 | cx: &mut Context<Self>, |
| 760 | ) { |
| 761 | if let Some(dialog) = &self.settings_dialog { |
| 762 | dialog.update(cx, |dialog, cx| dialog.show(section, window, cx)); |
| 763 | return; |
| 764 | } |
| 765 | self.close_image_viewer(window, cx); |
| 766 | self.switcher = None; |
| 767 | let (app, center) = (self.state.clone(), self.notifications.clone()); |
| 768 | let dialog = cx.new(|cx| SettingsDialog::new(app, center, section, window, cx)); |
| 769 | cx.subscribe_in( |
| 770 | &dialog, |
| 771 | window, |
| 772 | |this, _, _: &SettingsDialogEvent, window, cx| { |
| 773 | this.settings_dialog = None; |
| 774 | this.restore_focus(window, cx); |
| 775 | cx.notify(); |
| 776 | }, |
| 777 | ) |
| 778 | .detach(); |
| 779 | self.settings_dialog = Some(dialog); |
| 780 | cx.notify(); |
| 781 | } |
| 782 | |
| 783 | fn toggle_shortcuts_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 784 | if self.shortcuts_dialog.take().is_some() { |
| 785 | self.restore_focus(window, cx); |
| 786 | cx.notify(); |
| 787 | return; |
| 788 | } |
| 789 | self.close_image_viewer(window, cx); |
| 790 | self.switcher = None; |
| 791 | let dialog = cx.new(|cx| ShortcutsDialog::new(window, cx)); |
| 792 | cx.subscribe_in( |
| 793 | &dialog, |
| 794 | window, |
| 795 | |this, _, _: &ShortcutsDialogEvent, window, cx| { |
| 796 | this.shortcuts_dialog = None; |
| 797 | this.restore_focus(window, cx); |
| 798 | cx.notify(); |
| 799 | }, |
| 800 | ) |
| 801 | .detach(); |
| 802 | self.shortcuts_dialog = Some(dialog); |
| 803 | cx.notify(); |
| 804 | } |
| 805 | |
| 806 | fn open_profile_card(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 807 | let Some(request) = self |
| 808 | .state |
| 809 | .update(cx, |state, _| state.take_profile_request()) |
| 810 | else { |
| 811 | return; |
| 812 | }; |
| 813 | self.close_image_viewer(window, cx); |
| 814 | if let Some(card) = &self.profile_card { |
| 815 | card.update(cx, |card, cx| { |
| 816 | card.move_to(request.user_id, request.anchor, cx) |
| 817 | }); |
| 818 | return; |
| 819 | } |
| 820 | let app = self.state.clone(); |
| 821 | let card = cx.new(|cx| ProfileCard::new(app, request.user_id, request.anchor, window, cx)); |
| 822 | cx.subscribe_in( |
| 823 | &card, |
| 824 | window, |
| 825 | |this, _, _: &ProfileCardEvent, window, cx| { |
| 826 | this.profile_card = None; |
| 827 | this.restore_focus(window, cx); |
| 828 | cx.notify(); |
| 829 | }, |
| 830 | ) |
| 831 | .detach(); |
| 832 | self.profile_card = Some(card); |
| 833 | cx.notify(); |
| 834 | } |
| 835 | |
| 836 | fn open_image_viewer(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 837 | let Some(request) = self |
| 838 | .state |
| 839 | .update(cx, |state, _| state.take_image_viewer_request()) |
| 840 | else { |
| 841 | return; |
| 842 | }; |
| 843 | self.switcher = None; |
| 844 | let app = self.state.clone(); |
| 845 | let viewer = cx.new(|cx| ImageViewer::new(app, request, window, cx)); |
| 846 | cx.subscribe_in( |
| 847 | &viewer, |
| 848 | window, |
| 849 | |this, _, _: &ImageViewerEvent, window, cx| { |
| 850 | this.image_viewer = None; |
| 851 | window.focus(&this.focus_handle, cx); |
| 852 | cx.notify(); |
| 853 | }, |
| 854 | ) |
| 855 | .detach(); |
| 856 | self.image_viewer = Some(viewer); |
| 857 | cx.notify(); |
| 858 | } |
| 859 | |
| 860 | fn start_call_in_open_chat(&mut self, with_video: bool, cx: &mut Context<Self>) { |
| 861 | self.state.update(cx, |state, cx| { |
| 862 | if let Some(Selection::Chat(chat_id)) = state.selection.clone() { |
| 863 | if with_video { |
| 864 | state.start_chat_video_call(&chat_id, cx); |
| 865 | } else { |
| 866 | state.start_chat_call(&chat_id, cx); |
| 867 | } |
| 868 | } |
| 869 | }); |
| 870 | } |
| 871 | |
| 872 | fn close_image_viewer(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 873 | if self.image_viewer.take().is_some() { |
| 874 | window.focus(&self.focus_handle, cx); |
| 875 | cx.notify(); |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | fn restore_focus(&self, window: &mut Window, cx: &mut Context<Self>) { |
| 880 | match &self.image_viewer { |
| 881 | Some(viewer) => { |
| 882 | let handle = viewer.read(cx).focus_handle(); |
| 883 | window.focus(&handle, cx) |
| 884 | } |
| 885 | None => window.focus(&self.focus_handle, cx), |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | fn open_forward_dialog(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 890 | let Some(source) = self |
| 891 | .state |
| 892 | .update(cx, |state, _| state.take_forward_request()) |
| 893 | else { |
| 894 | return; |
| 895 | }; |
| 896 | self.switcher = None; |
| 897 | let candidates = candidates_from(self.state.read(cx)); |
| 898 | let app = self.state.clone(); |
| 899 | let dialog = cx.new(|cx| ForwardDialog::new(app, source, candidates, window, cx)); |
| 900 | cx.subscribe_in( |
| 901 | &dialog, |
| 902 | window, |
| 903 | |this, _, event: &ForwardDialogEvent, window, cx| { |
| 904 | this.forward_dialog = None; |
| 905 | this.restore_focus(window, cx); |
| 906 | if let ForwardDialogEvent::Sent { target, title } = event { |
| 907 | let target = target.clone(); |
| 908 | let open = NoticeAction::new("Open", move |state, cx| { |
| 909 | state.select(target.clone(), cx) |
| 910 | }); |
| 911 | this.state.update(cx, |state, cx| { |
| 912 | state.cancel_forward_selection(cx); |
| 913 | state.raise_notice(format!("Forwarded to {title}"), Some(open), cx) |
| 914 | }); |
| 915 | } |
| 916 | cx.notify(); |
| 917 | }, |
| 918 | ) |
| 919 | .detach(); |
| 920 | self.forward_dialog = Some(dialog); |
| 921 | cx.notify(); |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | impl AppShell { |
| 926 | fn render_splash(&mut self, cx: &mut Context<Self>) -> Option<AnyElement> { |
| 927 | let phase = if self.splash.is_up() { |
| 928 | let opening = self.conversation.read(cx).opening_title(); |
| 929 | let state = self.state.read(cx); |
| 930 | let phase = splash::phase(&StartupFacts { |
| 931 | elapsed: self.splash.elapsed(), |
| 932 | connection: &state.connection, |
| 933 | browser_sign_in: &state.browser_sign_in, |
| 934 | has_chats: !state.sidebar.chats.is_empty() || !state.sidebar.teams.is_empty(), |
| 935 | synced: state.last_sync.is_some(), |
| 936 | demo: state.mode.demo, |
| 937 | opening, |
| 938 | }); |
| 939 | // Poll only when the progress bar is not already driving repaints |
| 940 | // (idle/stopped bar or reduced motion); otherwise the sweep animation |
| 941 | // wakes the splash often enough for BrowserSignIn status updates. |
| 942 | let needs_poll = match &phase { |
| 943 | Phase::Loading { running, .. } => !*running || cx.reduce_motion(), |
| 944 | Phase::Ready => false, |
| 945 | }; |
| 946 | if needs_poll && !self.splash.recheck_scheduled { |
| 947 | self.splash.recheck_scheduled = true; |
| 948 | cx.spawn(async move |this, cx| { |
| 949 | cx.background_executor().timer(splash::STILL_RECHECK).await; |
| 950 | this.update(cx, |this, cx| { |
| 951 | this.splash.recheck_scheduled = false; |
| 952 | cx.notify(); |
| 953 | }) |
| 954 | .ok(); |
| 955 | }) |
| 956 | .detach(); |
| 957 | } |
| 958 | if phase == Phase::Ready { |
| 959 | self.splash.hide(); |
| 960 | cx.spawn(async move |this, cx| { |
| 961 | cx.background_executor().timer(splash::CONTENT_RISE).await; |
| 962 | this.update(cx, |_, cx| cx.notify()).ok(); |
| 963 | }) |
| 964 | .detach(); |
| 965 | } |
| 966 | phase |
| 967 | } else { |
| 968 | Phase::Ready |
| 969 | }; |
| 970 | self.splash.render(&phase, cx) |
| 971 | } |
| 972 | |
| 973 | fn islands( |
| 974 | &self, |
| 975 | show_sidebar: bool, |
| 976 | calendar_open: bool, |
| 977 | quick_view_open: bool, |
| 978 | calls_open: bool, |
| 979 | manage_team_open: bool, |
| 980 | ) -> Div { |
| 981 | h_flex() |
| 982 | .debug_selector(|| "shell/islands".into()) |
| 983 | .flex_1() |
| 984 | .min_h_0() |
| 985 | .w_full() |
| 986 | .when(show_sidebar, |islands| islands.gap(px(ISLAND_GAP))) |
| 987 | .pr(px(ISLAND_GAP)) |
| 988 | .pb(px(ISLAND_GAP)) |
| 989 | .child(h_flex().h_full().flex_none().child(self.rail.clone()).when( |
| 990 | show_sidebar, |
| 991 | |group| { |
| 992 | group.child( |
| 993 | self.sidebar.clone().cached( |
| 994 | StyleRefinement::default() |
| 995 | .w(px(SIDEBAR_WIDTH)) |
| 996 | .h_full() |
| 997 | .flex_none(), |
| 998 | ), |
| 999 | ) |
| 1000 | }, |
| 1001 | )) |
| 1002 | .child(match () { |
| 1003 | _ if calls_open => self |
| 1004 | .calls_page |
| 1005 | .clone() |
| 1006 | .cached(StyleRefinement::default().flex_1().min_w_0().h_full()) |
| 1007 | .into_any_element(), |
| 1008 | _ if manage_team_open => self |
| 1009 | .manage_team_page |
| 1010 | .clone() |
| 1011 | .cached(StyleRefinement::default().flex_1().min_w_0().h_full()) |
| 1012 | .into_any_element(), |
| 1013 | _ if quick_view_open => self |
| 1014 | .quick_pane |
| 1015 | .clone() |
| 1016 | .cached(StyleRefinement::default().flex_1().min_w_0().h_full()) |
| 1017 | .into_any_element(), |
| 1018 | _ if calendar_open => self |
| 1019 | .calendar |
| 1020 | .clone() |
| 1021 | .cached(StyleRefinement::default().flex_1().min_w_0().h_full()) |
| 1022 | .into_any_element(), |
| 1023 | _ => self |
| 1024 | .conversation |
| 1025 | .clone() |
| 1026 | .cached(StyleRefinement::default().flex_1().min_w_0().h_full()) |
| 1027 | .into_any_element(), |
| 1028 | }) |
| 1029 | } |
| 1030 | } |
| 1031 | |
| 1032 | impl Render for AppShell { |
| 1033 | fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { |
| 1034 | let open_dialogs = [ |
| 1035 | self.state.read(cx).task_dialog.is_some(), |
| 1036 | self.forward_dialog.is_some(), |
| 1037 | self.status_dialog.is_some(), |
| 1038 | self.shortcuts_dialog.is_some(), |
| 1039 | self.agent_dialog.is_some(), |
| 1040 | self.settings_dialog.is_some(), |
| 1041 | ] |
| 1042 | .into_iter() |
| 1043 | .filter(|open| *open) |
| 1044 | .count(); |
| 1045 | elevation::set_app_modal_layers(window, open_dialogs, cx); |
| 1046 | if open_dialogs > 0 { |
| 1047 | crate::inline_video::stop(cx); |
| 1048 | } |
| 1049 | if let Some(dialog) = self |
| 1050 | .state |
| 1051 | .read(cx) |
| 1052 | .task_dialog |
| 1053 | .as_ref() |
| 1054 | .map(|dialog| (dialog.scope.clone(), dialog.card.clone())) |
| 1055 | { |
| 1056 | self.state.update(cx, |state, cx| { |
| 1057 | state.ensure_card_inputs(&dialog.0, &dialog.1, window, cx) |
| 1058 | }); |
| 1059 | } |
| 1060 | if let Some(me) = self.state.read(cx).directory.me.clone() { |
| 1061 | let app = self.state.clone(); |
| 1062 | cx.defer(move |cx| { |
| 1063 | app.update(cx, |state, cx| { |
| 1064 | state.request_avatars(vec![me.user_id.clone()], cx); |
| 1065 | state.request_presence(vec![me.user_id], cx); |
| 1066 | }); |
| 1067 | }); |
| 1068 | } |
| 1069 | let notice = self.state.read(cx).notice.clone(); |
| 1070 | self.toasts.sync(&self.state, notice.as_ref(), window, cx); |
| 1071 | let update_failure = match &self.update { |
| 1072 | UpdateStatus::Failed(message) => Some(message.clone()), |
| 1073 | _ => None, |
| 1074 | }; |
| 1075 | self.toasts |
| 1076 | .update_failed(update_failure.as_deref(), window, cx); |
| 1077 | let calendar_tab = self.sidebar.read(cx).tab() == SidebarTab::Calendar; |
| 1078 | let chats_tab = self.sidebar.read(cx).tab() == SidebarTab::Chats; |
| 1079 | let calls_tab = self.sidebar.read(cx).tab() == SidebarTab::Calls; |
| 1080 | let splash = self.render_splash(cx); |
| 1081 | let state = self.state.read(cx); |
| 1082 | let calendar_open = calendar_tab; |
| 1083 | let quick_view_open = chats_tab && state.quick_view.is_some(); |
| 1084 | let manage_team_open = !calendar_tab && !calls_tab && state.manage_team.is_some(); |
| 1085 | let calls_open = calls_tab; |
| 1086 | let show_sidebar = !calendar_open && !calls_open; |
| 1087 | let banner = state |
| 1088 | .connection_banner_text() |
| 1089 | .filter(|_| !self.splash.is_up()) |
| 1090 | .map(|banner| { |
| 1091 | render_connection_banner( |
| 1092 | banner, |
| 1093 | cx.listener(|this, _, _, cx| { |
| 1094 | this.state.update(cx, |state, _| state.retry_live()) |
| 1095 | }), |
| 1096 | ) |
| 1097 | }); |
| 1098 | let title_bar = render_title_bar( |
| 1099 | crate::active_appearance::current(cx).app_icon, |
| 1100 | mode_label(state.mode), |
| 1101 | [ |
| 1102 | update_button( |
| 1103 | &self.update, |
| 1104 | cx.listener(|this, _, _, cx| this.restart_into_update(cx)), |
| 1105 | ), |
| 1106 | Some(settings_more_button(&self.state)), |
| 1107 | own_status_button(&self.state, state), |
| 1108 | ] |
| 1109 | .into_iter() |
| 1110 | .flatten(), |
| 1111 | cx.listener(|this, _, window, cx| this.toggle_switcher("", window, cx)), |
| 1112 | ); |
| 1113 | let shell = div() |
| 1114 | .id("app-shell") |
| 1115 | .key_context("AppShell") |
| 1116 | .track_focus(&self.focus_handle); |
| 1117 | self.team_keys(shell, cx) |
| 1118 | .on_action(cx.listener(|this, _: &OpenSwitcher, window, cx| { |
| 1119 | this.toggle_switcher("", window, cx); |
| 1120 | })) |
| 1121 | .on_action(cx.listener(|this, _: &NewChat, window, cx| { |
| 1122 | this.close_image_viewer(window, cx); |
| 1123 | this.state.update(cx, |state, cx| state.start_new_chat(cx)); |
| 1124 | })) |
| 1125 | .on_action(cx.listener(|this, _: &ToggleCallMute, _, cx| { |
| 1126 | this.state |
| 1127 | .update(cx, |state, cx| state.toggle_call_mute(cx)); |
| 1128 | })) |
| 1129 | .on_action(cx.listener(|this, _: &PushToTalk, _, cx| { |
| 1130 | this.state |
| 1131 | .update(cx, |state, cx| state.press_push_to_talk(cx)); |
| 1132 | })) |
| 1133 | .on_key_up(cx.listener(|this, event: &KeyUpEvent, _, cx| { |
| 1134 | if event.keystroke.key == "space" { |
| 1135 | this.state |
| 1136 | .update(cx, |state, cx| state.release_push_to_talk(cx)); |
| 1137 | } |
| 1138 | })) |
| 1139 | .on_modifiers_changed(cx.listener(|this, event: &ModifiersChangedEvent, _, cx| { |
| 1140 | if !event.modifiers.control { |
| 1141 | this.state |
| 1142 | .update(cx, |state, cx| state.release_push_to_talk(cx)); |
| 1143 | } |
| 1144 | })) |
| 1145 | .on_action(cx.listener(|this, _: &OpenSettings, window, cx| { |
| 1146 | this.open_settings(SettingsSection::General, window, cx); |
| 1147 | })) |
| 1148 | .on_action(cx.listener(|this, _: &ShowShortcuts, window, cx| { |
| 1149 | this.toggle_shortcuts_dialog(window, cx); |
| 1150 | })) |
| 1151 | .on_action(cx.listener(|this, _: &OpenActivity, window, cx| { |
| 1152 | this.close_image_viewer(window, cx); |
| 1153 | this.sidebar |
| 1154 | .update(cx, |sidebar, cx| sidebar.show_activity(cx)); |
| 1155 | })) |
| 1156 | .on_action(cx.listener(|this, _: &OpenSaved, window, cx| { |
| 1157 | this.close_image_viewer(window, cx); |
| 1158 | this.sidebar.update(cx, |sidebar, cx| { |
| 1159 | sidebar.open_quick_view(QuickView::Saved, cx) |
| 1160 | }); |
| 1161 | })) |
| 1162 | .on_action(cx.listener(|this, _: &OpenCalendar, window, cx| { |
| 1163 | this.close_image_viewer(window, cx); |
| 1164 | this.sidebar |
| 1165 | .update(cx, |sidebar, cx| sidebar.show_calendar(cx)); |
| 1166 | })) |
| 1167 | .on_action(cx.listener(|this, _: &OpenAgents, window, cx| { |
| 1168 | this.close_image_viewer(window, cx); |
| 1169 | this.sidebar |
| 1170 | .update(cx, |sidebar, cx| sidebar.show_agents(cx)); |
| 1171 | })) |
| 1172 | .on_action(cx.listener(|this, _: &OpenChatsTab, window, cx| { |
| 1173 | this.close_image_viewer(window, cx); |
| 1174 | this.sidebar |
| 1175 | .update(cx, |sidebar, cx| sidebar.show_chats(cx)); |
| 1176 | })) |
| 1177 | .on_action(cx.listener(|this, _: &FindInChat, window, cx| { |
| 1178 | this.close_image_viewer(window, cx); |
| 1179 | this.state |
| 1180 | .update(cx, |state, cx| state.close_quick_view(cx)); |
| 1181 | this.conversation |
| 1182 | .update(cx, |conversation, cx| conversation.open_find(window, cx)); |
| 1183 | })) |
| 1184 | .on_action(cx.listener(|this, _: &PopOutSelectedChat, _, cx| { |
| 1185 | let selected = this.state.read(cx).selection.clone(); |
| 1186 | if let Some(Selection::Chat(chat_id)) = selected { |
| 1187 | chat_pop_out::pop_out_chat(&this.state, &chat_id, cx); |
| 1188 | } |
| 1189 | })) |
| 1190 | .on_action(cx.listener(|this, _: &OpenChatFilter, window, cx| { |
| 1191 | this.close_image_viewer(window, cx); |
| 1192 | this.sidebar |
| 1193 | .update(cx, |sidebar, cx| sidebar.toggle_filter_box(window, cx)); |
| 1194 | })) |
| 1195 | .on_action(cx.listener(|this, _: &FilterUnreadChats, _, cx| { |
| 1196 | this.sidebar.update(cx, |sidebar, cx| { |
| 1197 | sidebar.toggle_pill(ChatFilterPill::Unread, cx) |
| 1198 | }); |
| 1199 | })) |
| 1200 | .on_action(cx.listener(|this, _: &FilterNonMeetingChats, _, cx| { |
| 1201 | this.sidebar.update(cx, |sidebar, cx| { |
| 1202 | sidebar.toggle_pill(ChatFilterPill::Chats, cx) |
| 1203 | }); |
| 1204 | })) |
| 1205 | .on_action(cx.listener(|this, _: &FilterMeetingChats, _, cx| { |
| 1206 | this.sidebar.update(cx, |sidebar, cx| { |
| 1207 | sidebar.toggle_pill(ChatFilterPill::Meetings, cx) |
| 1208 | }); |
| 1209 | })) |
| 1210 | .on_action(cx.listener(|this, _: &FilterMutedChats, _, cx| { |
| 1211 | this.sidebar.update(cx, |sidebar, cx| { |
| 1212 | sidebar.toggle_pill(ChatFilterPill::Muted, cx) |
| 1213 | }); |
| 1214 | })) |
| 1215 | .on_action(cx.listener(|this, _: &ClearChatFilters, window, cx| { |
| 1216 | this.sidebar |
| 1217 | .update(cx, |sidebar, cx| sidebar.clear_filters(window, cx)); |
| 1218 | })) |
| 1219 | .on_action(cx.listener(|this, _: &OpenChannelsTab, window, cx| { |
| 1220 | this.close_image_viewer(window, cx); |
| 1221 | this.sidebar |
| 1222 | .update(cx, |sidebar, cx| sidebar.show_channels(cx)); |
| 1223 | })) |
| 1224 | .on_action(cx.listener(|this, _: &OpenCallsTab, window, cx| { |
| 1225 | this.close_image_viewer(window, cx); |
| 1226 | this.sidebar |
| 1227 | .update(cx, |sidebar, cx| sidebar.show_calls(cx)); |
| 1228 | })) |
| 1229 | .on_action(cx.listener(|this, _: &PreviousConversation, window, cx| { |
| 1230 | this.close_image_viewer(window, cx); |
| 1231 | this.sidebar.update(cx, |sidebar, cx| { |
| 1232 | sidebar.select_adjacent(Step::Previous, cx) |
| 1233 | }); |
| 1234 | })) |
| 1235 | .on_action(cx.listener(|this, _: &NextConversation, window, cx| { |
| 1236 | this.close_image_viewer(window, cx); |
| 1237 | this.sidebar |
| 1238 | .update(cx, |sidebar, cx| sidebar.select_adjacent(Step::Next, cx)); |
| 1239 | })) |
| 1240 | .on_action(cx.listener(|this, _: &DeclineCall, _, cx| { |
| 1241 | this.state |
| 1242 | .update(cx, |state, cx| state.decline_ringing_call(cx)); |
| 1243 | })) |
| 1244 | .on_action(cx.listener(|this, _: &JoinMeetingFromToast, _, cx| { |
| 1245 | this.state |
| 1246 | .update(cx, |state, cx| state.join_latest_meeting_toast(cx)); |
| 1247 | })) |
| 1248 | .on_action(cx.listener(|this, _: &HangUpCall, _, cx| { |
| 1249 | this.state.update(cx, |state, cx| state.leave_call(cx)); |
| 1250 | })) |
| 1251 | .on_action(cx.listener(|this, _: &ToggleCallCamera, _, cx| { |
| 1252 | this.state |
| 1253 | .update(cx, |state, cx| state.toggle_call_camera(cx)); |
| 1254 | })) |
| 1255 | .on_action(cx.listener(|this, _: &ToggleCallShare, _, cx| { |
| 1256 | this.state |
| 1257 | .update(cx, |state, cx| state.toggle_call_share(cx)); |
| 1258 | })) |
| 1259 | .on_action(cx.listener(|this, _: &ToggleCallHand, _, cx| { |
| 1260 | this.state |
| 1261 | .update(cx, |state, cx| state.toggle_call_hand(cx)); |
| 1262 | })) |
| 1263 | .on_action(cx.listener(|this, _: &OpenLobbyList, _, cx| { |
| 1264 | this.state |
| 1265 | .update(cx, |state, cx| state.open_call_lobby_list(cx)); |
| 1266 | })) |
| 1267 | .on_action(cx.listener(|this, _: &StartAudioCall, _, cx| { |
| 1268 | this.start_call_in_open_chat(false, cx); |
| 1269 | })) |
| 1270 | .on_action(cx.listener(|this, _: &StartVideoCall, _, cx| { |
| 1271 | this.start_call_in_open_chat(true, cx); |
| 1272 | })) |
| 1273 | .on_action( |
| 1274 | cx.listener(|this, _: &ZoomIn, _, cx| change_zoom(&this.state, WindowZoom::In, cx)), |
| 1275 | ) |
| 1276 | .on_action( |
| 1277 | cx.listener(|this, _: &ZoomOut, _, cx| { |
| 1278 | change_zoom(&this.state, WindowZoom::Out, cx) |
| 1279 | }), |
| 1280 | ) |
| 1281 | .on_action(cx.listener(|this, _: &ZoomReset, _, cx| { |
| 1282 | change_zoom(&this.state, WindowZoom::Reset, cx) |
| 1283 | })) |
| 1284 | .on_action(zoom_listener::<ZoomShareIn>(&self.state, ZoomStep::In)) |
| 1285 | .on_action(zoom_listener::<ZoomShareOut>(&self.state, ZoomStep::Out)) |
| 1286 | .on_action(zoom_listener::<ZoomShareReset>( |
| 1287 | &self.state, |
| 1288 | ZoomStep::Reset, |
| 1289 | )) |
| 1290 | .on_action(cx.listener(|this, _: &JumpToLastReadOrNewest, _, cx| { |
| 1291 | if this.image_viewer.is_some() { |
| 1292 | cx.propagate(); |
| 1293 | return; |
| 1294 | } |
| 1295 | this.conversation.update(cx, |conversation, cx| { |
| 1296 | conversation.jump_to_last_read_or_newest(cx) |
| 1297 | }); |
| 1298 | })) |
| 1299 | .on_action(cx.listener(|this, _: &ReplyToHovered, window, cx| { |
| 1300 | this.close_image_viewer(window, cx); |
| 1301 | this.conversation.update(cx, |conversation, cx| { |
| 1302 | conversation.reply_to_hovered(window, cx) |
| 1303 | }); |
| 1304 | })) |
| 1305 | .relative() |
| 1306 | .size_full() |
| 1307 | .bg(theme::background()) |
| 1308 | .text_color(theme::text()) |
| 1309 | .text_size(px(14.)) |
| 1310 | .child(crate::frame_log::probe("first")) |
| 1311 | .child(user_activity::input_probe(self.user_input.clone())) |
| 1312 | .child(app_ui_kit::long_press::long_press_right_click()) |
| 1313 | .child( |
| 1314 | v_flex() |
| 1315 | .debug_selector(|| "shell".into()) |
| 1316 | .size_full() |
| 1317 | .child(title_bar) |
| 1318 | .children(banner) |
| 1319 | .child(rising_in( |
| 1320 | self.islands( |
| 1321 | show_sidebar, |
| 1322 | calendar_open, |
| 1323 | quick_view_open, |
| 1324 | calls_open, |
| 1325 | manage_team_open, |
| 1326 | ), |
| 1327 | &self.splash, |
| 1328 | cx, |
| 1329 | )), |
| 1330 | ) |
| 1331 | .children(splash) |
| 1332 | .children(self.image_viewer.clone()) |
| 1333 | .children(self.switcher.clone()) |
| 1334 | .children(render_task_dialog(self.state.read(cx), cx)) |
| 1335 | .children(self.forward_dialog.clone()) |
| 1336 | .children(self.status_dialog.clone()) |
| 1337 | .children(self.shortcuts_dialog.clone()) |
| 1338 | .children(self.agent_dialog.clone()) |
| 1339 | .children(self.settings_dialog.clone()) |
| 1340 | .children(self.profile_card.clone()) |
| 1341 | .child(crate::frame_log::probe("last")) |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | fn rising_in(islands: Div, splash: &Splash, cx: &App) -> AnyElement { |
| 1346 | if splash.content_rising().is_none() || cx.reduce_motion() { |
| 1347 | return islands.into_any_element(); |
| 1348 | } |
| 1349 | islands |
| 1350 | .relative() |
| 1351 | .with_animation( |
| 1352 | "startup-content-rise", |
| 1353 | Animation::new(splash::CONTENT_RISE).with_easing(ease_out_quint()), |
| 1354 | |islands, delta| { |
| 1355 | islands |
| 1356 | .top(px(splash::CONTENT_RISE_OFFSET * (1. - delta))) |
| 1357 | .opacity(delta) |
| 1358 | }, |
| 1359 | ) |
| 1360 | .into_any_element() |
| 1361 | } |
| 1362 | |
| 1363 | #[cfg(test)] |
| 1364 | mod opening_link_tests { |
| 1365 | use super::opening_link_text; |
| 1366 | |
| 1367 | #[test] |
| 1368 | fn the_notice_names_the_host() { |
| 1369 | assert_eq!( |
| 1370 | opening_link_text("https://example.com/a?b#c"), |
| 1371 | "Opening example.com..." |
| 1372 | ); |
| 1373 | assert_eq!(opening_link_text("mailto:"), "Opening mailto:..."); |
| 1374 | assert_eq!(opening_link_text(""), "Opening link..."); |
| 1375 | } |
| 1376 | } |