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
10 changed files with 2858 additions and 4009 deletions

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();