From e468ae57976924558734133f4fa4c77576dae906 Mon Sep 17 00:00:00 2001 From: Kingtous Date: Tue, 7 Jun 2022 11:25:34 +0800 Subject: [PATCH] fix: cli compilation error when using cli feature --- src/cli.rs | 11 ++++++++--- src/client/file_trait.rs | 6 +++--- src/common.rs | 19 +++++++++++++++++++ src/main.rs | 5 +++-- src/mobile.rs | 20 +------------------- src/mobile_ffi.rs | 3 ++- 6 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 5aebea432..59c356a5a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -21,7 +21,7 @@ impl Session { pub fn new(id: &str, sender: mpsc::UnboundedSender) -> Self { let mut password = "".to_owned(); if PeerConfig::load(id).password.is_empty() { - password = rpassword::read_password_from_tty(Some("Enter password: ")).unwrap(); + password = rpassword::prompt_password("Enter password: ").unwrap(); } let session = Self { id: id.to_owned(), @@ -47,7 +47,7 @@ impl Interface for Session { .ok(); } else if msgtype == "re-input-password" { log::error!("{}: {}", title, text); - let pass = rpassword::read_password_from_tty(Some("Enter password: ")).unwrap(); + let pass = rpassword::prompt_password("Enter password: ").unwrap(); self.sender.send(Data::Login((pass, true))).ok(); } else if msgtype.contains("error") { log::error!("{}: {}: {}", msgtype, title, text); @@ -76,6 +76,10 @@ impl Interface for Session { async fn handle_test_delay(&mut self, t: TestDelay, peer: &mut Stream) { handle_test_delay(t, peer).await; } + + fn send(&self, data: Data) { + self.sender.send(data).ok(); + } } #[tokio::main(flavor = "current_thread")] @@ -85,6 +89,7 @@ pub async fn start_one_port_forward( remote_host: String, remote_port: i32, key: String, + token: String, ) { crate::common::test_rendezvous_server(); crate::common::test_nat_type(); @@ -92,7 +97,7 @@ pub async fn start_one_port_forward( let handler = Session::new(&id, sender); handler.lc.write().unwrap().port_forward = (remote_host, remote_port); if let Err(err) = - crate::port_forward::listen(handler.id.clone(), port, handler.clone(), receiver, &key).await + crate::port_forward::listen(handler.id.clone(), port, handler.clone(), receiver, &key, &token).await { log::error!("Failed to listen on {}: {}", port, err); } diff --git a/src/client/file_trait.rs b/src/client/file_trait.rs index be790b035..9d107edb8 100644 --- a/src/client/file_trait.rs +++ b/src/client/file_trait.rs @@ -9,7 +9,7 @@ pub trait FileManager: Interface { fs::get_home_as_string() } - #[cfg(not(any(target_os = "android", target_os = "ios")))] + #[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))] fn read_dir(&self,path: String, include_hidden: bool) -> sciter::Value { match fs::read_dir(&fs::get_path(&path), include_hidden) { Err(_) => sciter::Value::null(), @@ -22,9 +22,9 @@ pub trait FileManager: Interface { } } - #[cfg(any(target_os = "android", target_os = "ios"))] + #[cfg(any(target_os = "android", target_os = "ios", feature = "cli"))] fn read_dir(&self,path: &str, include_hidden: bool) -> String { - use crate::mobile::make_fd_to_json; + use crate::common::make_fd_to_json; match fs::read_dir(&fs::get_path(path), include_hidden){ Ok(fd) => make_fd_to_json(fd), Err(_)=>"".into() diff --git a/src/common.rs b/src/common.rs index dac98fb76..39503ace6 100644 --- a/src/common.rs +++ b/src/common.rs @@ -605,3 +605,22 @@ pub fn make_privacy_mode_msg(state: back_notification::PrivacyModeState) -> Mess msg_out.set_misc(misc); msg_out } + +pub fn make_fd_to_json(fd: FileDirectory) -> String { + use serde_json::json; + let mut fd_json = serde_json::Map::new(); + fd_json.insert("id".into(), json!(fd.id)); + fd_json.insert("path".into(), json!(fd.path)); + + let mut entries = vec![]; + for entry in fd.entries { + let mut entry_map = serde_json::Map::new(); + entry_map.insert("entry_type".into(), json!(entry.entry_type.value())); + entry_map.insert("name".into(), json!(entry.name)); + entry_map.insert("size".into(), json!(entry.size)); + entry_map.insert("modified_time".into(), json!(entry.modified_time)); + entries.push(entry_map); + } + fd_json.insert("entries".into(), json!(entries)); + serde_json::to_string(&fd_json).unwrap_or("".into()) +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index f6156ff30..8a5b5717a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -186,7 +186,7 @@ fn main() { .about("RustDesk command line tool") .args_from_usage(&args) .get_matches(); - use hbb_common::env_logger::*; + use hbb_common::{env_logger::*, config::LocalConfig}; init_from_env(Env::default().filter_or(DEFAULT_FILTER_ENV, "info")); if let Some(p) = matches.value_of("port-forward") { let options: Vec = p.split(":").map(|x| x.to_owned()).collect(); @@ -213,6 +213,7 @@ fn main() { remote_host = options[3].clone(); } let key = matches.value_of("key").unwrap_or("").to_owned(); - cli::start_one_port_forward(options[0].clone(), port, remote_host, remote_port, key); + let token = LocalConfig::get_option("access_token"); + cli::start_one_port_forward(options[0].clone(), port, remote_host, remote_port, key, token); } } diff --git a/src/mobile.rs b/src/mobile.rs index 200c0b24d..fe02513a0 100644 --- a/src/mobile.rs +++ b/src/mobile.rs @@ -1,4 +1,5 @@ use crate::client::*; +use crate::common::{make_fd_to_json}; use flutter_rust_bridge::{StreamSink, ZeroCopyBuffer}; use hbb_common::{ allow_err, @@ -1144,25 +1145,6 @@ impl Connection { } } -pub fn make_fd_to_json(fd: FileDirectory) -> String { - use serde_json::json; - let mut fd_json = serde_json::Map::new(); - fd_json.insert("id".into(), json!(fd.id)); - fd_json.insert("path".into(), json!(fd.path)); - - let mut entries = vec![]; - for entry in fd.entries { - let mut entry_map = serde_json::Map::new(); - entry_map.insert("entry_type".into(), json!(entry.entry_type.value())); - entry_map.insert("name".into(), json!(entry.name)); - entry_map.insert("size".into(), json!(entry.size)); - entry_map.insert("modified_time".into(), json!(entry.modified_time)); - entries.push(entry_map); - } - fd_json.insert("entries".into(), json!(entries)); - serde_json::to_string(&fd_json).unwrap_or("".into()) -} - // Server Side // TODO connection_manager need use struct and trait,impl default method #[cfg(target_os = "android")] diff --git a/src/mobile_ffi.rs b/src/mobile_ffi.rs index 2d1b90e7c..6a0b71a5e 100644 --- a/src/mobile_ffi.rs +++ b/src/mobile_ffi.rs @@ -1,6 +1,7 @@ use crate::client::file_trait::FileManager; use crate::mobile::connection_manager::{self, get_clients_length, get_clients_state}; -use crate::mobile::{self, make_fd_to_json, Session}; +use crate::mobile::{self, Session}; +use crate::common::{make_fd_to_json}; use flutter_rust_bridge::{StreamSink, ZeroCopyBuffer}; use hbb_common::ResultType; use hbb_common::{