mod archive_labels; mod bookmarks; mod command_actions; mod downloads; mod focus; mod history; mod internal_pages; mod navigation; mod notes; mod plugins; mod reading_list; mod render; mod sidebar; mod site_permissions; mod space_files; mod spaces; mod splits; mod tab_groups; mod tab_lifecycle; mod web_surface; mod web_surface_controller; mod web_surface_frame; mod web_surface_geometry; mod web_surface_image; mod web_surface_keyboard; mod web_surface_permissions; mod web_surface_state; mod web_surface_view; use ely_browser_core::{BrowserCore, InitialBrowserConfig}; use ely_domain::{ ArchivePolicy, DownloadPolicy, FavoriteLimit, HistoryRecordingPolicy, NewTabDestination, ProfileId, ProfileSyncPolicy, SearchEngine, SpaceId, SyncObjectKind, SyncObjectPolicy, TabId, }; use gpui::{AppContext, Context, Entity, FocusHandle, Subscription, Window}; use gpui_component::input::{InputEvent, InputState}; use bookmarks::PendingBookmarkEdit; use downloads::PendingDownloadFileAction; use history::{PendingHistoryDomainClear, PendingHistoryTimeClear}; use plugins::{PendingPluginInstall, PendingPluginUninstall}; use web_surface::WebSurfaceStore; use crate::{ CloseCurrentTab, FocusAddressBar, FocusCommandMode, OpenDownloads, OpenHistory, OpenNewTab, OpenSettings, OpenTaskManager, RestoreClosedTab, SelectNextTab, SelectPreviousTab, ToggleFavoriteTab, TogglePinnedTab, }; enum ShellState { Ready(Box), StartupError(String), } pub struct ElyShell { state: ShellState, focus_handle: FocusHandle, command_input: Entity, download_action_error: Option, download_clear_confirmation: bool, download_security_confirmation: Option, history_clear_confirmation: Option, pending_history_domain_clear: Option, pending_history_time_clear: Option, site_permissions_clear_confirmation: Option, pending_space_trash: Option, space_file_error: Option, space_file_notice: Option, pending_bookmark_edit: Option, bookmark_edit_error: Option, plugin_install_error: Option, pending_plugin_install: Option, pending_plugin_uninstall: Option, web_surfaces: WebSurfaceStore, _command_subscription: Subscription, } impl ElyShell { pub fn new(window: &mut Window, cx: &mut Context) -> Self { let command_input = cx.new(|cx| InputState::new(window, cx).placeholder("Search or enter address")); let command_subscription = cx.subscribe_in( &command_input, window, |shell: &mut Self, input, event: &InputEvent, window, cx| { let mut submitted_intent = None; let mut sync_address = false; let submitted = matches!(event, InputEvent::PressEnter { .. }); { let ShellState::Ready(core) = &mut shell.state else { return; }; let value = input.read(cx).value().to_string(); core.set_command_query(value); if submitted { submitted_intent = core.submit_command().ok().flatten(); sync_address = core.command_query().is_empty(); } } shell.handle_shell_command_intent(submitted_intent.as_ref(), window, cx); if sync_address { shell.sync_address_input(window, cx); } cx.notify(); }, ); let state = match InitialBrowserConfig::ely_defaults().and_then(|config| { BrowserCore::new(config).map_err(|error| match error { ely_browser_core::CoreError::Domain(source) => source, _ => ely_domain::DomainError::InvalidCommand, }) }) { Ok(core) => ShellState::Ready(Box::new(core)), Err(error) => ShellState::StartupError(error.to_string()), }; Self { state, focus_handle: cx.focus_handle(), command_input, download_action_error: None, download_clear_confirmation: false, download_security_confirmation: None, history_clear_confirmation: None, pending_history_domain_clear: None, pending_history_time_clear: None, site_permissions_clear_confirmation: None, pending_space_trash: None, space_file_error: None, space_file_notice: None, pending_bookmark_edit: None, bookmark_edit_error: None, plugin_install_error: None, pending_plugin_install: None, pending_plugin_uninstall: None, web_surfaces: WebSurfaceStore::new(), _command_subscription: command_subscription, } } fn focus_command_mode(&mut self, window: &mut Window, cx: &mut Context) { if let ShellState::Ready(core) = &mut self.state { core.set_command_query(">"); } self.command_input.update(cx, |input, cx| { input.set_value(">", window, cx); input.focus(window, cx); }); cx.notify(); } fn select_tab(&mut self, tab_id: &TabId, window: &mut Window, cx: &mut Context) { if let ShellState::Ready(core) = &mut self.state && core.select_tab(tab_id).is_ok() { self.sync_address_input(window, cx); cx.notify(); } } fn select_space(&mut self, space_id: &SpaceId, window: &mut Window, cx: &mut Context) { if let ShellState::Ready(core) = &mut self.state && core.select_space(space_id).is_ok() { self.sync_address_input(window, cx); cx.notify(); } } fn select_profile( &mut self, profile_id: &ProfileId, window: &mut Window, cx: &mut Context, ) { if let ShellState::Ready(core) = &mut self.state && core.select_profile(profile_id).is_ok() { self.sync_address_input(window, cx); cx.notify(); } } fn select_next_tab(&mut self, window: &mut Window, cx: &mut Context) { if let ShellState::Ready(core) = &mut self.state && core.select_next_tab().is_ok() { self.sync_address_input(window, cx); cx.notify(); } } fn select_previous_tab(&mut self, window: &mut Window, cx: &mut Context) { if let ShellState::Ready(core) = &mut self.state && core.select_previous_tab().is_ok() { self.sync_address_input(window, cx); cx.notify(); } } fn close_active_tab(&mut self, window: &mut Window, cx: &mut Context) { if let ShellState::Ready(core) = &mut self.state && core.close_active_tab().is_ok() { self.sync_address_input(window, cx); cx.notify(); } } fn restore_closed_tab(&mut self, window: &mut Window, cx: &mut Context) { if let ShellState::Ready(core) = &mut self.state && core.restore_last_archived_tab().is_ok() { self.sync_address_input(window, cx); cx.notify(); } } fn restore_archived_tab( &mut self, tab_id: &TabId, window: &mut Window, cx: &mut Context, ) { if let ShellState::Ready(core) = &mut self.state && core.restore_archived_tab(tab_id).is_ok() { self.sync_address_input(window, cx); cx.notify(); } } fn toggle_active_tab_favorite(&mut self, cx: &mut Context) { if let ShellState::Ready(core) = &mut self.state && core.toggle_active_tab_favorite().is_ok() { cx.notify(); } } fn toggle_active_tab_pinned(&mut self, cx: &mut Context) { if let ShellState::Ready(core) = &mut self.state && core.toggle_active_tab_pinned().is_ok() { cx.notify(); } } fn set_active_space_archive_policy( &mut self, archive_policy: ArchivePolicy, cx: &mut Context, ) { if let ShellState::Ready(core) = &mut self.state && core.set_active_space_archive_policy(archive_policy).is_ok() { cx.notify(); } } fn set_search_engine(&mut self, search_engine: SearchEngine, cx: &mut Context) { if let ShellState::Ready(core) = &mut self.state { core.set_search_engine(search_engine); cx.notify(); } } fn set_new_tab_destination(&mut self, destination: NewTabDestination, cx: &mut Context) { if let ShellState::Ready(core) = &mut self.state { core.set_new_tab_destination(destination); cx.notify(); } } fn set_history_recording_policy( &mut self, policy: HistoryRecordingPolicy, cx: &mut Context, ) { if let ShellState::Ready(core) = &mut self.state { core.set_history_recording_policy(policy); cx.notify(); } } fn set_active_profile_download_policy( &mut self, policy: DownloadPolicy, cx: &mut Context, ) { if let ShellState::Ready(core) = &mut self.state && core.set_active_profile_download_policy(policy).is_ok() { cx.notify(); } } fn set_profile_sync_policy( &mut self, profile_id: &ProfileId, sync_policy: ProfileSyncPolicy, cx: &mut Context, ) { if let ShellState::Ready(core) = &mut self.state && core.set_profile_sync_policy(profile_id, sync_policy).is_ok() { cx.notify(); } } fn set_favorite_limit(&mut self, favorite_limit: FavoriteLimit, cx: &mut Context) { if let ShellState::Ready(core) = &mut self.state { core.set_favorite_limit(favorite_limit); cx.notify(); } } fn set_sync_object_policy( &mut self, kind: SyncObjectKind, policy: SyncObjectPolicy, cx: &mut Context, ) { if let ShellState::Ready(core) = &mut self.state { core.set_sync_object_policy(kind, policy); cx.notify(); } } fn archive_idle_tabs_now(&mut self, cx: &mut Context) { if let ShellState::Ready(core) = &mut self.state && core.archive_idle_tabs(std::time::SystemTime::now()).is_ok() { cx.notify(); } } fn on_close_current_tab( &mut self, _: &CloseCurrentTab, window: &mut Window, cx: &mut Context, ) { self.close_active_tab(window, cx); } fn on_focus_address_bar( &mut self, _: &FocusAddressBar, window: &mut Window, cx: &mut Context, ) { self.focus_address_bar(window, cx); } fn on_focus_command_mode( &mut self, _: &FocusCommandMode, window: &mut Window, cx: &mut Context, ) { self.focus_command_mode(window, cx); } fn on_open_new_tab(&mut self, _: &OpenNewTab, window: &mut Window, cx: &mut Context) { self.open_new_tab(window, cx); } fn on_open_downloads( &mut self, _: &OpenDownloads, window: &mut Window, cx: &mut Context, ) { self.open_downloads(window, cx); } fn on_open_history(&mut self, _: &OpenHistory, window: &mut Window, cx: &mut Context) { self.open_history(window, cx); } fn on_open_settings(&mut self, _: &OpenSettings, window: &mut Window, cx: &mut Context) { self.open_settings(window, cx); } fn on_open_task_manager( &mut self, _: &OpenTaskManager, window: &mut Window, cx: &mut Context, ) { self.open_task_manager(window, cx); } fn on_restore_closed_tab( &mut self, _: &RestoreClosedTab, window: &mut Window, cx: &mut Context, ) { self.restore_closed_tab(window, cx); } fn on_select_next_tab( &mut self, _: &SelectNextTab, window: &mut Window, cx: &mut Context, ) { self.select_next_tab(window, cx); } fn on_select_previous_tab( &mut self, _: &SelectPreviousTab, window: &mut Window, cx: &mut Context, ) { self.select_previous_tab(window, cx); } fn on_toggle_favorite_tab( &mut self, _: &ToggleFavoriteTab, _: &mut Window, cx: &mut Context, ) { self.toggle_active_tab_favorite(cx); } fn on_toggle_pinned_tab( &mut self, _: &TogglePinnedTab, _: &mut Window, cx: &mut Context, ) { self.toggle_active_tab_pinned(cx); } }