Merge pull request #1419 from Heap-Hop/refactor_desktop_remote_code

Refactor desktop remote.rs flutter.rs
This commit is contained in:
RustDesk 2022-09-01 18:56:52 +08:00 committed by GitHub
commit 027ffbb405
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 2858 additions and 4009 deletions

View File

@ -325,6 +325,7 @@ class FfiModel with ChangeNotifier {
}
if (evt['is_file_transfer'] == "true") {
// TODO is file transfer
parent.target?.fileModel.onReady();
} else {
_pi.displays = [];

View File

@ -2,7 +2,7 @@ use std::{
collections::HashMap,
net::SocketAddr,
ops::{Deref, Not},
sync::{mpsc, Arc, Mutex, RwLock},
sync::{atomic::AtomicBool, mpsc, Arc, Mutex, RwLock},
};
pub use async_trait::async_trait;
@ -37,7 +37,6 @@ use hbb_common::{
};
pub use helper::LatencyController;
pub use helper::*;
use scrap::Image;
use scrap::{
codec::{Decoder, DecoderCfg},
VpxDecoderConfig, VpxVideoCodecId,
@ -47,7 +46,12 @@ pub use super::lang::*;
pub mod file_trait;
pub mod helper;
pub mod io_loop;
pub static SERVER_KEYBOARD_ENABLED: AtomicBool = AtomicBool::new(true);
pub static SERVER_FILE_TRANSFER_ENABLED: AtomicBool = AtomicBool::new(true);
pub static SERVER_CLIPBOARD_ENABLED: AtomicBool = AtomicBool::new(true);
pub const MILLI1: Duration = Duration::from_millis(1);
pub const SEC30: Duration = Duration::from_secs(30);
/// Client of the remote desktop.
@ -55,7 +59,22 @@ pub struct Client;
#[cfg(not(any(target_os = "android", target_os = "linux")))]
lazy_static::lazy_static! {
static ref AUDIO_HOST: Host = cpal::default_host();
static ref AUDIO_HOST: Host = cpal::default_host();
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
lazy_static::lazy_static! {
static ref ENIGO: Arc<Mutex<enigo::Enigo>> = Arc::new(Mutex::new(enigo::Enigo::new()));
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn get_key_state(key: enigo::Key) -> bool {
use enigo::KeyboardControllable;
#[cfg(target_os = "macos")]
if key == enigo::Key::NumLock {
return true;
}
ENIGO.lock().unwrap().get_key_state(key)
}
cfg_if::cfg_if! {
@ -846,8 +865,7 @@ impl VideoHandler {
#[derive(Default)]
pub struct LoginConfigHandler {
id: String,
pub is_file_transfer: bool,
pub is_port_forward: bool,
pub conn_type: ConnType,
hash: Hash,
password: Vec<u8>, // remember password for reconnect
pub remember: bool,
@ -886,12 +904,10 @@ impl LoginConfigHandler {
/// # Arguments
///
/// * `id` - id of peer
/// * `is_file_transfer` - Whether the connection is file transfer.
/// * `is_port_forward` - Whether the connection is port forward.
pub fn initialize(&mut self, id: String, is_file_transfer: bool, is_port_forward: bool) {
/// * `conn_type` - Connection type enum.
pub fn initialize(&mut self, id: String, conn_type: ConnType) {
self.id = id;
self.is_file_transfer = is_file_transfer;
self.is_port_forward = is_port_forward;
self.conn_type = conn_type;
let config = self.load_config();
self.remember = !config.password.is_empty();
self.config = config;
@ -1048,7 +1064,8 @@ impl LoginConfigHandler {
///
/// * `ignore_default` - If `true`, ignore the default value of the option.
fn get_option_message(&self, ignore_default: bool) -> Option<OptionMessage> {
if self.is_port_forward || self.is_file_transfer {
if self.conn_type.eq(&ConnType::FILE_TRANSFER) || self.conn_type.eq(&ConnType::PORT_FORWARD)
{
return None;
}
let mut n = 0;
@ -1094,7 +1111,8 @@ impl LoginConfigHandler {
}
pub fn get_option_message_after_login(&self) -> Option<OptionMessage> {
if self.is_port_forward || self.is_file_transfer {
if self.conn_type.eq(&ConnType::FILE_TRANSFER) || self.conn_type.eq(&ConnType::PORT_FORWARD)
{
return None;
}
let mut n = 0;
@ -1260,13 +1278,13 @@ impl LoginConfigHandler {
///
/// * `username` - The name of the peer.
/// * `pi` - The peer info.
pub fn handle_peer_info(&mut self, username: String, pi: PeerInfo) {
pub fn handle_peer_info(&mut self, pi: PeerInfo) {
if !pi.version.is_empty() {
self.version = hbb_common::get_version_number(&pi.version);
}
self.features = pi.features.into_option();
let serde = PeerInfoSerde {
username,
username: pi.username.clone(),
hostname: pi.hostname.clone(),
platform: pi.platform.clone(),
};
@ -1330,19 +1348,20 @@ impl LoginConfigHandler {
version: crate::VERSION.to_string(),
..Default::default()
};
if self.is_file_transfer {
lr.set_file_transfer(FileTransfer {
match self.conn_type {
ConnType::FILE_TRANSFER => lr.set_file_transfer(FileTransfer {
dir: self.get_remote_dir(),
show_hidden: !self.get_option("remote_show_hidden").is_empty(),
..Default::default()
});
} else if self.is_port_forward {
lr.set_port_forward(PortForward {
}),
ConnType::PORT_FORWARD => lr.set_port_forward(PortForward {
host: self.port_forward.0.clone(),
port: self.port_forward.1,
..Default::default()
});
}),
_ => {}
}
let mut msg_out = Message::new();
msg_out.set_login_request(lr);
msg_out
@ -1651,6 +1670,12 @@ pub trait Interface: Send + Clone + 'static + Sized {
fn handle_login_error(&mut self, err: &str) -> bool;
fn handle_peer_info(&mut self, pi: PeerInfo);
fn set_force_relay(&mut self, direct: bool, received: bool);
fn is_file_transfer(&self) -> bool;
fn is_port_forward(&self) -> bool;
fn is_rdp(&self) -> bool;
fn on_error(&self, err: &str) {
self.msgbox("error", "Error", err);
}
fn is_force_relay(&self) -> bool;
async fn handle_hash(&mut self, pass: &str, hash: Hash, peer: &mut Stream);
async fn handle_login_from_ui(&mut self, password: String, remember: bool, peer: &mut Stream);

View File

@ -1,4 +1,4 @@
use hbb_common::{fs, message_proto::*};
use hbb_common::{fs, message_proto::*, log};
use super::{Data, Interface};
@ -114,4 +114,26 @@ pub trait FileManager: Interface {
fn resume_job(&self, id: i32, is_remote: bool) {
self.send(Data::ResumeJob((id, is_remote)));
}
fn set_confirm_override_file(
&self,
id: i32,
file_num: i32,
need_override: bool,
remember: bool,
is_upload: bool,
) {
log::info!(
"confirm file transfer, job: {}, need_override: {}",
id,
need_override
);
self.send(Data::SetConfirmOverrideFile((
id,
file_num,
need_override,
remember,
is_upload,
)));
}
}

1208
src/client/io_loop.rs Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -13,10 +13,10 @@ use hbb_common::{
};
use hbb_common::{password_security, ResultType};
use crate::client::file_trait::FileManager;
use crate::{client::file_trait::FileManager, flutter::{session_add, session_start_}};
use crate::common::make_fd_to_json;
use crate::flutter::connection_manager::{self, get_clients_length, get_clients_state};
use crate::flutter::{self, Session, SESSIONS};
use crate::flutter::{self, SESSIONS};
use crate::start_server;
use crate::ui_interface;
#[cfg(not(any(target_os = "android", target_os = "ios")))]
@ -111,7 +111,7 @@ pub fn host_stop_system_key_propagate(stopped: bool) {
// FIXME: -> ResultType<()> cannot be parsed by frb_codegen
// thread 'main' panicked at 'Failed to parse function output type `ResultType<()>`', $HOME\.cargo\git\checkouts\flutter_rust_bridge-ddba876d3ebb2a1e\e5adce5\frb_codegen\src\parser\mod.rs:151:25
pub fn session_add_sync(id: String, is_file_transfer: bool, is_port_forward: bool) -> SyncReturn<String> {
if let Err(e) = Session::add(&id, is_file_transfer, is_port_forward) {
if let Err(e) = session_add(&id, is_file_transfer, is_port_forward) {
SyncReturn(format!("Failed to add session with id {}, {}", &id, e))
} else {
SyncReturn("".to_owned())
@ -119,7 +119,7 @@ pub fn session_add_sync(id: String, is_file_transfer: bool, is_port_forward: boo
}
pub fn session_start(events2ui: StreamSink<EventToUI>, id: String) -> ResultType<()> {
Session::start(&id, events2ui)
session_start_(&id, events2ui)
}
pub fn session_get_remember(id: String) -> Option<bool> {
@ -132,7 +132,7 @@ pub fn session_get_remember(id: String) -> Option<bool> {
pub fn session_get_toggle_option(id: String, arg: String) -> Option<bool> {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
Some(session.get_toggle_option(&arg))
Some(session.get_toggle_option(arg))
} else {
None
}
@ -153,7 +153,7 @@ pub fn session_get_image_quality(id: String) -> Option<String> {
pub fn session_get_option(id: String, arg: String) -> Option<String> {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
Some(session.get_option(&arg))
Some(session.get_option(arg))
} else {
None
}
@ -161,7 +161,7 @@ pub fn session_get_option(id: String, arg: String) -> Option<String> {
pub fn session_login(id: String, password: String, remember: bool) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.login(&password, remember);
session.login(password, remember);
}
}
@ -174,7 +174,7 @@ pub fn session_close(id: String) {
pub fn session_refresh(id: String) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.refresh();
session.refresh_video();
}
}
@ -185,14 +185,14 @@ pub fn session_reconnect(id: String) {
}
pub fn session_toggle_option(id: String, value: String) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.toggle_option(&value);
if let Some(session) = SESSIONS.write().unwrap().get_mut(&id) {
session.toggle_option(value);
}
}
pub fn session_set_image_quality(id: String, value: String) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
session.set_image_quality(&value);
if let Some(session) = SESSIONS.write().unwrap().get_mut(&id) {
session.save_image_quality(value);
}
}
@ -250,7 +250,7 @@ pub fn session_peer_option(id: String, name: String, value: String) {
pub fn session_get_peer_option(id: String, name: String) -> String {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
return session.get_option(&name);
return session.get_option(name);
}
"".to_string()
}
@ -349,7 +349,7 @@ pub fn session_get_platform(id: String, is_remote: bool) -> String {
pub fn session_load_last_transfer_jobs(id: String) {
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
return session.load_last_jobs();
// return session.load_last_jobs();
} else {
// a tip for flutter dev
eprintln!(
@ -687,7 +687,6 @@ pub fn main_has_hwcodec() -> bool {
has_hwcodec()
}
// TODO
pub fn session_send_mouse(id: String, msg: String) {
if let Ok(m) = serde_json::from_str::<HashMap<String, String>>(&msg) {
let alt = m.get("alt").is_some();

View File

@ -48,6 +48,7 @@ mod port_forward;
mod tray;
mod ui_interface;
mod ui_session_interface;
#[cfg(windows)]
pub mod clipboard_file;

View File

@ -146,7 +146,7 @@ pub fn start(args: &mut [String]) {
let args: Vec<String> = iter.map(|x| x.clone()).collect();
frame.set_title(&id);
frame.register_behavior("native-remote", move || {
Box::new(remote::Handler::new(
Box::new(remote::SciterSession::new(
cmd.clone(),
id.clone(),
pass.clone(),

File diff suppressed because it is too large Load Diff

1097
src/ui_session_interface.rs Normal file

File diff suppressed because it is too large Load Diff