diff --git a/src/ui/activities/auth/view.rs b/src/ui/activities/auth/view.rs index ae67e47..7da7e36 100644 --- a/src/ui/activities/auth/view.rs +++ b/src/ui/activities/auth/view.rs @@ -2,32 +2,28 @@ //! //! `auth_activity` is the module which implements the authentication activity -// Locals -use std::path::PathBuf; -use std::str::FromStr; - use tuirealm::props::Color; use tuirealm::ratatui::layout::{Constraint, Direction, Layout}; use tuirealm::ratatui::widgets::Clear; -use tuirealm::{State, StateValue, Sub, SubClause, SubEventClause}; use super::{ AuthActivity, AuthFormId, Context, FileTransferProtocol, FormTab, HostBridgeProtocol, Id, InputMask, components, }; -use crate::filetransfer::FileTransferParams; -use crate::filetransfer::params::{ - AwsS3Params, GenericProtocolParams, KubeProtocolParams, ProtocolParams, SmbParams, - WebDAVProtocolParams, -}; use crate::utils::ui::{Popup, Size}; +#[path = "view/mounting.rs"] +mod mounting; +#[path = "view/query.rs"] +mod query; +#[path = "view/visible.rs"] +mod visible; + impl AuthActivity { /// Initialize view, mounting all startup components inside the view pub(super) fn init(&mut self) { let key_color = self.theme().misc_keys; let info_color = self.theme().misc_info_dialog; - // Headers if let Err(err) = self .app .mount(Id::Title, Box::::default(), vec![]) @@ -40,7 +36,6 @@ impl AuthActivity { { error!("Failed to mount component: {err}"); } - // Footer if let Err(err) = self.app.mount( Id::HelpFooter, Box::new(components::HelpFooter::new(key_color)), @@ -49,7 +44,6 @@ impl AuthActivity { error!("Failed to mount component: {err}"); } - // Host bridge auth form self.mount_host_bridge_protocol(HostBridgeProtocol::Localhost); self.mount_remote_directory(FormTab::HostBridge, ""); self.mount_local_directory(FormTab::HostBridge, ""); @@ -76,10 +70,7 @@ impl AuthActivity { self.mount_smb_workgroup(FormTab::HostBridge, ""); self.mount_webdav_uri(FormTab::HostBridge, ""); - // Remote Auth form - // Get default protocol - let remote_default_protocol: FileTransferProtocol = - self.context().config().get_default_protocol(); + let remote_default_protocol = self.context().config().get_default_protocol(); self.mount_remote_protocol(remote_default_protocol); self.mount_remote_directory(FormTab::Remote, ""); self.mount_local_directory(FormTab::Remote, ""); @@ -109,13 +100,12 @@ impl AuthActivity { self.mount_smb_workgroup(FormTab::Remote, ""); self.mount_webdav_uri(FormTab::Remote, ""); - // Version notice if let Some(version) = self .context() .store() .get_string(super::STORE_KEY_LATEST_VERSION) { - let version: String = version.to_string(); + let version = version.to_string(); if let Err(err) = self.app.mount( Id::NewVersionDisclaimer, Box::new(components::NewVersionDisclaimer::new( @@ -127,12 +117,9 @@ impl AuthActivity { error!("Failed to mount component: {err}"); } } - // Load bookmarks self.view_bookmarks(); self.view_recent_connections(); - // Global listener self.init_global_listener(); - // Active protocol if let Err(err) = self.app.active(&Id::Remote(AuthFormId::Protocol)) { error!("Failed to activate component: {err}"); } @@ -143,158 +130,108 @@ impl AuthActivity { self.redraw = false; let mut ctx: Context = self.context.take().unwrap(); let _ = ctx.terminal().raw_mut().draw(|f| { - // Check window size - let height: u16 = f.area().height; + let height = f.area().height; self.check_minimum_window_size(height); - // Prepare chunks let body = Layout::default() .direction(Direction::Vertical) - .constraints( - [ - Constraint::Min(24), // Body - Constraint::Length(1), // Footer - ] - .as_ref(), - ) + .constraints([Constraint::Min(24), Constraint::Length(1)].as_ref()) .split(f.area()); - // Footer self.app.view(&Id::HelpFooter, f, body[1]); let auth_form_len = 7 + self.max_input_mask_size(); let main_chunks = Layout::default() .direction(Direction::Vertical) .margin(1) - .constraints( - [ - Constraint::Length(auth_form_len), // Auth Form - Constraint::Min(3), // Bookmarks - ] - .as_ref(), - ) + .constraints([Constraint::Length(auth_form_len), Constraint::Min(3)].as_ref()) .split(body[0]); - // Create explorer chunks let auth_chunks = Layout::default() .constraints( [ - Constraint::Length(1), // h1 - Constraint::Length(1), // h2 - Constraint::Length(1), // Version - Constraint::Length(self.max_input_mask_size()), // Input mask - Constraint::Length(1), // Prevents last field to overflow + Constraint::Length(1), + Constraint::Length(1), + Constraint::Length(1), + Constraint::Length(self.max_input_mask_size()), + Constraint::Length(1), ] .as_ref(), ) .direction(Direction::Vertical) .split(main_chunks[0]); - - // Create bookmark chunks let bookmark_chunks = Layout::default() .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) .direction(Direction::Horizontal) .spacing(2) .split(main_chunks[1]); - // Render - // Auth chunks self.app.view(&Id::Title, f, auth_chunks[0]); self.app.view(&Id::Subtitle, f, auth_chunks[1]); self.app.view(&Id::NewVersionDisclaimer, f, auth_chunks[2]); - // Render the host bridge and remote forms let host_bridge_and_remote_chunks = Layout::default() - .constraints( - [ - Constraint::Percentage(50), // Host bridge - Constraint::Percentage(50), // Remote - ] - .as_ref(), - ) + .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) .spacing(2) .direction(Direction::Horizontal) .split(auth_chunks[3]); - // Input mask self.render_host_bridge_input_mask(f, host_bridge_and_remote_chunks[0]); self.render_remote_input_mask(f, host_bridge_and_remote_chunks[1]); - // Bookmark chunks self.app.view(&Id::BookmarksList, f, bookmark_chunks[0]); self.app.view(&Id::RecentsList, f, bookmark_chunks[1]); - // Popups - if self.app.mounted(&Id::ErrorPopup) { - let popup = Popup(Size::Percentage(50), Size::Unit(3)).draw_in(f.area()); - f.render_widget(Clear, popup); - // make popup - self.app.view(&Id::ErrorPopup, f, popup); - } else if self.app.mounted(&Id::InfoPopup) { - let popup = Popup(Size::Percentage(50), Size::Unit(3)).draw_in(f.area()); - f.render_widget(Clear, popup); - // make popup - self.app.view(&Id::InfoPopup, f, popup); - } else if self.app.mounted(&Id::WaitPopup) { - let popup = Popup(Size::Percentage(50), Size::Unit(3)).draw_in(f.area()); - f.render_widget(Clear, popup); - // make popup - self.app.view(&Id::WaitPopup, f, popup); - } else if self.app.mounted(&Id::WindowSizeError) { - let popup = Popup(Size::Percentage(80), Size::Percentage(20)).draw_in(f.area()); - f.render_widget(Clear, popup); - // make popup - self.app.view(&Id::WindowSizeError, f, popup); - } else if self.app.mounted(&Id::QuitPopup) { - // make popup - let popup = Popup(Size::Percentage(30), Size::Unit(3)).draw_in(f.area()); - f.render_widget(Clear, popup); - self.app.view(&Id::QuitPopup, f, popup); - } else if self.app.mounted(&Id::DeleteBookmarkPopup) { - // make popup - let popup = Popup(Size::Percentage(30), Size::Unit(3)).draw_in(f.area()); - f.render_widget(Clear, popup); - self.app.view(&Id::DeleteBookmarkPopup, f, popup); - } else if self.app.mounted(&Id::DeleteRecentPopup) { - // make popup - let popup = Popup(Size::Percentage(30), Size::Unit(3)).draw_in(f.area()); - f.render_widget(Clear, popup); - self.app.view(&Id::DeleteRecentPopup, f, popup); - } else if self.app.mounted(&Id::NewVersionChangelog) { - // make popup - let popup = Popup(Size::Percentage(90), Size::Percentage(85)).draw_in(f.area()); - f.render_widget(Clear, popup); - let popup_chunks = Layout::default() - .direction(Direction::Vertical) - .constraints( - [ - Constraint::Percentage(90), // Notes - Constraint::Length(3), // Install radio - ] - .as_ref(), - ) - .split(popup); - self.app.view(&Id::NewVersionChangelog, f, popup_chunks[0]); - self.app.view(&Id::InstallUpdatePopup, f, popup_chunks[1]); - } else if self.app.mounted(&Id::Keybindings) { - // make popup - let popup = Popup(Size::Percentage(50), Size::Percentage(70)).draw_in(f.area()); - f.render_widget(Clear, popup); - self.app.view(&Id::Keybindings, f, popup); - } else if self.app.mounted(&Id::BookmarkSavePassword) { - // make popup - let popup = Popup(Size::Percentage(20), Size::Percentage(20)).draw_in(f.area()); - f.render_widget(Clear, popup); - let popup_chunks = Layout::default() - .direction(Direction::Vertical) - .constraints( - [ - Constraint::Length(3), // Input form - Constraint::Length(4), // Yes/No - ] - .as_ref(), - ) - .split(popup); - self.app.view(&Id::BookmarkName, f, popup_chunks[0]); - self.app.view(&Id::BookmarkSavePassword, f, popup_chunks[1]); - } + self.render_popup(f); }); self.context = Some(ctx); } - // -- partials + fn render_popup(&mut self, f: &mut tuirealm::ratatui::Frame<'_>) { + if self.app.mounted(&Id::ErrorPopup) { + let popup = Popup(Size::Percentage(50), Size::Unit(3)).draw_in(f.area()); + f.render_widget(Clear, popup); + self.app.view(&Id::ErrorPopup, f, popup); + } else if self.app.mounted(&Id::InfoPopup) { + let popup = Popup(Size::Percentage(50), Size::Unit(3)).draw_in(f.area()); + f.render_widget(Clear, popup); + self.app.view(&Id::InfoPopup, f, popup); + } else if self.app.mounted(&Id::WaitPopup) { + let popup = Popup(Size::Percentage(50), Size::Unit(3)).draw_in(f.area()); + f.render_widget(Clear, popup); + self.app.view(&Id::WaitPopup, f, popup); + } else if self.app.mounted(&Id::WindowSizeError) { + let popup = Popup(Size::Percentage(80), Size::Percentage(20)).draw_in(f.area()); + f.render_widget(Clear, popup); + self.app.view(&Id::WindowSizeError, f, popup); + } else if self.app.mounted(&Id::QuitPopup) { + let popup = Popup(Size::Percentage(30), Size::Unit(3)).draw_in(f.area()); + f.render_widget(Clear, popup); + self.app.view(&Id::QuitPopup, f, popup); + } else if self.app.mounted(&Id::DeleteBookmarkPopup) { + let popup = Popup(Size::Percentage(30), Size::Unit(3)).draw_in(f.area()); + f.render_widget(Clear, popup); + self.app.view(&Id::DeleteBookmarkPopup, f, popup); + } else if self.app.mounted(&Id::DeleteRecentPopup) { + let popup = Popup(Size::Percentage(30), Size::Unit(3)).draw_in(f.area()); + f.render_widget(Clear, popup); + self.app.view(&Id::DeleteRecentPopup, f, popup); + } else if self.app.mounted(&Id::NewVersionChangelog) { + let popup = Popup(Size::Percentage(90), Size::Percentage(85)).draw_in(f.area()); + f.render_widget(Clear, popup); + let popup_chunks = Layout::default() + .direction(Direction::Vertical) + .constraints([Constraint::Percentage(90), Constraint::Length(3)].as_ref()) + .split(popup); + self.app.view(&Id::NewVersionChangelog, f, popup_chunks[0]); + self.app.view(&Id::InstallUpdatePopup, f, popup_chunks[1]); + } else if self.app.mounted(&Id::Keybindings) { + let popup = Popup(Size::Percentage(50), Size::Percentage(70)).draw_in(f.area()); + f.render_widget(Clear, popup); + self.app.view(&Id::Keybindings, f, popup); + } else if self.app.mounted(&Id::BookmarkSavePassword) { + let popup = Popup(Size::Percentage(20), Size::Percentage(20)).draw_in(f.area()); + f.render_widget(Clear, popup); + let popup_chunks = Layout::default() + .direction(Direction::Vertical) + .constraints([Constraint::Length(3), Constraint::Length(4)].as_ref()) + .split(popup); + self.app.view(&Id::BookmarkName, f, popup_chunks[0]); + self.app.view(&Id::BookmarkSavePassword, f, popup_chunks[1]); + } + } fn render_host_bridge_input_mask( &mut self, @@ -302,13 +239,7 @@ impl AuthActivity { area: tuirealm::ratatui::layout::Rect, ) { let protocol_and_mask_chunks = Layout::default() - .constraints( - [ - Constraint::Length(3), // protocol - Constraint::Length(12), // Input mask - ] - .as_ref(), - ) + .constraints([Constraint::Length(3), Constraint::Length(12)].as_ref()) .direction(Direction::Vertical) .split(area); @@ -321,55 +252,30 @@ impl AuthActivity { let input_mask = Layout::default() .constraints( [ - Constraint::Length(3), // uri - Constraint::Length(3), // username - Constraint::Length(3), // password - Constraint::Length(3), // dir + Constraint::Length(3), + Constraint::Length(3), + Constraint::Length(3), + Constraint::Length(3), ] .as_ref(), ) .direction(Direction::Vertical) .split(protocol_and_mask_chunks[1]); - // Render input mask match self.host_bridge_input_mask() { - InputMask::AwsS3 => { - let view_ids = self.get_host_bridge_s3_view(); - self.app.view(&view_ids[0], f, input_mask[0]); - self.app.view(&view_ids[1], f, input_mask[1]); - self.app.view(&view_ids[2], f, input_mask[2]); - self.app.view(&view_ids[3], f, input_mask[3]); - } + InputMask::AwsS3 => self.render_view_ids(f, input_mask, self.get_host_bridge_s3_view()), InputMask::Generic => { - let view_ids = self.get_host_bridge_generic_params_view(); - self.app.view(&view_ids[0], f, input_mask[0]); - self.app.view(&view_ids[1], f, input_mask[1]); - self.app.view(&view_ids[2], f, input_mask[2]); - self.app.view(&view_ids[3], f, input_mask[3]); + self.render_view_ids(f, input_mask, self.get_host_bridge_generic_params_view()) } InputMask::Kube => { - let view_ids = self.get_host_bridge_kube_view(); - self.app.view(&view_ids[0], f, input_mask[0]); - self.app.view(&view_ids[1], f, input_mask[1]); - self.app.view(&view_ids[2], f, input_mask[2]); - self.app.view(&view_ids[3], f, input_mask[3]); + self.render_view_ids(f, input_mask, self.get_host_bridge_kube_view()) } InputMask::Localhost => { let view_ids = self.get_host_bridge_localhost_view(); self.app.view(&view_ids[0], f, input_mask[0]); } - InputMask::Smb => { - let view_ids = self.get_host_bridge_smb_view(); - self.app.view(&view_ids[0], f, input_mask[0]); - self.app.view(&view_ids[1], f, input_mask[1]); - self.app.view(&view_ids[2], f, input_mask[2]); - self.app.view(&view_ids[3], f, input_mask[3]); - } + InputMask::Smb => self.render_view_ids(f, input_mask, self.get_host_bridge_smb_view()), InputMask::WebDAV => { - let view_ids = self.get_host_bridge_webdav_view(); - self.app.view(&view_ids[0], f, input_mask[0]); - self.app.view(&view_ids[1], f, input_mask[1]); - self.app.view(&view_ids[2], f, input_mask[2]); - self.app.view(&view_ids[3], f, input_mask[3]); + self.render_view_ids(f, input_mask, self.get_host_bridge_webdav_view()) } } } @@ -380,13 +286,7 @@ impl AuthActivity { area: tuirealm::ratatui::layout::Rect, ) { let protocol_and_mask_chunks = Layout::default() - .constraints( - [ - Constraint::Length(3), // protocol - Constraint::Length(12), // Input mask - ] - .as_ref(), - ) + .constraints([Constraint::Length(3), Constraint::Length(12)].as_ref()) .direction(Direction::Vertical) .split(area); @@ -399,1619 +299,36 @@ impl AuthActivity { let input_mask = Layout::default() .constraints( [ - Constraint::Length(3), // uri - Constraint::Length(3), // username - Constraint::Length(3), // password - Constraint::Length(3), // dir + Constraint::Length(3), + Constraint::Length(3), + Constraint::Length(3), + Constraint::Length(3), ] .as_ref(), ) .direction(Direction::Vertical) .split(protocol_and_mask_chunks[1]); - // Render input mask match self.remote_input_mask() { - InputMask::AwsS3 => { - let view_ids = self.get_remote_s3_view(); - self.app.view(&view_ids[0], f, input_mask[0]); - self.app.view(&view_ids[1], f, input_mask[1]); - self.app.view(&view_ids[2], f, input_mask[2]); - self.app.view(&view_ids[3], f, input_mask[3]); - } + InputMask::AwsS3 => self.render_view_ids(f, input_mask, self.get_remote_s3_view()), InputMask::Generic => { - let view_ids = self.get_remote_generic_params_view(); - self.app.view(&view_ids[0], f, input_mask[0]); - self.app.view(&view_ids[1], f, input_mask[1]); - self.app.view(&view_ids[2], f, input_mask[2]); - self.app.view(&view_ids[3], f, input_mask[3]); - } - InputMask::Kube => { - let view_ids = self.get_remote_kube_view(); - self.app.view(&view_ids[0], f, input_mask[0]); - self.app.view(&view_ids[1], f, input_mask[1]); - self.app.view(&view_ids[2], f, input_mask[2]); - self.app.view(&view_ids[3], f, input_mask[3]); + self.render_view_ids(f, input_mask, self.get_remote_generic_params_view()) } + InputMask::Kube => self.render_view_ids(f, input_mask, self.get_remote_kube_view()), InputMask::Localhost => unreachable!(), - InputMask::Smb => { - let view_ids = self.get_remote_smb_view(); - self.app.view(&view_ids[0], f, input_mask[0]); - self.app.view(&view_ids[1], f, input_mask[1]); - self.app.view(&view_ids[2], f, input_mask[2]); - self.app.view(&view_ids[3], f, input_mask[3]); - } - InputMask::WebDAV => { - let view_ids = self.get_remote_webdav_view(); - self.app.view(&view_ids[0], f, input_mask[0]); - self.app.view(&view_ids[1], f, input_mask[1]); - self.app.view(&view_ids[2], f, input_mask[2]); - self.app.view(&view_ids[3], f, input_mask[3]); - } + InputMask::Smb => self.render_view_ids(f, input_mask, self.get_remote_smb_view()), + InputMask::WebDAV => self.render_view_ids(f, input_mask, self.get_remote_webdav_view()), } } - /// Make text span from bookmarks - pub(super) fn view_bookmarks(&mut self) { - let bookmarks: Vec = self - .bookmarks_list - .iter() - .map(|x| { - Self::fmt_bookmark(x, self.bookmarks_client().unwrap().get_bookmark(x).unwrap()) - }) - .collect(); - let bookmarks_color = self.theme().auth_bookmarks; - if let Err(err) = self.app.remount( - Id::BookmarksList, - Box::new(components::BookmarksList::new(&bookmarks, bookmarks_color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - /// View recent connections - pub(super) fn view_recent_connections(&mut self) { - let bookmarks: Vec = self - .recents_list - .iter() - .map(|x| Self::fmt_recent(self.bookmarks_client().unwrap().get_recent(x).unwrap())) - .collect(); - let recents_color = self.theme().auth_recents; - if let Err(err) = self.app.remount( - Id::RecentsList, - Box::new(components::RecentsList::new(&bookmarks, recents_color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - // -- mount - - /// Mount error box - pub(super) fn mount_error>(&mut self, text: S) { - let err_color = self.theme().misc_error_dialog; - if let Err(err) = self.app.remount( - Id::ErrorPopup, - Box::new(components::ErrorPopup::new(text, err_color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - if let Err(err) = self.app.active(&Id::ErrorPopup) { - error!("Failed to activate component: {err}"); - } - } - - /// Umount error message - pub(super) fn umount_error(&mut self) { - let _ = self.app.umount(&Id::ErrorPopup); - } - - /// Mount info box - pub(super) fn mount_info>(&mut self, text: S) { - let color = self.theme().misc_info_dialog; - if let Err(err) = self.app.remount( - Id::InfoPopup, - Box::new(components::InfoPopup::new(text, color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - if let Err(err) = self.app.active(&Id::InfoPopup) { - error!("Failed to activate component: {err}"); - } - } - - /// Umount info message - pub(super) fn umount_info(&mut self) { - let _ = self.app.umount(&Id::InfoPopup); - } - - /// Mount wait box - pub(super) fn mount_wait(&mut self, text: &str) { - let wait_color = self.theme().misc_info_dialog; - if let Err(err) = self.app.remount( - Id::WaitPopup, - Box::new(components::WaitPopup::new(text, wait_color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - if let Err(err) = self.app.active(&Id::WaitPopup) { - error!("Failed to activate component: {err}"); - } - } - - /// Umount wait message - pub(super) fn umount_wait(&mut self) { - let _ = self.app.umount(&Id::WaitPopup); - } - - /// Mount size error - pub(super) fn mount_size_err(&mut self) { - // Mount - if let Err(err) = self.app.remount( - Id::WindowSizeError, - Box::new(components::WindowSizeError::new(Color::Red)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - if let Err(err) = self.app.active(&Id::WindowSizeError) { - error!("Failed to activate component: {err}"); - } - } - - /// Umount error size error - pub(super) fn umount_size_err(&mut self) { - let _ = self.app.umount(&Id::WindowSizeError); - } - - /// Mount quit popup - pub(super) fn mount_quit(&mut self) { - // Protocol - let quit_color = self.theme().misc_quit_dialog; - if let Err(err) = self.app.remount( - Id::QuitPopup, - Box::new(components::QuitPopup::new(quit_color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - if let Err(err) = self.app.active(&Id::QuitPopup) { - error!("Failed to activate component: {err}"); - } - } - - /// Umount quit popup - pub(super) fn umount_quit(&mut self) { - let _ = self.app.umount(&Id::QuitPopup); - } - - /// Mount bookmark delete dialog - pub(super) fn mount_bookmark_del_dialog(&mut self) { - let warn_color = self.theme().misc_warn_dialog; - if let Err(err) = self.app.remount( - Id::DeleteBookmarkPopup, - Box::new(components::DeleteBookmarkPopup::new(warn_color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - if let Err(err) = self.app.active(&Id::DeleteBookmarkPopup) { - error!("Failed to activate component: {err}"); - } - } - - /// umount delete bookmark dialog - pub(super) fn umount_bookmark_del_dialog(&mut self) { - let _ = self.app.umount(&Id::DeleteBookmarkPopup); - } - - /// Mount recent delete dialog - pub(super) fn mount_recent_del_dialog(&mut self) { - let warn_color = self.theme().misc_warn_dialog; - if let Err(err) = self.app.remount( - Id::DeleteRecentPopup, - Box::new(components::DeleteRecentPopup::new(warn_color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - if let Err(err) = self.app.active(&Id::DeleteRecentPopup) { - error!("Failed to activate component: {err}"); - } - } - - /// umount delete recent dialog - pub(super) fn umount_recent_del_dialog(&mut self) { - let _ = self.app.umount(&Id::DeleteRecentPopup); - } - - /// Mount bookmark save dialog - pub(super) fn mount_bookmark_save_dialog(&mut self, form_tab: FormTab) { - let save_color = self.theme().misc_save_dialog; - let warn_color = self.theme().misc_warn_dialog; - if let Err(err) = self.app.remount( - Id::BookmarkName, - Box::new(components::BookmarkName::new(form_tab, save_color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - if let Err(err) = self.app.remount( - Id::BookmarkSavePassword, - Box::new(components::BookmarkSavePassword::new(form_tab, warn_color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - // Give focus to input bookmark name - if let Err(err) = self.app.active(&Id::BookmarkName) { - error!("Failed to activate component: {err}"); - } - } - - /// Umount bookmark save dialog - pub(super) fn umount_bookmark_save_dialog(&mut self) { - let _ = self.app.umount(&Id::BookmarkName); - let _ = self.app.umount(&Id::BookmarkSavePassword); - } - - /// Mount keybindings - pub(super) fn mount_keybindings(&mut self) { - let key_color = self.theme().misc_keys; - if let Err(err) = self.app.remount( - Id::Keybindings, - Box::new(components::Keybindings::new(key_color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - // Active help - if let Err(err) = self.app.active(&Id::Keybindings) { - error!("Failed to activate component: {err}"); - } - } - - /// Umount help - pub(super) fn umount_help(&mut self) { - let _ = self.app.umount(&Id::Keybindings); - } - - /// mount release notes text area - pub(super) fn mount_release_notes(&mut self) { - if let Some(ctx) = self.context.as_ref() - && let Some(release_notes) = ctx.store().get_string(super::STORE_KEY_RELEASE_NOTES) - { - // make spans - let info_color = self.theme().misc_info_dialog; - if let Err(err) = self.app.remount( - Id::NewVersionChangelog, - Box::new(components::ReleaseNotes::new(release_notes, info_color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - if let Err(err) = self.app.remount( - Id::InstallUpdatePopup, - Box::new(components::InstallUpdatePopup::new(info_color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - if let Err(err) = self.app.active(&Id::InstallUpdatePopup) { - error!("Failed to activate component: {err}"); - } - } - } - - /// Umount release notes text area - pub(super) fn umount_release_notes(&mut self) { - let _ = self.app.umount(&Id::NewVersionChangelog); - let _ = self.app.umount(&Id::InstallUpdatePopup); - } - - pub(super) fn mount_host_bridge_protocol(&mut self, protocol: HostBridgeProtocol) { - let protocol_color = self.theme().auth_protocol; - if let Err(err) = self.app.remount( - Id::HostBridge(AuthFormId::Protocol), - Box::new(components::HostBridgeProtocolRadio::new( - protocol, - protocol_color, - )), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_remote_protocol(&mut self, protocol: FileTransferProtocol) { - let protocol_color = self.theme().auth_protocol; - if let Err(err) = self.app.remount( - Id::Remote(AuthFormId::Protocol), - Box::new(components::RemoteProtocolRadio::new( - protocol, - protocol_color, - )), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_remote_directory>( + fn render_view_ids( &mut self, - form_tab: FormTab, - remote_path: S, + f: &mut tuirealm::ratatui::Frame<'_>, + input_mask: std::rc::Rc<[tuirealm::ratatui::layout::Rect]>, + view_ids: [Id; 4], ) { - let id = Self::form_tab_id(form_tab, AuthFormId::RemoteDirectory); - let protocol_color = self.theme().auth_protocol; - if let Err(err) = self.app.remount( - id, - Box::new(components::InputRemoteDirectory::new( - remote_path.as_ref(), - form_tab, - protocol_color, - )), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_local_directory>( - &mut self, - form_tab: FormTab, - local_path: S, - ) { - let id = Self::form_tab_id(form_tab, AuthFormId::LocalDirectory); - let color = self.theme().auth_username; - if let Err(err) = self.app.remount( - id, - Box::new(components::InputLocalDirectory::new( - local_path.as_ref(), - form_tab, - color, - )), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_address(&mut self, form_tab: FormTab, address: &str) { - let addr_color = self.theme().auth_address; - let id = Self::form_tab_id(form_tab, AuthFormId::Address); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputAddress::new(address, form_tab, addr_color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_port(&mut self, form_tab: FormTab, port: u16) { - let port_color = self.theme().auth_port; - let id = Self::form_tab_id(form_tab, AuthFormId::Port); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputPort::new(port, form_tab, port_color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_username(&mut self, form_tab: FormTab, username: &str) { - let username_color = self.theme().auth_username; - let id = Self::form_tab_id(form_tab, AuthFormId::Username); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputUsername::new( - username, - form_tab, - username_color, - )), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_password(&mut self, form_tab: FormTab, password: &str) { - let password_color = self.theme().auth_password; - let id = Self::form_tab_id(form_tab, AuthFormId::Password); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputPassword::new( - password, - form_tab, - password_color, - )), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_s3_bucket(&mut self, form_tab: FormTab, bucket: &str) { - let addr_color = self.theme().auth_address; - let id = Self::form_tab_id(form_tab, AuthFormId::S3Bucket); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputS3Bucket::new(bucket, form_tab, addr_color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_s3_region(&mut self, form_tab: FormTab, region: &str) { - let port_color = self.theme().auth_port; - let id = Self::form_tab_id(form_tab, AuthFormId::S3Region); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputS3Region::new(region, form_tab, port_color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_s3_endpoint(&mut self, form_tab: FormTab, endpoint: &str) { - let username_color = self.theme().auth_username; - let id = Self::form_tab_id(form_tab, AuthFormId::S3Endpoint); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputS3Endpoint::new( - endpoint, - form_tab, - username_color, - )), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_s3_profile(&mut self, form_tab: FormTab, profile: &str) { - let color = self.theme().auth_password; - let id = Self::form_tab_id(form_tab, AuthFormId::S3Profile); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputS3Profile::new(profile, form_tab, color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_s3_access_key(&mut self, form_tab: FormTab, key: &str) { - let color = self.theme().auth_address; - let id = Self::form_tab_id(form_tab, AuthFormId::S3AccessKey); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputS3AccessKey::new(key, form_tab, color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_s3_secret_access_key(&mut self, form_tab: FormTab, key: &str) { - let color = self.theme().auth_port; - let id = Self::form_tab_id(form_tab, AuthFormId::S3SecretAccessKey); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputS3SecretAccessKey::new( - key, form_tab, color, - )), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_s3_security_token(&mut self, form_tab: FormTab, token: &str) { - let color = self.theme().auth_username; - let id = Self::form_tab_id(form_tab, AuthFormId::S3SecurityToken); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputS3SecurityToken::new( - token, form_tab, color, - )), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_s3_session_token(&mut self, form_tab: FormTab, token: &str) { - let color = self.theme().auth_password; - let id = Self::form_tab_id(form_tab, AuthFormId::S3SessionToken); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputS3SessionToken::new(token, form_tab, color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_s3_new_path_style(&mut self, form_tab: FormTab, new_path_style: bool) { - let color = self.theme().auth_address; - let id = Self::form_tab_id(form_tab, AuthFormId::S3NewPathStyle); - if let Err(err) = self.app.remount( - id, - Box::new(components::RadioS3NewPathStyle::new( - new_path_style, - form_tab, - color, - )), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_kube_namespace(&mut self, form_tab: FormTab, value: &str) { - let color = self.theme().auth_port; - let id = Self::form_tab_id(form_tab, AuthFormId::KubeNamespace); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputKubeNamespace::new(value, form_tab, color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_kube_cluster_url(&mut self, form_tab: FormTab, value: &str) { - let color = self.theme().auth_username; - let id = Self::form_tab_id(form_tab, AuthFormId::KubeClusterUrl); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputKubeClusterUrl::new(value, form_tab, color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_kube_username(&mut self, form_tab: FormTab, value: &str) { - let color = self.theme().auth_password; - let id = Self::form_tab_id(form_tab, AuthFormId::KubeUsername); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputKubeUsername::new(value, form_tab, color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_kube_client_cert(&mut self, form_tab: FormTab, value: &str) { - let color = self.theme().auth_address; - let id = Self::form_tab_id(form_tab, AuthFormId::KubeClientCert); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputKubeClientCert::new(value, form_tab, color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_kube_client_key(&mut self, form_tab: FormTab, value: &str) { - let color = self.theme().auth_port; - let id = Self::form_tab_id(form_tab, AuthFormId::KubeClientKey); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputKubeClientKey::new(value, form_tab, color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_smb_share(&mut self, form_tab: FormTab, share: &str) { - let color = self.theme().auth_password; - let id = Self::form_tab_id(form_tab, AuthFormId::SmbShare); - - if let Err(err) = self.app.remount( - id, - Box::new(components::InputSmbShare::new(share, form_tab, color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - #[cfg(posix)] - pub(super) fn mount_smb_workgroup(&mut self, form_tab: FormTab, workgroup: &str) { - let color = self.theme().auth_address; - let id = Self::form_tab_id(form_tab, AuthFormId::SmbWorkgroup); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputSmbWorkgroup::new( - workgroup, form_tab, color, - )), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - pub(super) fn mount_webdav_uri(&mut self, form_tab: FormTab, uri: &str) { - let addr_color = self.theme().auth_address; - let id = Self::form_tab_id(form_tab, AuthFormId::WebDAVUri); - if let Err(err) = self.app.remount( - id, - Box::new(components::InputWebDAVUri::new(uri, form_tab, addr_color)), - vec![], - ) { - error!("Failed to remount component: {err}"); - } - } - - fn form_tab_id(form_tab: FormTab, id: AuthFormId) -> Id { - match form_tab { - FormTab::HostBridge => Id::HostBridge(id), - FormTab::Remote => Id::Remote(id), - } - } - - // -- query - - /// Collect input values from view - pub(super) fn get_generic_params_input(&self, form_tab: FormTab) -> GenericProtocolParams { - let addr: String = self.get_input_addr(form_tab); - let port: u16 = self.get_input_port(form_tab); - let username = self.get_input_username(form_tab); - let password = self.get_input_password(form_tab); - GenericProtocolParams::default() - .address(addr) - .port(port) - .username(username) - .password(password) - } - - /// Collect s3 input values from view - pub(super) fn get_s3_params_input(&self, form_tab: FormTab) -> AwsS3Params { - let bucket: String = self.get_input_s3_bucket(form_tab); - let region: Option = self.get_input_s3_region(form_tab); - let endpoint = self.get_input_s3_endpoint(form_tab); - let profile: Option = self.get_input_s3_profile(form_tab); - let access_key = self.get_input_s3_access_key(form_tab); - let secret_access_key = self.get_input_s3_secret_access_key(form_tab); - let security_token = self.get_input_s3_security_token(form_tab); - let session_token = self.get_input_s3_session_token(form_tab); - let new_path_style = self.get_input_s3_new_path_style(form_tab); - AwsS3Params::new(bucket, region, profile) - .endpoint(endpoint) - .access_key(access_key) - .secret_access_key(secret_access_key) - .security_token(security_token) - .session_token(session_token) - .new_path_style(new_path_style) - } - - /// Collect s3 input values from view - pub(super) fn get_kube_params_input(&self, form_tab: FormTab) -> KubeProtocolParams { - let namespace = self.get_input_kube_namespace(form_tab); - let cluster_url = self.get_input_kube_cluster_url(form_tab); - let username = self.get_input_kube_username(form_tab); - let client_cert = self.get_input_kube_client_cert(form_tab); - let client_key = self.get_input_kube_client_key(form_tab); - KubeProtocolParams { - namespace, - cluster_url, - username, - client_cert, - client_key, - } - } - - /// Collect s3 input values from view - #[cfg(posix)] - pub(super) fn get_smb_params_input(&self, form_tab: FormTab) -> SmbParams { - let share: String = self.get_input_smb_share(form_tab); - let workgroup: Option = self.get_input_smb_workgroup(form_tab); - - let address: String = self.get_input_addr(form_tab); - let port: u16 = self.get_input_port(form_tab); - let username = self.get_input_username(form_tab); - let password = self.get_input_password(form_tab); - - SmbParams::new(address, share) - .port(port) - .username(username) - .password(password) - .workgroup(workgroup) - } - - #[cfg(win)] - pub(super) fn get_smb_params_input(&self, form_tab: FormTab) -> SmbParams { - let share: String = self.get_input_smb_share(form_tab); - - let address: String = self.get_input_addr(form_tab); - let username = self.get_input_username(form_tab); - let password = self.get_input_password(form_tab); - - SmbParams::new(address, share) - .username(username) - .password(password) - } - - pub(super) fn get_webdav_params_input(&self, form_tab: FormTab) -> WebDAVProtocolParams { - let uri: String = self.get_webdav_uri(form_tab); - let username = self.get_input_username(form_tab).unwrap_or_default(); - let password = self.get_input_password(form_tab).unwrap_or_default(); - - WebDAVProtocolParams { - uri, - username, - password, - } - } - - pub(super) fn get_input_remote_directory(&self, form_tab: FormTab) -> Option { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::RemoteDirectory)) - { - Ok(State::One(StateValue::String(x))) if !x.is_empty() => { - Some(PathBuf::from(x.as_str())) - } - _ => None, - } - } - - pub(super) fn get_input_local_directory(&self, form_tab: FormTab) -> Option { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::LocalDirectory)) - { - Ok(State::One(StateValue::String(x))) if !x.is_empty() => { - Some(PathBuf::from(x.as_str())) - } - _ => None, - } - } - - pub(super) fn get_webdav_uri(&self, form_tab: FormTab) -> String { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::WebDAVUri)) - { - Ok(State::One(StateValue::String(x))) => x, - _ => String::new(), - } - } - - pub(super) fn get_input_addr(&self, form_tab: FormTab) -> String { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::Address)) - { - Ok(State::One(StateValue::String(x))) => x, - _ => String::new(), - } - } - - pub(super) fn get_input_port(&self, form_tab: FormTab) -> u16 { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::Port)) - { - Ok(State::One(StateValue::String(x))) => u16::from_str(x.as_str()).unwrap_or_default(), - _ => 0, - } - } - - pub(super) fn get_input_username(&self, form_tab: FormTab) -> Option { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::Username)) - { - Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), - _ => None, - } - } - - pub(super) fn get_input_password(&self, form_tab: FormTab) -> Option { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::Password)) - { - Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), - _ => None, - } - } - - pub(super) fn get_input_s3_bucket(&self, form_tab: FormTab) -> String { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::S3Bucket)) - { - Ok(State::One(StateValue::String(x))) => x, - _ => String::new(), - } - } - - pub(super) fn get_input_s3_region(&self, form_tab: FormTab) -> Option { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::S3Region)) - { - Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), - _ => None, - } - } - - pub(super) fn get_input_s3_endpoint(&self, form_tab: FormTab) -> Option { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::S3Endpoint)) - { - Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), - _ => None, - } - } - - pub(super) fn get_input_s3_profile(&self, form_tab: FormTab) -> Option { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::S3Profile)) - { - Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), - _ => None, - } - } - - pub(super) fn get_input_s3_access_key(&self, form_tab: FormTab) -> Option { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::S3AccessKey)) - { - Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), - _ => None, - } - } - - pub(super) fn get_input_s3_secret_access_key(&self, form_tab: FormTab) -> Option { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::S3SecretAccessKey)) - { - Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), - _ => None, - } - } - - pub(super) fn get_input_s3_security_token(&self, form_tab: FormTab) -> Option { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::S3SecurityToken)) - { - Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), - _ => None, - } - } - - pub(super) fn get_input_s3_session_token(&self, form_tab: FormTab) -> Option { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::S3SessionToken)) - { - Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), - _ => None, - } - } - - pub(super) fn get_input_s3_new_path_style(&self, form_tab: FormTab) -> bool { - matches!( - self.app - .state(&Self::form_tab_id(form_tab, AuthFormId::S3NewPathStyle)), - Ok(State::One(StateValue::Usize(0))) - ) - } - - pub(super) fn get_input_kube_namespace(&self, form_tab: FormTab) -> Option { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::KubeNamespace)) - { - Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), - _ => None, - } - } - - pub(super) fn get_input_kube_cluster_url(&self, form_tab: FormTab) -> Option { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::KubeClusterUrl)) - { - Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), - _ => None, - } - } - - pub(super) fn get_input_kube_username(&self, form_tab: FormTab) -> Option { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::KubeUsername)) - { - Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), - _ => None, - } - } - - pub(super) fn get_input_kube_client_cert(&self, form_tab: FormTab) -> Option { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::KubeClientCert)) - { - Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), - _ => None, - } - } - - pub(super) fn get_input_kube_client_key(&self, form_tab: FormTab) -> Option { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::KubeClientKey)) - { - Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), - _ => None, - } - } - - pub(super) fn get_input_smb_share(&self, form_tab: FormTab) -> String { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::SmbShare)) - { - Ok(State::One(StateValue::String(x))) => x, - _ => String::new(), - } - } - - #[cfg(posix)] - pub(super) fn get_input_smb_workgroup(&self, form_tab: FormTab) -> Option { - match self - .app - .state(&Self::form_tab_id(form_tab, AuthFormId::SmbWorkgroup)) - { - Ok(State::One(StateValue::String(x))) => Some(x), - _ => None, - } - } - - /// Get new bookmark params - pub(super) fn get_new_bookmark(&self) -> (String, bool) { - let name = match self.app.state(&Id::BookmarkName) { - Ok(State::One(StateValue::String(name))) => name, - _ => String::default(), - }; - if matches!( - self.app.state(&Id::BookmarkSavePassword), - Ok(State::One(StateValue::Usize(0))) - ) { - (name, true) - } else { - (name, false) - } - } - - // -- len - - /// Returns the max input mask size based on current input mask - fn max_input_mask_size(&self) -> u16 { - Self::input_mask_size(self.host_bridge_input_mask()) - .max(Self::input_mask_size(self.remote_input_mask())) - + 3 // +3 because of protocol - } - - /// Get the input mask size based on input mask - fn input_mask_size(input_mask: InputMask) -> u16 { - match input_mask { - InputMask::AwsS3 => 12, - InputMask::Generic => 12, - InputMask::Kube => 12, - InputMask::Localhost => 3, - InputMask::Smb => 12, - InputMask::WebDAV => 12, - } - } - - // -- fmt - - /// Format bookmark to display on ui - fn fmt_bookmark(name: &str, b: FileTransferParams) -> String { - let addr: String = Self::fmt_recent(b); - format!("{name} ({addr})") - } - - /// Format recent connection to display on ui - fn fmt_recent(b: FileTransferParams) -> String { - let protocol: String = b.protocol.to_string().to_lowercase(); - match b.params { - ProtocolParams::AwsS3(s3) => { - let profile: String = match s3.profile { - Some(p) => format!("[{p}]"), - None => String::default(), - }; - format!( - "{}://{}{} ({}) {}", - protocol, - s3.endpoint.unwrap_or_default(), - s3.bucket_name, - s3.region.as_deref().unwrap_or("custom"), - profile - ) - } - ProtocolParams::Generic(params) => { - let username: String = match params.username { - None => String::default(), - Some(u) => format!("{u}@"), - }; - format!( - "{}://{}{}:{}", - protocol, username, params.address, params.port - ) - } - ProtocolParams::Kube(params) => { - format!( - "{}://{}{}", - protocol, - params - .namespace - .as_deref() - .map(|x| format!("/{x}")) - .unwrap_or_else(|| String::from("default")), - params - .cluster_url - .as_deref() - .map(|x| format!("@{x}")) - .unwrap_or_default() - ) - } - #[cfg(posix)] - ProtocolParams::Smb(params) => { - let username: String = match params.username { - None => String::default(), - Some(u) => format!("{u}@"), - }; - format!( - "\\\\{username}{}:{}\\{}", - params.address, params.port, params.share - ) - } - #[cfg(win)] - ProtocolParams::Smb(params) => { - let username: String = match params.username { - None => String::default(), - Some(u) => format!("{u}@"), - }; - format!("\\\\{username}{}\\{}", params.address, params.share) - } - ProtocolParams::WebDAV(params) => params.uri, - } - } - - /// Get the visible element in the generic params form, based on current focus - fn get_host_bridge_generic_params_view(&self) -> [Id; 4] { - match self.app.focus() { - Some(&Id::HostBridge(AuthFormId::RemoteDirectory)) => [ - Id::HostBridge(AuthFormId::Port), - Id::HostBridge(AuthFormId::Username), - Id::HostBridge(AuthFormId::Password), - Id::HostBridge(AuthFormId::RemoteDirectory), - ], - Some(&Id::HostBridge(AuthFormId::LocalDirectory)) => [ - Id::HostBridge(AuthFormId::Username), - Id::HostBridge(AuthFormId::Password), - Id::HostBridge(AuthFormId::RemoteDirectory), - Id::HostBridge(AuthFormId::LocalDirectory), - ], - _ => [ - Id::HostBridge(AuthFormId::Address), - Id::HostBridge(AuthFormId::Port), - Id::HostBridge(AuthFormId::Username), - Id::HostBridge(AuthFormId::Password), - ], - } - } - - /// Get the visible element in the generic params form, based on current focus - fn get_remote_generic_params_view(&self) -> [Id; 4] { - match self.app.focus() { - Some(&Id::Remote(AuthFormId::RemoteDirectory)) => [ - Id::Remote(AuthFormId::Port), - Id::Remote(AuthFormId::Username), - Id::Remote(AuthFormId::Password), - Id::Remote(AuthFormId::RemoteDirectory), - ], - Some(&Id::Remote(AuthFormId::LocalDirectory)) => [ - Id::Remote(AuthFormId::Username), - Id::Remote(AuthFormId::Password), - Id::Remote(AuthFormId::RemoteDirectory), - Id::Remote(AuthFormId::LocalDirectory), - ], - _ => [ - Id::Remote(AuthFormId::Address), - Id::Remote(AuthFormId::Port), - Id::Remote(AuthFormId::Username), - Id::Remote(AuthFormId::Password), - ], - } - } - - fn get_host_bridge_localhost_view(&self) -> [Id; 1] { - [Id::HostBridge(AuthFormId::LocalDirectory)] - } - - /// Get the visible element in the aws-s3 form, based on current focus - fn get_host_bridge_s3_view(&self) -> [Id; 4] { - match self.app.focus() { - Some(&Id::HostBridge(AuthFormId::S3AccessKey)) => [ - Id::HostBridge(AuthFormId::S3Region), - Id::HostBridge(AuthFormId::S3Endpoint), - Id::HostBridge(AuthFormId::S3Profile), - Id::HostBridge(AuthFormId::S3AccessKey), - ], - Some(&Id::HostBridge(AuthFormId::S3SecretAccessKey)) => [ - Id::HostBridge(AuthFormId::S3Endpoint), - Id::HostBridge(AuthFormId::S3Profile), - Id::HostBridge(AuthFormId::S3AccessKey), - Id::HostBridge(AuthFormId::S3SecretAccessKey), - ], - Some(&Id::HostBridge(AuthFormId::S3SecurityToken)) => [ - Id::HostBridge(AuthFormId::S3Profile), - Id::HostBridge(AuthFormId::S3AccessKey), - Id::HostBridge(AuthFormId::S3SecretAccessKey), - Id::HostBridge(AuthFormId::S3SecurityToken), - ], - Some(&Id::HostBridge(AuthFormId::S3SessionToken)) => [ - Id::HostBridge(AuthFormId::S3AccessKey), - Id::HostBridge(AuthFormId::S3SecretAccessKey), - Id::HostBridge(AuthFormId::S3SecurityToken), - Id::HostBridge(AuthFormId::S3SessionToken), - ], - Some(&Id::HostBridge(AuthFormId::S3NewPathStyle)) => [ - Id::HostBridge(AuthFormId::S3SecretAccessKey), - Id::HostBridge(AuthFormId::S3SecurityToken), - Id::HostBridge(AuthFormId::S3SessionToken), - Id::HostBridge(AuthFormId::S3NewPathStyle), - ], - Some(&Id::HostBridge(AuthFormId::RemoteDirectory)) => [ - Id::HostBridge(AuthFormId::S3SecurityToken), - Id::HostBridge(AuthFormId::S3SessionToken), - Id::HostBridge(AuthFormId::S3NewPathStyle), - Id::HostBridge(AuthFormId::RemoteDirectory), - ], - Some(&Id::HostBridge(AuthFormId::LocalDirectory)) => [ - Id::HostBridge(AuthFormId::S3SessionToken), - Id::HostBridge(AuthFormId::S3NewPathStyle), - Id::HostBridge(AuthFormId::RemoteDirectory), - Id::HostBridge(AuthFormId::LocalDirectory), - ], - _ => [ - Id::HostBridge(AuthFormId::S3Bucket), - Id::HostBridge(AuthFormId::S3Region), - Id::HostBridge(AuthFormId::S3Endpoint), - Id::HostBridge(AuthFormId::S3Profile), - ], - } - } - - /// Get the visible element in the aws-s3 form, based on current focus - fn get_remote_s3_view(&self) -> [Id; 4] { - match self.app.focus() { - Some(&Id::Remote(AuthFormId::S3AccessKey)) => [ - Id::Remote(AuthFormId::S3Region), - Id::Remote(AuthFormId::S3Endpoint), - Id::Remote(AuthFormId::S3Profile), - Id::Remote(AuthFormId::S3AccessKey), - ], - Some(&Id::Remote(AuthFormId::S3SecretAccessKey)) => [ - Id::Remote(AuthFormId::S3Endpoint), - Id::Remote(AuthFormId::S3Profile), - Id::Remote(AuthFormId::S3AccessKey), - Id::Remote(AuthFormId::S3SecretAccessKey), - ], - Some(&Id::Remote(AuthFormId::S3SecurityToken)) => [ - Id::Remote(AuthFormId::S3Profile), - Id::Remote(AuthFormId::S3AccessKey), - Id::Remote(AuthFormId::S3SecretAccessKey), - Id::Remote(AuthFormId::S3SecurityToken), - ], - Some(&Id::Remote(AuthFormId::S3SessionToken)) => [ - Id::Remote(AuthFormId::S3AccessKey), - Id::Remote(AuthFormId::S3SecretAccessKey), - Id::Remote(AuthFormId::S3SecurityToken), - Id::Remote(AuthFormId::S3SessionToken), - ], - Some(&Id::Remote(AuthFormId::S3NewPathStyle)) => [ - Id::Remote(AuthFormId::S3SecretAccessKey), - Id::Remote(AuthFormId::S3SecurityToken), - Id::Remote(AuthFormId::S3SessionToken), - Id::Remote(AuthFormId::S3NewPathStyle), - ], - Some(&Id::Remote(AuthFormId::RemoteDirectory)) => [ - Id::Remote(AuthFormId::S3SecurityToken), - Id::Remote(AuthFormId::S3SessionToken), - Id::Remote(AuthFormId::S3NewPathStyle), - Id::Remote(AuthFormId::RemoteDirectory), - ], - Some(&Id::Remote(AuthFormId::LocalDirectory)) => [ - Id::Remote(AuthFormId::S3SessionToken), - Id::Remote(AuthFormId::S3NewPathStyle), - Id::Remote(AuthFormId::RemoteDirectory), - Id::Remote(AuthFormId::LocalDirectory), - ], - _ => [ - Id::Remote(AuthFormId::S3Bucket), - Id::Remote(AuthFormId::S3Region), - Id::Remote(AuthFormId::S3Endpoint), - Id::Remote(AuthFormId::S3Profile), - ], - } - } - - /// Get the visible element in the kube form, based on current focus - fn get_host_bridge_kube_view(&self) -> [Id; 4] { - match self.app.focus() { - Some(&Id::HostBridge(AuthFormId::KubeClientCert)) => [ - Id::HostBridge(AuthFormId::KubeNamespace), - Id::HostBridge(AuthFormId::KubeClusterUrl), - Id::HostBridge(AuthFormId::KubeUsername), - Id::HostBridge(AuthFormId::KubeClientCert), - ], - Some(&Id::HostBridge(AuthFormId::KubeClientKey)) => [ - Id::HostBridge(AuthFormId::KubeClusterUrl), - Id::HostBridge(AuthFormId::KubeUsername), - Id::HostBridge(AuthFormId::KubeClientCert), - Id::HostBridge(AuthFormId::KubeClientKey), - ], - Some(&Id::HostBridge(AuthFormId::RemoteDirectory)) => [ - Id::HostBridge(AuthFormId::KubeUsername), - Id::HostBridge(AuthFormId::KubeClientCert), - Id::HostBridge(AuthFormId::KubeClientKey), - Id::HostBridge(AuthFormId::RemoteDirectory), - ], - Some(&Id::HostBridge(AuthFormId::LocalDirectory)) => [ - Id::HostBridge(AuthFormId::KubeClientCert), - Id::HostBridge(AuthFormId::KubeClientKey), - Id::HostBridge(AuthFormId::RemoteDirectory), - Id::HostBridge(AuthFormId::LocalDirectory), - ], - _ => [ - Id::HostBridge(AuthFormId::KubeNamespace), - Id::HostBridge(AuthFormId::KubeClusterUrl), - Id::HostBridge(AuthFormId::KubeUsername), - Id::HostBridge(AuthFormId::KubeClientCert), - ], - } - } - - /// Get the visible element in the kube form, based on current focus - fn get_remote_kube_view(&self) -> [Id; 4] { - match self.app.focus() { - Some(&Id::Remote(AuthFormId::KubeClientCert)) => [ - Id::Remote(AuthFormId::KubeNamespace), - Id::Remote(AuthFormId::KubeClusterUrl), - Id::Remote(AuthFormId::KubeUsername), - Id::Remote(AuthFormId::KubeClientCert), - ], - Some(&Id::Remote(AuthFormId::KubeClientKey)) => [ - Id::Remote(AuthFormId::KubeClusterUrl), - Id::Remote(AuthFormId::KubeUsername), - Id::Remote(AuthFormId::KubeClientCert), - Id::Remote(AuthFormId::KubeClientKey), - ], - Some(&Id::Remote(AuthFormId::RemoteDirectory)) => [ - Id::Remote(AuthFormId::KubeUsername), - Id::Remote(AuthFormId::KubeClientCert), - Id::Remote(AuthFormId::KubeClientKey), - Id::Remote(AuthFormId::RemoteDirectory), - ], - Some(&Id::Remote(AuthFormId::LocalDirectory)) => [ - Id::Remote(AuthFormId::KubeClientCert), - Id::Remote(AuthFormId::KubeClientKey), - Id::Remote(AuthFormId::RemoteDirectory), - Id::Remote(AuthFormId::LocalDirectory), - ], - _ => [ - Id::Remote(AuthFormId::KubeNamespace), - Id::Remote(AuthFormId::KubeClusterUrl), - Id::Remote(AuthFormId::KubeUsername), - Id::Remote(AuthFormId::KubeClientCert), - ], - } - } - - #[cfg(posix)] - fn get_host_bridge_smb_view(&self) -> [Id; 4] { - match self.app.focus() { - Some( - &Id::HostBridge(AuthFormId::Address) - | &Id::HostBridge(AuthFormId::Port) - | &Id::HostBridge(AuthFormId::SmbShare) - | &Id::HostBridge(AuthFormId::Username), - ) => [ - Id::HostBridge(AuthFormId::Address), - Id::HostBridge(AuthFormId::Port), - Id::HostBridge(AuthFormId::SmbShare), - Id::HostBridge(AuthFormId::Username), - ], - Some(&Id::HostBridge(AuthFormId::Password)) => [ - Id::HostBridge(AuthFormId::Port), - Id::HostBridge(AuthFormId::SmbShare), - Id::HostBridge(AuthFormId::Username), - Id::HostBridge(AuthFormId::Password), - ], - Some(&Id::HostBridge(AuthFormId::SmbWorkgroup)) => [ - Id::HostBridge(AuthFormId::SmbShare), - Id::HostBridge(AuthFormId::Username), - Id::HostBridge(AuthFormId::Password), - Id::HostBridge(AuthFormId::SmbWorkgroup), - ], - Some(&Id::HostBridge(AuthFormId::RemoteDirectory)) => [ - Id::HostBridge(AuthFormId::Username), - Id::HostBridge(AuthFormId::Password), - Id::HostBridge(AuthFormId::SmbWorkgroup), - Id::HostBridge(AuthFormId::RemoteDirectory), - ], - Some(&Id::HostBridge(AuthFormId::LocalDirectory)) => [ - Id::HostBridge(AuthFormId::Password), - Id::HostBridge(AuthFormId::SmbWorkgroup), - Id::HostBridge(AuthFormId::RemoteDirectory), - Id::HostBridge(AuthFormId::LocalDirectory), - ], - _ => [ - Id::HostBridge(AuthFormId::Address), - Id::HostBridge(AuthFormId::Port), - Id::HostBridge(AuthFormId::SmbShare), - Id::HostBridge(AuthFormId::Username), - ], - } - } - - #[cfg(posix)] - fn get_remote_smb_view(&self) -> [Id; 4] { - match self.app.focus() { - Some( - &Id::Remote(AuthFormId::Address) - | &Id::Remote(AuthFormId::Port) - | &Id::Remote(AuthFormId::SmbShare) - | &Id::Remote(AuthFormId::Username), - ) => [ - Id::Remote(AuthFormId::Address), - Id::Remote(AuthFormId::Port), - Id::Remote(AuthFormId::SmbShare), - Id::Remote(AuthFormId::Username), - ], - Some(&Id::Remote(AuthFormId::Password)) => [ - Id::Remote(AuthFormId::Port), - Id::Remote(AuthFormId::SmbShare), - Id::Remote(AuthFormId::Username), - Id::Remote(AuthFormId::Password), - ], - Some(&Id::Remote(AuthFormId::SmbWorkgroup)) => [ - Id::Remote(AuthFormId::SmbShare), - Id::Remote(AuthFormId::Username), - Id::Remote(AuthFormId::Password), - Id::Remote(AuthFormId::SmbWorkgroup), - ], - Some(&Id::Remote(AuthFormId::RemoteDirectory)) => [ - Id::Remote(AuthFormId::Username), - Id::Remote(AuthFormId::Password), - Id::Remote(AuthFormId::SmbWorkgroup), - Id::Remote(AuthFormId::RemoteDirectory), - ], - Some(&Id::Remote(AuthFormId::LocalDirectory)) => [ - Id::Remote(AuthFormId::Password), - Id::Remote(AuthFormId::SmbWorkgroup), - Id::Remote(AuthFormId::RemoteDirectory), - Id::Remote(AuthFormId::LocalDirectory), - ], - _ => [ - Id::Remote(AuthFormId::Address), - Id::Remote(AuthFormId::Port), - Id::Remote(AuthFormId::SmbShare), - Id::Remote(AuthFormId::Username), - ], - } - } - - #[cfg(win)] - fn get_host_bridge_smb_view(&self) -> [Id; 4] { - match self.app.focus() { - Some( - &Id::HostBridge(AuthFormId::Address) - | &Id::HostBridge(AuthFormId::Password) - | &Id::HostBridge(AuthFormId::SmbShare) - | &Id::HostBridge(AuthFormId::Username), - ) => [ - Id::HostBridge(AuthFormId::Address), - Id::HostBridge(AuthFormId::SmbShare), - Id::HostBridge(AuthFormId::Username), - Id::HostBridge(AuthFormId::Password), - ], - Some(&Id::HostBridge(AuthFormId::RemoteDirectory)) => [ - Id::HostBridge(AuthFormId::SmbShare), - Id::HostBridge(AuthFormId::Username), - Id::HostBridge(AuthFormId::Password), - Id::HostBridge(AuthFormId::RemoteDirectory), - ], - Some(&Id::HostBridge(AuthFormId::LocalDirectory)) => [ - Id::HostBridge(AuthFormId::Username), - Id::HostBridge(AuthFormId::Password), - Id::HostBridge(AuthFormId::RemoteDirectory), - Id::HostBridge(AuthFormId::LocalDirectory), - ], - _ => [ - Id::HostBridge(AuthFormId::Address), - Id::HostBridge(AuthFormId::SmbShare), - Id::HostBridge(AuthFormId::Username), - Id::HostBridge(AuthFormId::Password), - ], - } - } - - #[cfg(win)] - fn get_remote_smb_view(&self) -> [Id; 4] { - match self.app.focus() { - Some( - &Id::Remote(AuthFormId::Address) - | &Id::Remote(AuthFormId::Password) - | &Id::Remote(AuthFormId::SmbShare) - | &Id::Remote(AuthFormId::Username), - ) => [ - Id::Remote(AuthFormId::Address), - Id::Remote(AuthFormId::SmbShare), - Id::Remote(AuthFormId::Username), - Id::Remote(AuthFormId::Password), - ], - Some(&Id::Remote(AuthFormId::RemoteDirectory)) => [ - Id::Remote(AuthFormId::SmbShare), - Id::Remote(AuthFormId::Username), - Id::Remote(AuthFormId::Password), - Id::Remote(AuthFormId::RemoteDirectory), - ], - Some(&Id::Remote(AuthFormId::LocalDirectory)) => [ - Id::Remote(AuthFormId::Username), - Id::Remote(AuthFormId::Password), - Id::Remote(AuthFormId::RemoteDirectory), - Id::Remote(AuthFormId::LocalDirectory), - ], - _ => [ - Id::Remote(AuthFormId::Address), - Id::Remote(AuthFormId::SmbShare), - Id::Remote(AuthFormId::Username), - Id::Remote(AuthFormId::Password), - ], - } - } - - fn get_host_bridge_webdav_view(&self) -> [Id; 4] { - match self.app.focus() { - Some(&Id::HostBridge(AuthFormId::LocalDirectory)) => [ - Id::HostBridge(AuthFormId::Username), - Id::HostBridge(AuthFormId::Password), - Id::HostBridge(AuthFormId::RemoteDirectory), - Id::HostBridge(AuthFormId::LocalDirectory), - ], - _ => [ - Id::HostBridge(AuthFormId::WebDAVUri), - Id::HostBridge(AuthFormId::Username), - Id::HostBridge(AuthFormId::Password), - Id::HostBridge(AuthFormId::RemoteDirectory), - ], - } - } - - fn get_remote_webdav_view(&self) -> [Id; 4] { - match self.app.focus() { - Some(&Id::Remote(AuthFormId::LocalDirectory)) => [ - Id::Remote(AuthFormId::Username), - Id::Remote(AuthFormId::Password), - Id::Remote(AuthFormId::RemoteDirectory), - Id::Remote(AuthFormId::LocalDirectory), - ], - _ => [ - Id::Remote(AuthFormId::WebDAVUri), - Id::Remote(AuthFormId::Username), - Id::Remote(AuthFormId::Password), - Id::Remote(AuthFormId::RemoteDirectory), - ], - } - } - - fn init_global_listener(&mut self) { - use tuirealm::event::{Key, KeyEvent, KeyModifiers}; - if let Err(err) = self.app.mount( - Id::GlobalListener, - Box::::default(), - vec![ - Sub::new( - SubEventClause::Keyboard(KeyEvent { - code: Key::Esc, - modifiers: KeyModifiers::NONE, - }), - Self::no_popup_mounted_clause(), - ), - Sub::new( - SubEventClause::Keyboard(KeyEvent { - code: Key::Function(10), - modifiers: KeyModifiers::NONE, - }), - Self::no_popup_mounted_clause(), - ), - Sub::new( - SubEventClause::Keyboard(KeyEvent { - code: Key::Char('c'), - modifiers: KeyModifiers::CONTROL, - }), - Self::no_popup_mounted_clause(), - ), - Sub::new( - SubEventClause::Keyboard(KeyEvent { - code: Key::Char('h'), - modifiers: KeyModifiers::CONTROL, - }), - Self::no_popup_mounted_clause(), - ), - Sub::new( - SubEventClause::Keyboard(KeyEvent { - code: Key::Function(1), - modifiers: KeyModifiers::NONE, - }), - Self::no_popup_mounted_clause(), - ), - Sub::new( - SubEventClause::Keyboard(KeyEvent { - code: Key::Char('r'), - modifiers: KeyModifiers::CONTROL, - }), - Self::no_popup_mounted_clause(), - ), - Sub::new( - SubEventClause::Keyboard(KeyEvent { - code: Key::Char('s'), - modifiers: KeyModifiers::CONTROL, - }), - Self::no_popup_mounted_clause(), - ), - Sub::new(SubEventClause::WindowResize, SubClause::Always), - ], - ) { - error!("Failed to mount component: {err}"); - } - } - - pub(super) fn get_current_form_tab(&self) -> FormTab { - match self.app.focus() { - Some(&Id::HostBridge(_)) => FormTab::HostBridge, - _ => FormTab::Remote, - } - } - - /// Returns a sub clause which requires that no popup is mounted in order to be satisfied - fn no_popup_mounted_clause() -> SubClause { - tuirealm::subclause_and_not!( - Id::ErrorPopup, - Id::InfoPopup, - Id::Keybindings, - Id::DeleteBookmarkPopup, - Id::DeleteRecentPopup, - Id::InstallUpdatePopup, - Id::BookmarkSavePassword, - Id::WaitPopup - ) + self.app.view(&view_ids[0], f, input_mask[0]); + self.app.view(&view_ids[1], f, input_mask[1]); + self.app.view(&view_ids[2], f, input_mask[2]); + self.app.view(&view_ids[3], f, input_mask[3]); } } diff --git a/src/ui/activities/auth/view/mounting.rs b/src/ui/activities/auth/view/mounting.rs new file mode 100644 index 0000000..af9ba12 --- /dev/null +++ b/src/ui/activities/auth/view/mounting.rs @@ -0,0 +1,679 @@ +use super::*; +use crate::ui::activities::auth::STORE_KEY_RELEASE_NOTES; + +impl AuthActivity { + /// Make text span from bookmarks + pub(in crate::ui::activities::auth) fn view_bookmarks(&mut self) { + let bookmarks: Vec = self + .bookmarks_list + .iter() + .map(|x| { + Self::fmt_bookmark(x, self.bookmarks_client().unwrap().get_bookmark(x).unwrap()) + }) + .collect(); + let bookmarks_color = self.theme().auth_bookmarks; + if let Err(err) = self.app.remount( + Id::BookmarksList, + Box::new(components::BookmarksList::new(&bookmarks, bookmarks_color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + /// View recent connections + pub(in crate::ui::activities::auth) fn view_recent_connections(&mut self) { + let bookmarks: Vec = self + .recents_list + .iter() + .map(|x| Self::fmt_recent(self.bookmarks_client().unwrap().get_recent(x).unwrap())) + .collect(); + let recents_color = self.theme().auth_recents; + if let Err(err) = self.app.remount( + Id::RecentsList, + Box::new(components::RecentsList::new(&bookmarks, recents_color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_error>(&mut self, text: S) { + let err_color = self.theme().misc_error_dialog; + if let Err(err) = self.app.remount( + Id::ErrorPopup, + Box::new(components::ErrorPopup::new(text, err_color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + if let Err(err) = self.app.active(&Id::ErrorPopup) { + error!("Failed to activate component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn umount_error(&mut self) { + let _ = self.app.umount(&Id::ErrorPopup); + } + + pub(in crate::ui::activities::auth) fn mount_info>(&mut self, text: S) { + let color = self.theme().misc_info_dialog; + if let Err(err) = self.app.remount( + Id::InfoPopup, + Box::new(components::InfoPopup::new(text, color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + if let Err(err) = self.app.active(&Id::InfoPopup) { + error!("Failed to activate component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn umount_info(&mut self) { + let _ = self.app.umount(&Id::InfoPopup); + } + + pub(in crate::ui::activities::auth) fn mount_wait(&mut self, text: &str) { + let wait_color = self.theme().misc_info_dialog; + if let Err(err) = self.app.remount( + Id::WaitPopup, + Box::new(components::WaitPopup::new(text, wait_color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + if let Err(err) = self.app.active(&Id::WaitPopup) { + error!("Failed to activate component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn umount_wait(&mut self) { + let _ = self.app.umount(&Id::WaitPopup); + } + + pub(in crate::ui::activities::auth) fn mount_size_err(&mut self) { + if let Err(err) = self.app.remount( + Id::WindowSizeError, + Box::new(components::WindowSizeError::new(Color::Red)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + if let Err(err) = self.app.active(&Id::WindowSizeError) { + error!("Failed to activate component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn umount_size_err(&mut self) { + let _ = self.app.umount(&Id::WindowSizeError); + } + + pub(in crate::ui::activities::auth) fn mount_quit(&mut self) { + let quit_color = self.theme().misc_quit_dialog; + if let Err(err) = self.app.remount( + Id::QuitPopup, + Box::new(components::QuitPopup::new(quit_color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + if let Err(err) = self.app.active(&Id::QuitPopup) { + error!("Failed to activate component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn umount_quit(&mut self) { + let _ = self.app.umount(&Id::QuitPopup); + } + + pub(in crate::ui::activities::auth) fn mount_bookmark_del_dialog(&mut self) { + let warn_color = self.theme().misc_warn_dialog; + if let Err(err) = self.app.remount( + Id::DeleteBookmarkPopup, + Box::new(components::DeleteBookmarkPopup::new(warn_color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + if let Err(err) = self.app.active(&Id::DeleteBookmarkPopup) { + error!("Failed to activate component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn umount_bookmark_del_dialog(&mut self) { + let _ = self.app.umount(&Id::DeleteBookmarkPopup); + } + + pub(in crate::ui::activities::auth) fn mount_recent_del_dialog(&mut self) { + let warn_color = self.theme().misc_warn_dialog; + if let Err(err) = self.app.remount( + Id::DeleteRecentPopup, + Box::new(components::DeleteRecentPopup::new(warn_color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + if let Err(err) = self.app.active(&Id::DeleteRecentPopup) { + error!("Failed to activate component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn umount_recent_del_dialog(&mut self) { + let _ = self.app.umount(&Id::DeleteRecentPopup); + } + + pub(in crate::ui::activities::auth) fn mount_bookmark_save_dialog( + &mut self, + form_tab: FormTab, + ) { + let save_color = self.theme().misc_save_dialog; + let warn_color = self.theme().misc_warn_dialog; + if let Err(err) = self.app.remount( + Id::BookmarkName, + Box::new(components::BookmarkName::new(form_tab, save_color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + if let Err(err) = self.app.remount( + Id::BookmarkSavePassword, + Box::new(components::BookmarkSavePassword::new(form_tab, warn_color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + if let Err(err) = self.app.active(&Id::BookmarkName) { + error!("Failed to activate component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn umount_bookmark_save_dialog(&mut self) { + let _ = self.app.umount(&Id::BookmarkName); + let _ = self.app.umount(&Id::BookmarkSavePassword); + } + + pub(in crate::ui::activities::auth) fn mount_keybindings(&mut self) { + let key_color = self.theme().misc_keys; + if let Err(err) = self.app.remount( + Id::Keybindings, + Box::new(components::Keybindings::new(key_color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + if let Err(err) = self.app.active(&Id::Keybindings) { + error!("Failed to activate component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn umount_help(&mut self) { + let _ = self.app.umount(&Id::Keybindings); + } + + pub(in crate::ui::activities::auth) fn mount_release_notes(&mut self) { + if let Some(ctx) = self.context.as_ref() + && let Some(release_notes) = ctx.store().get_string(STORE_KEY_RELEASE_NOTES) + { + let info_color = self.theme().misc_info_dialog; + if let Err(err) = self.app.remount( + Id::NewVersionChangelog, + Box::new(components::ReleaseNotes::new(release_notes, info_color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + if let Err(err) = self.app.remount( + Id::InstallUpdatePopup, + Box::new(components::InstallUpdatePopup::new(info_color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + if let Err(err) = self.app.active(&Id::InstallUpdatePopup) { + error!("Failed to activate component: {err}"); + } + } + } + + pub(in crate::ui::activities::auth) fn umount_release_notes(&mut self) { + let _ = self.app.umount(&Id::NewVersionChangelog); + let _ = self.app.umount(&Id::InstallUpdatePopup); + } + + pub(in crate::ui::activities::auth) fn mount_host_bridge_protocol( + &mut self, + protocol: HostBridgeProtocol, + ) { + let protocol_color = self.theme().auth_protocol; + if let Err(err) = self.app.remount( + Id::HostBridge(AuthFormId::Protocol), + Box::new(components::HostBridgeProtocolRadio::new( + protocol, + protocol_color, + )), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_remote_protocol( + &mut self, + protocol: FileTransferProtocol, + ) { + let protocol_color = self.theme().auth_protocol; + if let Err(err) = self.app.remount( + Id::Remote(AuthFormId::Protocol), + Box::new(components::RemoteProtocolRadio::new( + protocol, + protocol_color, + )), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_remote_directory>( + &mut self, + form_tab: FormTab, + remote_path: S, + ) { + let id = Self::form_tab_id(form_tab, AuthFormId::RemoteDirectory); + let protocol_color = self.theme().auth_protocol; + if let Err(err) = self.app.remount( + id, + Box::new(components::InputRemoteDirectory::new( + remote_path.as_ref(), + form_tab, + protocol_color, + )), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_local_directory>( + &mut self, + form_tab: FormTab, + local_path: S, + ) { + let id = Self::form_tab_id(form_tab, AuthFormId::LocalDirectory); + let color = self.theme().auth_username; + if let Err(err) = self.app.remount( + id, + Box::new(components::InputLocalDirectory::new( + local_path.as_ref(), + form_tab, + color, + )), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_address( + &mut self, + form_tab: FormTab, + address: &str, + ) { + let addr_color = self.theme().auth_address; + let id = Self::form_tab_id(form_tab, AuthFormId::Address); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputAddress::new(address, form_tab, addr_color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_port(&mut self, form_tab: FormTab, port: u16) { + let port_color = self.theme().auth_port; + let id = Self::form_tab_id(form_tab, AuthFormId::Port); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputPort::new(port, form_tab, port_color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_username( + &mut self, + form_tab: FormTab, + username: &str, + ) { + let username_color = self.theme().auth_username; + let id = Self::form_tab_id(form_tab, AuthFormId::Username); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputUsername::new( + username, + form_tab, + username_color, + )), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_password( + &mut self, + form_tab: FormTab, + password: &str, + ) { + let password_color = self.theme().auth_password; + let id = Self::form_tab_id(form_tab, AuthFormId::Password); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputPassword::new( + password, + form_tab, + password_color, + )), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_s3_bucket( + &mut self, + form_tab: FormTab, + bucket: &str, + ) { + let addr_color = self.theme().auth_address; + let id = Self::form_tab_id(form_tab, AuthFormId::S3Bucket); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputS3Bucket::new(bucket, form_tab, addr_color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_s3_region( + &mut self, + form_tab: FormTab, + region: &str, + ) { + let port_color = self.theme().auth_port; + let id = Self::form_tab_id(form_tab, AuthFormId::S3Region); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputS3Region::new(region, form_tab, port_color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_s3_endpoint( + &mut self, + form_tab: FormTab, + endpoint: &str, + ) { + let username_color = self.theme().auth_username; + let id = Self::form_tab_id(form_tab, AuthFormId::S3Endpoint); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputS3Endpoint::new( + endpoint, + form_tab, + username_color, + )), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_s3_profile( + &mut self, + form_tab: FormTab, + profile: &str, + ) { + let color = self.theme().auth_password; + let id = Self::form_tab_id(form_tab, AuthFormId::S3Profile); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputS3Profile::new(profile, form_tab, color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_s3_access_key( + &mut self, + form_tab: FormTab, + key: &str, + ) { + let color = self.theme().auth_address; + let id = Self::form_tab_id(form_tab, AuthFormId::S3AccessKey); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputS3AccessKey::new(key, form_tab, color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_s3_secret_access_key( + &mut self, + form_tab: FormTab, + key: &str, + ) { + let color = self.theme().auth_port; + let id = Self::form_tab_id(form_tab, AuthFormId::S3SecretAccessKey); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputS3SecretAccessKey::new( + key, form_tab, color, + )), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_s3_security_token( + &mut self, + form_tab: FormTab, + token: &str, + ) { + let color = self.theme().auth_username; + let id = Self::form_tab_id(form_tab, AuthFormId::S3SecurityToken); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputS3SecurityToken::new( + token, form_tab, color, + )), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_s3_session_token( + &mut self, + form_tab: FormTab, + token: &str, + ) { + let color = self.theme().auth_password; + let id = Self::form_tab_id(form_tab, AuthFormId::S3SessionToken); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputS3SessionToken::new(token, form_tab, color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_s3_new_path_style( + &mut self, + form_tab: FormTab, + new_path_style: bool, + ) { + let color = self.theme().auth_address; + let id = Self::form_tab_id(form_tab, AuthFormId::S3NewPathStyle); + if let Err(err) = self.app.remount( + id, + Box::new(components::RadioS3NewPathStyle::new( + new_path_style, + form_tab, + color, + )), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_kube_namespace( + &mut self, + form_tab: FormTab, + value: &str, + ) { + let color = self.theme().auth_port; + let id = Self::form_tab_id(form_tab, AuthFormId::KubeNamespace); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputKubeNamespace::new(value, form_tab, color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_kube_cluster_url( + &mut self, + form_tab: FormTab, + value: &str, + ) { + let color = self.theme().auth_username; + let id = Self::form_tab_id(form_tab, AuthFormId::KubeClusterUrl); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputKubeClusterUrl::new(value, form_tab, color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_kube_username( + &mut self, + form_tab: FormTab, + value: &str, + ) { + let color = self.theme().auth_password; + let id = Self::form_tab_id(form_tab, AuthFormId::KubeUsername); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputKubeUsername::new(value, form_tab, color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_kube_client_cert( + &mut self, + form_tab: FormTab, + value: &str, + ) { + let color = self.theme().auth_address; + let id = Self::form_tab_id(form_tab, AuthFormId::KubeClientCert); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputKubeClientCert::new(value, form_tab, color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_kube_client_key( + &mut self, + form_tab: FormTab, + value: &str, + ) { + let color = self.theme().auth_port; + let id = Self::form_tab_id(form_tab, AuthFormId::KubeClientKey); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputKubeClientKey::new(value, form_tab, color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_smb_share( + &mut self, + form_tab: FormTab, + share: &str, + ) { + let color = self.theme().auth_password; + let id = Self::form_tab_id(form_tab, AuthFormId::SmbShare); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputSmbShare::new(share, form_tab, color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + #[cfg(posix)] + pub(in crate::ui::activities::auth) fn mount_smb_workgroup( + &mut self, + form_tab: FormTab, + workgroup: &str, + ) { + let color = self.theme().auth_address; + let id = Self::form_tab_id(form_tab, AuthFormId::SmbWorkgroup); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputSmbWorkgroup::new( + workgroup, form_tab, color, + )), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn mount_webdav_uri( + &mut self, + form_tab: FormTab, + uri: &str, + ) { + let addr_color = self.theme().auth_address; + let id = Self::form_tab_id(form_tab, AuthFormId::WebDAVUri); + if let Err(err) = self.app.remount( + id, + Box::new(components::InputWebDAVUri::new(uri, form_tab, addr_color)), + vec![], + ) { + error!("Failed to remount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn form_tab_id(form_tab: FormTab, id: AuthFormId) -> Id { + match form_tab { + FormTab::HostBridge => Id::HostBridge(id), + FormTab::Remote => Id::Remote(id), + } + } +} diff --git a/src/ui/activities/auth/view/query.rs b/src/ui/activities/auth/view/query.rs new file mode 100644 index 0000000..e89ef4f --- /dev/null +++ b/src/ui/activities/auth/view/query.rs @@ -0,0 +1,510 @@ +use std::path::PathBuf; +use std::str::FromStr; + +use tuirealm::{State, StateValue}; + +use super::*; +use crate::filetransfer::FileTransferParams; +use crate::filetransfer::params::{ + AwsS3Params, GenericProtocolParams, KubeProtocolParams, ProtocolParams, SmbParams, + WebDAVProtocolParams, +}; + +impl AuthActivity { + pub(in crate::ui::activities::auth) fn get_generic_params_input( + &self, + form_tab: FormTab, + ) -> GenericProtocolParams { + let addr = self.get_input_addr(form_tab); + let port = self.get_input_port(form_tab); + let username = self.get_input_username(form_tab); + let password = self.get_input_password(form_tab); + GenericProtocolParams::default() + .address(addr) + .port(port) + .username(username) + .password(password) + } + + pub(in crate::ui::activities::auth) fn get_s3_params_input( + &self, + form_tab: FormTab, + ) -> AwsS3Params { + let bucket = self.get_input_s3_bucket(form_tab); + let region = self.get_input_s3_region(form_tab); + let endpoint = self.get_input_s3_endpoint(form_tab); + let profile = self.get_input_s3_profile(form_tab); + let access_key = self.get_input_s3_access_key(form_tab); + let secret_access_key = self.get_input_s3_secret_access_key(form_tab); + let security_token = self.get_input_s3_security_token(form_tab); + let session_token = self.get_input_s3_session_token(form_tab); + let new_path_style = self.get_input_s3_new_path_style(form_tab); + AwsS3Params::new(bucket, region, profile) + .endpoint(endpoint) + .access_key(access_key) + .secret_access_key(secret_access_key) + .security_token(security_token) + .session_token(session_token) + .new_path_style(new_path_style) + } + + pub(in crate::ui::activities::auth) fn get_kube_params_input( + &self, + form_tab: FormTab, + ) -> KubeProtocolParams { + let namespace = self.get_input_kube_namespace(form_tab); + let cluster_url = self.get_input_kube_cluster_url(form_tab); + let username = self.get_input_kube_username(form_tab); + let client_cert = self.get_input_kube_client_cert(form_tab); + let client_key = self.get_input_kube_client_key(form_tab); + KubeProtocolParams { + namespace, + cluster_url, + username, + client_cert, + client_key, + } + } + + #[cfg(posix)] + pub(in crate::ui::activities::auth) fn get_smb_params_input( + &self, + form_tab: FormTab, + ) -> SmbParams { + let share = self.get_input_smb_share(form_tab); + let workgroup = self.get_input_smb_workgroup(form_tab); + let address = self.get_input_addr(form_tab); + let port = self.get_input_port(form_tab); + let username = self.get_input_username(form_tab); + let password = self.get_input_password(form_tab); + + SmbParams::new(address, share) + .port(port) + .username(username) + .password(password) + .workgroup(workgroup) + } + + #[cfg(win)] + pub(in crate::ui::activities::auth) fn get_smb_params_input( + &self, + form_tab: FormTab, + ) -> SmbParams { + let share = self.get_input_smb_share(form_tab); + let address = self.get_input_addr(form_tab); + let username = self.get_input_username(form_tab); + let password = self.get_input_password(form_tab); + + SmbParams::new(address, share) + .username(username) + .password(password) + } + + pub(in crate::ui::activities::auth) fn get_webdav_params_input( + &self, + form_tab: FormTab, + ) -> WebDAVProtocolParams { + let uri = self.get_webdav_uri(form_tab); + let username = self.get_input_username(form_tab).unwrap_or_default(); + let password = self.get_input_password(form_tab).unwrap_or_default(); + + WebDAVProtocolParams { + uri, + username, + password, + } + } + + pub(in crate::ui::activities::auth) fn get_input_remote_directory( + &self, + form_tab: FormTab, + ) -> Option { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::RemoteDirectory)) + { + Ok(State::One(StateValue::String(x))) if !x.is_empty() => { + Some(PathBuf::from(x.as_str())) + } + _ => None, + } + } + + pub(in crate::ui::activities::auth) fn get_input_local_directory( + &self, + form_tab: FormTab, + ) -> Option { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::LocalDirectory)) + { + Ok(State::One(StateValue::String(x))) if !x.is_empty() => { + Some(PathBuf::from(x.as_str())) + } + _ => None, + } + } + + pub(in crate::ui::activities::auth) fn get_webdav_uri(&self, form_tab: FormTab) -> String { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::WebDAVUri)) + { + Ok(State::One(StateValue::String(x))) => x, + _ => String::new(), + } + } + + pub(in crate::ui::activities::auth) fn get_input_addr(&self, form_tab: FormTab) -> String { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::Address)) + { + Ok(State::One(StateValue::String(x))) => x, + _ => String::new(), + } + } + + pub(in crate::ui::activities::auth) fn get_input_port(&self, form_tab: FormTab) -> u16 { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::Port)) + { + Ok(State::One(StateValue::String(x))) => u16::from_str(x.as_str()).unwrap_or_default(), + _ => 0, + } + } + + pub(in crate::ui::activities::auth) fn get_input_username( + &self, + form_tab: FormTab, + ) -> Option { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::Username)) + { + Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), + _ => None, + } + } + + pub(in crate::ui::activities::auth) fn get_input_password( + &self, + form_tab: FormTab, + ) -> Option { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::Password)) + { + Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), + _ => None, + } + } + + pub(in crate::ui::activities::auth) fn get_input_s3_bucket(&self, form_tab: FormTab) -> String { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::S3Bucket)) + { + Ok(State::One(StateValue::String(x))) => x, + _ => String::new(), + } + } + + pub(in crate::ui::activities::auth) fn get_input_s3_region( + &self, + form_tab: FormTab, + ) -> Option { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::S3Region)) + { + Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), + _ => None, + } + } + + pub(in crate::ui::activities::auth) fn get_input_s3_endpoint( + &self, + form_tab: FormTab, + ) -> Option { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::S3Endpoint)) + { + Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), + _ => None, + } + } + + pub(in crate::ui::activities::auth) fn get_input_s3_profile( + &self, + form_tab: FormTab, + ) -> Option { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::S3Profile)) + { + Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), + _ => None, + } + } + + pub(in crate::ui::activities::auth) fn get_input_s3_access_key( + &self, + form_tab: FormTab, + ) -> Option { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::S3AccessKey)) + { + Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), + _ => None, + } + } + + pub(in crate::ui::activities::auth) fn get_input_s3_secret_access_key( + &self, + form_tab: FormTab, + ) -> Option { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::S3SecretAccessKey)) + { + Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), + _ => None, + } + } + + pub(in crate::ui::activities::auth) fn get_input_s3_security_token( + &self, + form_tab: FormTab, + ) -> Option { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::S3SecurityToken)) + { + Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), + _ => None, + } + } + + pub(in crate::ui::activities::auth) fn get_input_s3_session_token( + &self, + form_tab: FormTab, + ) -> Option { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::S3SessionToken)) + { + Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), + _ => None, + } + } + + pub(in crate::ui::activities::auth) fn get_input_s3_new_path_style( + &self, + form_tab: FormTab, + ) -> bool { + matches!( + self.app + .state(&Self::form_tab_id(form_tab, AuthFormId::S3NewPathStyle)), + Ok(State::One(StateValue::Usize(0))) + ) + } + + pub(in crate::ui::activities::auth) fn get_input_kube_namespace( + &self, + form_tab: FormTab, + ) -> Option { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::KubeNamespace)) + { + Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), + _ => None, + } + } + + pub(in crate::ui::activities::auth) fn get_input_kube_cluster_url( + &self, + form_tab: FormTab, + ) -> Option { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::KubeClusterUrl)) + { + Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), + _ => None, + } + } + + pub(in crate::ui::activities::auth) fn get_input_kube_username( + &self, + form_tab: FormTab, + ) -> Option { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::KubeUsername)) + { + Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), + _ => None, + } + } + + pub(in crate::ui::activities::auth) fn get_input_kube_client_cert( + &self, + form_tab: FormTab, + ) -> Option { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::KubeClientCert)) + { + Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), + _ => None, + } + } + + pub(in crate::ui::activities::auth) fn get_input_kube_client_key( + &self, + form_tab: FormTab, + ) -> Option { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::KubeClientKey)) + { + Ok(State::One(StateValue::String(x))) if !x.is_empty() => Some(x), + _ => None, + } + } + + pub(in crate::ui::activities::auth) fn get_input_smb_share(&self, form_tab: FormTab) -> String { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::SmbShare)) + { + Ok(State::One(StateValue::String(x))) => x, + _ => String::new(), + } + } + + #[cfg(posix)] + pub(in crate::ui::activities::auth) fn get_input_smb_workgroup( + &self, + form_tab: FormTab, + ) -> Option { + match self + .app + .state(&Self::form_tab_id(form_tab, AuthFormId::SmbWorkgroup)) + { + Ok(State::One(StateValue::String(x))) => Some(x), + _ => None, + } + } + + pub(in crate::ui::activities::auth) fn get_new_bookmark(&self) -> (String, bool) { + let name = match self.app.state(&Id::BookmarkName) { + Ok(State::One(StateValue::String(name))) => name, + _ => String::default(), + }; + if matches!( + self.app.state(&Id::BookmarkSavePassword), + Ok(State::One(StateValue::Usize(0))) + ) { + (name, true) + } else { + (name, false) + } + } + + pub(in crate::ui::activities::auth) fn max_input_mask_size(&self) -> u16 { + Self::input_mask_size(self.host_bridge_input_mask()) + .max(Self::input_mask_size(self.remote_input_mask())) + + 3 + } + + fn input_mask_size(input_mask: InputMask) -> u16 { + match input_mask { + InputMask::AwsS3 + | InputMask::Generic + | InputMask::Kube + | InputMask::Smb + | InputMask::WebDAV => 12, + InputMask::Localhost => 3, + } + } + + pub(in crate::ui::activities::auth) fn fmt_bookmark( + name: &str, + b: FileTransferParams, + ) -> String { + let addr = Self::fmt_recent(b); + format!("{name} ({addr})") + } + + pub(in crate::ui::activities::auth) fn fmt_recent(b: FileTransferParams) -> String { + let protocol = b.protocol.to_string().to_lowercase(); + match b.params { + ProtocolParams::AwsS3(s3) => { + let profile = match s3.profile { + Some(p) => format!("[{p}]"), + None => String::default(), + }; + format!( + "{}://{}{} ({}) {}", + protocol, + s3.endpoint.unwrap_or_default(), + s3.bucket_name, + s3.region.as_deref().unwrap_or("custom"), + profile + ) + } + ProtocolParams::Generic(params) => { + let username = match params.username { + None => String::default(), + Some(u) => format!("{u}@"), + }; + format!( + "{}://{}{}:{}", + protocol, username, params.address, params.port + ) + } + ProtocolParams::Kube(params) => { + format!( + "{}://{}{}", + protocol, + params + .namespace + .as_deref() + .map(|x| format!("/{x}")) + .unwrap_or_else(|| String::from("default")), + params + .cluster_url + .as_deref() + .map(|x| format!("@{x}")) + .unwrap_or_default() + ) + } + #[cfg(posix)] + ProtocolParams::Smb(params) => { + let username = match params.username { + None => String::default(), + Some(u) => format!("{u}@"), + }; + format!( + "\\\\{username}{}:{}\\{}", + params.address, params.port, params.share + ) + } + #[cfg(win)] + ProtocolParams::Smb(params) => { + let username = match params.username { + None => String::default(), + Some(u) => format!("{u}@"), + }; + format!("\\\\{username}{}\\{}", params.address, params.share) + } + ProtocolParams::WebDAV(params) => params.uri, + } + } +} diff --git a/src/ui/activities/auth/view/visible.rs b/src/ui/activities/auth/view/visible.rs new file mode 100644 index 0000000..6ddb4e5 --- /dev/null +++ b/src/ui/activities/auth/view/visible.rs @@ -0,0 +1,512 @@ +use tuirealm::{Sub, SubClause, SubEventClause}; + +use super::*; + +impl AuthActivity { + pub(in crate::ui::activities::auth) fn get_host_bridge_generic_params_view(&self) -> [Id; 4] { + match self.app.focus() { + Some(&Id::HostBridge(AuthFormId::RemoteDirectory)) => [ + Id::HostBridge(AuthFormId::Port), + Id::HostBridge(AuthFormId::Username), + Id::HostBridge(AuthFormId::Password), + Id::HostBridge(AuthFormId::RemoteDirectory), + ], + Some(&Id::HostBridge(AuthFormId::LocalDirectory)) => [ + Id::HostBridge(AuthFormId::Username), + Id::HostBridge(AuthFormId::Password), + Id::HostBridge(AuthFormId::RemoteDirectory), + Id::HostBridge(AuthFormId::LocalDirectory), + ], + _ => [ + Id::HostBridge(AuthFormId::Address), + Id::HostBridge(AuthFormId::Port), + Id::HostBridge(AuthFormId::Username), + Id::HostBridge(AuthFormId::Password), + ], + } + } + + pub(in crate::ui::activities::auth) fn get_remote_generic_params_view(&self) -> [Id; 4] { + match self.app.focus() { + Some(&Id::Remote(AuthFormId::RemoteDirectory)) => [ + Id::Remote(AuthFormId::Port), + Id::Remote(AuthFormId::Username), + Id::Remote(AuthFormId::Password), + Id::Remote(AuthFormId::RemoteDirectory), + ], + Some(&Id::Remote(AuthFormId::LocalDirectory)) => [ + Id::Remote(AuthFormId::Username), + Id::Remote(AuthFormId::Password), + Id::Remote(AuthFormId::RemoteDirectory), + Id::Remote(AuthFormId::LocalDirectory), + ], + _ => [ + Id::Remote(AuthFormId::Address), + Id::Remote(AuthFormId::Port), + Id::Remote(AuthFormId::Username), + Id::Remote(AuthFormId::Password), + ], + } + } + + pub(in crate::ui::activities::auth) fn get_host_bridge_localhost_view(&self) -> [Id; 1] { + [Id::HostBridge(AuthFormId::LocalDirectory)] + } + + pub(in crate::ui::activities::auth) fn get_host_bridge_s3_view(&self) -> [Id; 4] { + match self.app.focus() { + Some(&Id::HostBridge(AuthFormId::S3AccessKey)) => [ + Id::HostBridge(AuthFormId::S3Region), + Id::HostBridge(AuthFormId::S3Endpoint), + Id::HostBridge(AuthFormId::S3Profile), + Id::HostBridge(AuthFormId::S3AccessKey), + ], + Some(&Id::HostBridge(AuthFormId::S3SecretAccessKey)) => [ + Id::HostBridge(AuthFormId::S3Endpoint), + Id::HostBridge(AuthFormId::S3Profile), + Id::HostBridge(AuthFormId::S3AccessKey), + Id::HostBridge(AuthFormId::S3SecretAccessKey), + ], + Some(&Id::HostBridge(AuthFormId::S3SecurityToken)) => [ + Id::HostBridge(AuthFormId::S3Profile), + Id::HostBridge(AuthFormId::S3AccessKey), + Id::HostBridge(AuthFormId::S3SecretAccessKey), + Id::HostBridge(AuthFormId::S3SecurityToken), + ], + Some(&Id::HostBridge(AuthFormId::S3SessionToken)) => [ + Id::HostBridge(AuthFormId::S3AccessKey), + Id::HostBridge(AuthFormId::S3SecretAccessKey), + Id::HostBridge(AuthFormId::S3SecurityToken), + Id::HostBridge(AuthFormId::S3SessionToken), + ], + Some(&Id::HostBridge(AuthFormId::S3NewPathStyle)) => [ + Id::HostBridge(AuthFormId::S3SecretAccessKey), + Id::HostBridge(AuthFormId::S3SecurityToken), + Id::HostBridge(AuthFormId::S3SessionToken), + Id::HostBridge(AuthFormId::S3NewPathStyle), + ], + Some(&Id::HostBridge(AuthFormId::RemoteDirectory)) => [ + Id::HostBridge(AuthFormId::S3SecurityToken), + Id::HostBridge(AuthFormId::S3SessionToken), + Id::HostBridge(AuthFormId::S3NewPathStyle), + Id::HostBridge(AuthFormId::RemoteDirectory), + ], + Some(&Id::HostBridge(AuthFormId::LocalDirectory)) => [ + Id::HostBridge(AuthFormId::S3SessionToken), + Id::HostBridge(AuthFormId::S3NewPathStyle), + Id::HostBridge(AuthFormId::RemoteDirectory), + Id::HostBridge(AuthFormId::LocalDirectory), + ], + _ => [ + Id::HostBridge(AuthFormId::S3Bucket), + Id::HostBridge(AuthFormId::S3Region), + Id::HostBridge(AuthFormId::S3Endpoint), + Id::HostBridge(AuthFormId::S3Profile), + ], + } + } + + pub(in crate::ui::activities::auth) fn get_remote_s3_view(&self) -> [Id; 4] { + match self.app.focus() { + Some(&Id::Remote(AuthFormId::S3AccessKey)) => [ + Id::Remote(AuthFormId::S3Region), + Id::Remote(AuthFormId::S3Endpoint), + Id::Remote(AuthFormId::S3Profile), + Id::Remote(AuthFormId::S3AccessKey), + ], + Some(&Id::Remote(AuthFormId::S3SecretAccessKey)) => [ + Id::Remote(AuthFormId::S3Endpoint), + Id::Remote(AuthFormId::S3Profile), + Id::Remote(AuthFormId::S3AccessKey), + Id::Remote(AuthFormId::S3SecretAccessKey), + ], + Some(&Id::Remote(AuthFormId::S3SecurityToken)) => [ + Id::Remote(AuthFormId::S3Profile), + Id::Remote(AuthFormId::S3AccessKey), + Id::Remote(AuthFormId::S3SecretAccessKey), + Id::Remote(AuthFormId::S3SecurityToken), + ], + Some(&Id::Remote(AuthFormId::S3SessionToken)) => [ + Id::Remote(AuthFormId::S3AccessKey), + Id::Remote(AuthFormId::S3SecretAccessKey), + Id::Remote(AuthFormId::S3SecurityToken), + Id::Remote(AuthFormId::S3SessionToken), + ], + Some(&Id::Remote(AuthFormId::S3NewPathStyle)) => [ + Id::Remote(AuthFormId::S3SecretAccessKey), + Id::Remote(AuthFormId::S3SecurityToken), + Id::Remote(AuthFormId::S3SessionToken), + Id::Remote(AuthFormId::S3NewPathStyle), + ], + Some(&Id::Remote(AuthFormId::RemoteDirectory)) => [ + Id::Remote(AuthFormId::S3SecurityToken), + Id::Remote(AuthFormId::S3SessionToken), + Id::Remote(AuthFormId::S3NewPathStyle), + Id::Remote(AuthFormId::RemoteDirectory), + ], + Some(&Id::Remote(AuthFormId::LocalDirectory)) => [ + Id::Remote(AuthFormId::S3SessionToken), + Id::Remote(AuthFormId::S3NewPathStyle), + Id::Remote(AuthFormId::RemoteDirectory), + Id::Remote(AuthFormId::LocalDirectory), + ], + _ => [ + Id::Remote(AuthFormId::S3Bucket), + Id::Remote(AuthFormId::S3Region), + Id::Remote(AuthFormId::S3Endpoint), + Id::Remote(AuthFormId::S3Profile), + ], + } + } + + pub(in crate::ui::activities::auth) fn get_host_bridge_kube_view(&self) -> [Id; 4] { + match self.app.focus() { + Some(&Id::HostBridge(AuthFormId::KubeClientCert)) => [ + Id::HostBridge(AuthFormId::KubeNamespace), + Id::HostBridge(AuthFormId::KubeClusterUrl), + Id::HostBridge(AuthFormId::KubeUsername), + Id::HostBridge(AuthFormId::KubeClientCert), + ], + Some(&Id::HostBridge(AuthFormId::KubeClientKey)) => [ + Id::HostBridge(AuthFormId::KubeClusterUrl), + Id::HostBridge(AuthFormId::KubeUsername), + Id::HostBridge(AuthFormId::KubeClientCert), + Id::HostBridge(AuthFormId::KubeClientKey), + ], + Some(&Id::HostBridge(AuthFormId::RemoteDirectory)) => [ + Id::HostBridge(AuthFormId::KubeUsername), + Id::HostBridge(AuthFormId::KubeClientCert), + Id::HostBridge(AuthFormId::KubeClientKey), + Id::HostBridge(AuthFormId::RemoteDirectory), + ], + Some(&Id::HostBridge(AuthFormId::LocalDirectory)) => [ + Id::HostBridge(AuthFormId::KubeClientCert), + Id::HostBridge(AuthFormId::KubeClientKey), + Id::HostBridge(AuthFormId::RemoteDirectory), + Id::HostBridge(AuthFormId::LocalDirectory), + ], + _ => [ + Id::HostBridge(AuthFormId::KubeNamespace), + Id::HostBridge(AuthFormId::KubeClusterUrl), + Id::HostBridge(AuthFormId::KubeUsername), + Id::HostBridge(AuthFormId::KubeClientCert), + ], + } + } + + pub(in crate::ui::activities::auth) fn get_remote_kube_view(&self) -> [Id; 4] { + match self.app.focus() { + Some(&Id::Remote(AuthFormId::KubeClientCert)) => [ + Id::Remote(AuthFormId::KubeNamespace), + Id::Remote(AuthFormId::KubeClusterUrl), + Id::Remote(AuthFormId::KubeUsername), + Id::Remote(AuthFormId::KubeClientCert), + ], + Some(&Id::Remote(AuthFormId::KubeClientKey)) => [ + Id::Remote(AuthFormId::KubeClusterUrl), + Id::Remote(AuthFormId::KubeUsername), + Id::Remote(AuthFormId::KubeClientCert), + Id::Remote(AuthFormId::KubeClientKey), + ], + Some(&Id::Remote(AuthFormId::RemoteDirectory)) => [ + Id::Remote(AuthFormId::KubeUsername), + Id::Remote(AuthFormId::KubeClientCert), + Id::Remote(AuthFormId::KubeClientKey), + Id::Remote(AuthFormId::RemoteDirectory), + ], + Some(&Id::Remote(AuthFormId::LocalDirectory)) => [ + Id::Remote(AuthFormId::KubeClientCert), + Id::Remote(AuthFormId::KubeClientKey), + Id::Remote(AuthFormId::RemoteDirectory), + Id::Remote(AuthFormId::LocalDirectory), + ], + _ => [ + Id::Remote(AuthFormId::KubeNamespace), + Id::Remote(AuthFormId::KubeClusterUrl), + Id::Remote(AuthFormId::KubeUsername), + Id::Remote(AuthFormId::KubeClientCert), + ], + } + } + + #[cfg(posix)] + pub(in crate::ui::activities::auth) fn get_host_bridge_smb_view(&self) -> [Id; 4] { + match self.app.focus() { + Some( + &Id::HostBridge(AuthFormId::Address) + | &Id::HostBridge(AuthFormId::Port) + | &Id::HostBridge(AuthFormId::SmbShare) + | &Id::HostBridge(AuthFormId::Username), + ) => [ + Id::HostBridge(AuthFormId::Address), + Id::HostBridge(AuthFormId::Port), + Id::HostBridge(AuthFormId::SmbShare), + Id::HostBridge(AuthFormId::Username), + ], + Some(&Id::HostBridge(AuthFormId::Password)) => [ + Id::HostBridge(AuthFormId::Port), + Id::HostBridge(AuthFormId::SmbShare), + Id::HostBridge(AuthFormId::Username), + Id::HostBridge(AuthFormId::Password), + ], + Some(&Id::HostBridge(AuthFormId::SmbWorkgroup)) => [ + Id::HostBridge(AuthFormId::SmbShare), + Id::HostBridge(AuthFormId::Username), + Id::HostBridge(AuthFormId::Password), + Id::HostBridge(AuthFormId::SmbWorkgroup), + ], + Some(&Id::HostBridge(AuthFormId::RemoteDirectory)) => [ + Id::HostBridge(AuthFormId::Username), + Id::HostBridge(AuthFormId::Password), + Id::HostBridge(AuthFormId::SmbWorkgroup), + Id::HostBridge(AuthFormId::RemoteDirectory), + ], + Some(&Id::HostBridge(AuthFormId::LocalDirectory)) => [ + Id::HostBridge(AuthFormId::Password), + Id::HostBridge(AuthFormId::SmbWorkgroup), + Id::HostBridge(AuthFormId::RemoteDirectory), + Id::HostBridge(AuthFormId::LocalDirectory), + ], + _ => [ + Id::HostBridge(AuthFormId::Address), + Id::HostBridge(AuthFormId::Port), + Id::HostBridge(AuthFormId::SmbShare), + Id::HostBridge(AuthFormId::Username), + ], + } + } + + #[cfg(posix)] + pub(in crate::ui::activities::auth) fn get_remote_smb_view(&self) -> [Id; 4] { + match self.app.focus() { + Some( + &Id::Remote(AuthFormId::Address) + | &Id::Remote(AuthFormId::Port) + | &Id::Remote(AuthFormId::SmbShare) + | &Id::Remote(AuthFormId::Username), + ) => [ + Id::Remote(AuthFormId::Address), + Id::Remote(AuthFormId::Port), + Id::Remote(AuthFormId::SmbShare), + Id::Remote(AuthFormId::Username), + ], + Some(&Id::Remote(AuthFormId::Password)) => [ + Id::Remote(AuthFormId::Port), + Id::Remote(AuthFormId::SmbShare), + Id::Remote(AuthFormId::Username), + Id::Remote(AuthFormId::Password), + ], + Some(&Id::Remote(AuthFormId::SmbWorkgroup)) => [ + Id::Remote(AuthFormId::SmbShare), + Id::Remote(AuthFormId::Username), + Id::Remote(AuthFormId::Password), + Id::Remote(AuthFormId::SmbWorkgroup), + ], + Some(&Id::Remote(AuthFormId::RemoteDirectory)) => [ + Id::Remote(AuthFormId::Username), + Id::Remote(AuthFormId::Password), + Id::Remote(AuthFormId::SmbWorkgroup), + Id::Remote(AuthFormId::RemoteDirectory), + ], + Some(&Id::Remote(AuthFormId::LocalDirectory)) => [ + Id::Remote(AuthFormId::Password), + Id::Remote(AuthFormId::SmbWorkgroup), + Id::Remote(AuthFormId::RemoteDirectory), + Id::Remote(AuthFormId::LocalDirectory), + ], + _ => [ + Id::Remote(AuthFormId::Address), + Id::Remote(AuthFormId::Port), + Id::Remote(AuthFormId::SmbShare), + Id::Remote(AuthFormId::Username), + ], + } + } + + #[cfg(win)] + pub(in crate::ui::activities::auth) fn get_host_bridge_smb_view(&self) -> [Id; 4] { + match self.app.focus() { + Some( + &Id::HostBridge(AuthFormId::Address) + | &Id::HostBridge(AuthFormId::Password) + | &Id::HostBridge(AuthFormId::SmbShare) + | &Id::HostBridge(AuthFormId::Username), + ) => [ + Id::HostBridge(AuthFormId::Address), + Id::HostBridge(AuthFormId::SmbShare), + Id::HostBridge(AuthFormId::Username), + Id::HostBridge(AuthFormId::Password), + ], + Some(&Id::HostBridge(AuthFormId::RemoteDirectory)) => [ + Id::HostBridge(AuthFormId::SmbShare), + Id::HostBridge(AuthFormId::Username), + Id::HostBridge(AuthFormId::Password), + Id::HostBridge(AuthFormId::RemoteDirectory), + ], + Some(&Id::HostBridge(AuthFormId::LocalDirectory)) => [ + Id::HostBridge(AuthFormId::Username), + Id::HostBridge(AuthFormId::Password), + Id::HostBridge(AuthFormId::RemoteDirectory), + Id::HostBridge(AuthFormId::LocalDirectory), + ], + _ => [ + Id::HostBridge(AuthFormId::Address), + Id::HostBridge(AuthFormId::SmbShare), + Id::HostBridge(AuthFormId::Username), + Id::HostBridge(AuthFormId::Password), + ], + } + } + + #[cfg(win)] + pub(in crate::ui::activities::auth) fn get_remote_smb_view(&self) -> [Id; 4] { + match self.app.focus() { + Some( + &Id::Remote(AuthFormId::Address) + | &Id::Remote(AuthFormId::Password) + | &Id::Remote(AuthFormId::SmbShare) + | &Id::Remote(AuthFormId::Username), + ) => [ + Id::Remote(AuthFormId::Address), + Id::Remote(AuthFormId::SmbShare), + Id::Remote(AuthFormId::Username), + Id::Remote(AuthFormId::Password), + ], + Some(&Id::Remote(AuthFormId::RemoteDirectory)) => [ + Id::Remote(AuthFormId::SmbShare), + Id::Remote(AuthFormId::Username), + Id::Remote(AuthFormId::Password), + Id::Remote(AuthFormId::RemoteDirectory), + ], + Some(&Id::Remote(AuthFormId::LocalDirectory)) => [ + Id::Remote(AuthFormId::Username), + Id::Remote(AuthFormId::Password), + Id::Remote(AuthFormId::RemoteDirectory), + Id::Remote(AuthFormId::LocalDirectory), + ], + _ => [ + Id::Remote(AuthFormId::Address), + Id::Remote(AuthFormId::SmbShare), + Id::Remote(AuthFormId::Username), + Id::Remote(AuthFormId::Password), + ], + } + } + + pub(in crate::ui::activities::auth) fn get_host_bridge_webdav_view(&self) -> [Id; 4] { + match self.app.focus() { + Some(&Id::HostBridge(AuthFormId::LocalDirectory)) => [ + Id::HostBridge(AuthFormId::Username), + Id::HostBridge(AuthFormId::Password), + Id::HostBridge(AuthFormId::RemoteDirectory), + Id::HostBridge(AuthFormId::LocalDirectory), + ], + _ => [ + Id::HostBridge(AuthFormId::WebDAVUri), + Id::HostBridge(AuthFormId::Username), + Id::HostBridge(AuthFormId::Password), + Id::HostBridge(AuthFormId::RemoteDirectory), + ], + } + } + + pub(in crate::ui::activities::auth) fn get_remote_webdav_view(&self) -> [Id; 4] { + match self.app.focus() { + Some(&Id::Remote(AuthFormId::LocalDirectory)) => [ + Id::Remote(AuthFormId::Username), + Id::Remote(AuthFormId::Password), + Id::Remote(AuthFormId::RemoteDirectory), + Id::Remote(AuthFormId::LocalDirectory), + ], + _ => [ + Id::Remote(AuthFormId::WebDAVUri), + Id::Remote(AuthFormId::Username), + Id::Remote(AuthFormId::Password), + Id::Remote(AuthFormId::RemoteDirectory), + ], + } + } + + pub(in crate::ui::activities::auth) fn init_global_listener(&mut self) { + use tuirealm::event::{Key, KeyEvent, KeyModifiers}; + + if let Err(err) = self.app.mount( + Id::GlobalListener, + Box::::default(), + vec![ + Sub::new( + SubEventClause::Keyboard(KeyEvent { + code: Key::Esc, + modifiers: KeyModifiers::NONE, + }), + Self::no_popup_mounted_clause(), + ), + Sub::new( + SubEventClause::Keyboard(KeyEvent { + code: Key::Function(10), + modifiers: KeyModifiers::NONE, + }), + Self::no_popup_mounted_clause(), + ), + Sub::new( + SubEventClause::Keyboard(KeyEvent { + code: Key::Char('c'), + modifiers: KeyModifiers::CONTROL, + }), + Self::no_popup_mounted_clause(), + ), + Sub::new( + SubEventClause::Keyboard(KeyEvent { + code: Key::Char('h'), + modifiers: KeyModifiers::CONTROL, + }), + Self::no_popup_mounted_clause(), + ), + Sub::new( + SubEventClause::Keyboard(KeyEvent { + code: Key::Function(1), + modifiers: KeyModifiers::NONE, + }), + Self::no_popup_mounted_clause(), + ), + Sub::new( + SubEventClause::Keyboard(KeyEvent { + code: Key::Char('r'), + modifiers: KeyModifiers::CONTROL, + }), + Self::no_popup_mounted_clause(), + ), + Sub::new( + SubEventClause::Keyboard(KeyEvent { + code: Key::Char('s'), + modifiers: KeyModifiers::CONTROL, + }), + Self::no_popup_mounted_clause(), + ), + Sub::new(SubEventClause::WindowResize, SubClause::Always), + ], + ) { + error!("Failed to mount component: {err}"); + } + } + + pub(in crate::ui::activities::auth) fn get_current_form_tab(&self) -> FormTab { + match self.app.focus() { + Some(&Id::HostBridge(_)) => FormTab::HostBridge, + _ => FormTab::Remote, + } + } + + fn no_popup_mounted_clause() -> SubClause { + tuirealm::subclause_and_not!( + Id::ErrorPopup, + Id::InfoPopup, + Id::Keybindings, + Id::DeleteBookmarkPopup, + Id::DeleteRecentPopup, + Id::InstallUpdatePopup, + Id::BookmarkSavePassword, + Id::WaitPopup + ) + } +}