mirror of
https://github.com/veeso/termscp.git
synced 2025-12-07 09:36:00 -08:00
Read default protocol in auth activity
This commit is contained in:
@@ -38,10 +38,13 @@ extern crate unicode_width;
|
|||||||
use super::{Activity, Context};
|
use super::{Activity, Context};
|
||||||
use crate::filetransfer::FileTransferProtocol;
|
use crate::filetransfer::FileTransferProtocol;
|
||||||
use crate::system::bookmarks_client::BookmarksClient;
|
use crate::system::bookmarks_client::BookmarksClient;
|
||||||
|
use crate::system::config_client::ConfigClient;
|
||||||
|
use crate::system::environment;
|
||||||
|
|
||||||
// Includes
|
// Includes
|
||||||
use crossterm::event::Event as InputEvent;
|
use crossterm::event::Event as InputEvent;
|
||||||
use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
|
use crossterm::terminal::{disable_raw_mode, enable_raw_mode};
|
||||||
|
use std::path::PathBuf;
|
||||||
use tui::style::Color;
|
use tui::style::Color;
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
@@ -112,6 +115,7 @@ pub struct AuthActivity {
|
|||||||
pub setup: bool, // Becomes true if user has requested setup
|
pub setup: bool, // Becomes true if user has requested setup
|
||||||
context: Option<Context>,
|
context: Option<Context>,
|
||||||
bookmarks_client: Option<BookmarksClient>,
|
bookmarks_client: Option<BookmarksClient>,
|
||||||
|
config_client: Option<ConfigClient>,
|
||||||
selected_field: InputField, // Selected field in AuthCredentials Form
|
selected_field: InputField, // Selected field in AuthCredentials Form
|
||||||
input_mode: InputMode,
|
input_mode: InputMode,
|
||||||
input_form: InputForm,
|
input_form: InputForm,
|
||||||
@@ -145,6 +149,7 @@ impl AuthActivity {
|
|||||||
setup: false,
|
setup: false,
|
||||||
context: None,
|
context: None,
|
||||||
bookmarks_client: None,
|
bookmarks_client: None,
|
||||||
|
config_client: None,
|
||||||
selected_field: InputField::Address,
|
selected_field: InputField::Address,
|
||||||
input_mode: InputMode::Form,
|
input_mode: InputMode::Form,
|
||||||
input_form: InputForm::AuthCredentials,
|
input_form: InputForm::AuthCredentials,
|
||||||
@@ -156,6 +161,42 @@ impl AuthActivity {
|
|||||||
recents_idx: 0,
|
recents_idx: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ### init_config_client
|
||||||
|
///
|
||||||
|
/// Initialize config client
|
||||||
|
fn init_config_client(&mut self) {
|
||||||
|
// Get config dir
|
||||||
|
match environment::init_config_dir() {
|
||||||
|
Ok(config_dir) => {
|
||||||
|
if let Some(config_dir) = config_dir {
|
||||||
|
// Get config client paths
|
||||||
|
let (config_path, ssh_dir): (PathBuf, PathBuf) =
|
||||||
|
environment::get_config_paths(config_dir.as_path());
|
||||||
|
match ConfigClient::new(config_path.as_path(), ssh_dir.as_path()) {
|
||||||
|
Ok(cli) => {
|
||||||
|
// Set default protocol
|
||||||
|
self.protocol = cli.get_default_protcol();
|
||||||
|
// Set client
|
||||||
|
self.config_client = Some(cli);
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
self.input_mode = InputMode::Popup(PopupType::Alert(
|
||||||
|
Color::Red,
|
||||||
|
format!("Could not initialize user configuration: {}", err),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
self.input_mode = InputMode::Popup(PopupType::Alert(
|
||||||
|
Color::Red,
|
||||||
|
format!("Could not initialize configuration directory: {}", err),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Activity for AuthActivity {
|
impl Activity for AuthActivity {
|
||||||
@@ -176,6 +217,10 @@ impl Activity for AuthActivity {
|
|||||||
if self.bookmarks_client.is_none() {
|
if self.bookmarks_client.is_none() {
|
||||||
self.init_bookmarks_client();
|
self.init_bookmarks_client();
|
||||||
}
|
}
|
||||||
|
// init config client
|
||||||
|
if self.config_client.is_none() {
|
||||||
|
self.init_config_client();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ### on_draw
|
/// ### on_draw
|
||||||
|
|||||||
Reference in New Issue
Block a user