mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-04-13 01:01:28 +03:00
Merge remote-tracking branch 'rustdesk/master' into flutter_desktop
# Conflicts: # .github/workflows/ci.yml # Cargo.lock # Cargo.toml # flutter/lib/common.dart # flutter/lib/mobile/pages/remote_page.dart # flutter/lib/mobile/pages/server_page.dart # flutter/lib/mobile/pages/settings_page.dart # flutter/lib/mobile/widgets/dialog.dart # flutter/lib/models/model.dart # flutter/lib/models/server_model.dart # src/client.rs # src/common.rs # src/ipc.rs # src/mobile_ffi.rs # src/rendezvous_mediator.rs # src/ui.rs
This commit is contained in:
129
src/ipc.rs
129
src/ipc.rs
@@ -1,3 +1,5 @@
|
||||
use crate::rendezvous_mediator::RendezvousMediator;
|
||||
use bytes::Bytes;
|
||||
use std::{collections::HashMap, sync::atomic::Ordering};
|
||||
#[cfg(not(windows))]
|
||||
use std::{fs::File, io::prelude::*};
|
||||
@@ -15,7 +17,7 @@ use hbb_common::{
|
||||
config::{self, Config, Config2},
|
||||
futures::StreamExt as _,
|
||||
futures_util::sink::SinkExt,
|
||||
log, timeout, tokio,
|
||||
log, password_security as password, timeout, tokio,
|
||||
tokio::io::{AsyncRead, AsyncWrite},
|
||||
tokio_util::codec::Framed,
|
||||
ResultType,
|
||||
@@ -66,7 +68,7 @@ pub enum FS {
|
||||
WriteBlock {
|
||||
id: i32,
|
||||
file_num: i32,
|
||||
data: Vec<u8>,
|
||||
data: Bytes,
|
||||
compressed: bool,
|
||||
},
|
||||
WriteDone {
|
||||
@@ -87,6 +89,47 @@ pub enum FS {
|
||||
},
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[serde(tag = "t", content = "c")]
|
||||
pub enum DataKeyboard {
|
||||
Sequence(String),
|
||||
KeyDown(enigo::Key),
|
||||
KeyUp(enigo::Key),
|
||||
KeyClick(enigo::Key),
|
||||
GetKeyState(enigo::Key),
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[serde(tag = "t", content = "c")]
|
||||
pub enum DataKeyboardResponse {
|
||||
GetKeyState(bool),
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[serde(tag = "t", content = "c")]
|
||||
pub enum DataMouse {
|
||||
MoveTo(i32, i32),
|
||||
MoveRelative(i32, i32),
|
||||
Down(enigo::MouseButton),
|
||||
Up(enigo::MouseButton),
|
||||
Click(enigo::MouseButton),
|
||||
ScrollX(i32),
|
||||
ScrollY(i32),
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[serde(tag = "t", content = "c")]
|
||||
pub enum DataControl {
|
||||
Resolution {
|
||||
minx: i32,
|
||||
maxx: i32,
|
||||
miny: i32,
|
||||
maxy: i32,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[serde(tag = "t", content = "c")]
|
||||
pub enum Data {
|
||||
@@ -102,6 +145,7 @@ pub enum Data {
|
||||
audio: bool,
|
||||
file: bool,
|
||||
file_transfer_enabled: bool,
|
||||
restart: bool,
|
||||
},
|
||||
ChatMessage {
|
||||
text: String,
|
||||
@@ -130,6 +174,15 @@ pub enum Data {
|
||||
ClipbaordFile(ClipbaordFile),
|
||||
ClipboardFileEnabled(bool),
|
||||
PrivacyModeState((i32, PrivacyModeState)),
|
||||
TestRendezvousServer,
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))]
|
||||
Keyboard(DataKeyboard),
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))]
|
||||
KeyboardResponse(DataKeyboardResponse),
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))]
|
||||
Mouse(DataMouse),
|
||||
Control(DataControl),
|
||||
Empty,
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
@@ -284,12 +337,18 @@ async fn handle(data: Data, stream: &mut Connection) {
|
||||
let value;
|
||||
if name == "id" {
|
||||
value = Some(Config::get_id());
|
||||
} else if name == "password" {
|
||||
value = Some(Config::get_password());
|
||||
} else if name == "temporary-password" {
|
||||
value = Some(password::temporary_password());
|
||||
} else if name == "permanent-password" {
|
||||
value = Some(Config::get_permanent_password());
|
||||
} else if name == "salt" {
|
||||
value = Some(Config::get_salt());
|
||||
} else if name == "rendezvous_server" {
|
||||
value = Some(Config::get_rendezvous_server());
|
||||
value = Some(format!(
|
||||
"{},{}",
|
||||
Config::get_rendezvous_server(),
|
||||
Config::get_rendezvous_servers().join(",")
|
||||
));
|
||||
} else if name == "rendezvous_servers" {
|
||||
value = Some(Config::get_rendezvous_servers().join(","));
|
||||
} else {
|
||||
@@ -301,8 +360,10 @@ async fn handle(data: Data, stream: &mut Connection) {
|
||||
if name == "id" {
|
||||
Config::set_key_confirmed(false);
|
||||
Config::set_id(&value);
|
||||
} else if name == "password" {
|
||||
Config::set_password(&value);
|
||||
} else if name == "temporary-password" {
|
||||
password::update_temporary_password();
|
||||
} else if name == "permanent-password" {
|
||||
Config::set_permanent_password(&value);
|
||||
} else if name == "salt" {
|
||||
Config::set_salt(&value);
|
||||
} else {
|
||||
@@ -339,6 +400,9 @@ async fn handle(data: Data, stream: &mut Connection) {
|
||||
.await
|
||||
);
|
||||
}
|
||||
Data::TestRendezvousServer => {
|
||||
crate::test_rendezvous_server();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -450,8 +514,8 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn send_raw(&mut self, data: Vec<u8>) -> ResultType<()> {
|
||||
self.inner.send(bytes::Bytes::from(data)).await?;
|
||||
pub async fn send_raw(&mut self, data: Bytes) -> ResultType<()> {
|
||||
self.inner.send(data).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -492,9 +556,22 @@ pub async fn set_config(name: &str, value: String) -> ResultType<()> {
|
||||
set_config_async(name, value).await
|
||||
}
|
||||
|
||||
pub fn set_password(v: String) -> ResultType<()> {
|
||||
Config::set_password(&v);
|
||||
set_config("password", v)
|
||||
pub fn update_temporary_password() -> ResultType<()> {
|
||||
set_config("temporary-password", "".to_owned())
|
||||
}
|
||||
|
||||
pub fn get_permanent_password() -> String {
|
||||
if let Ok(Some(v)) = get_config("permanent-password") {
|
||||
Config::set_permanent_password(&v);
|
||||
v
|
||||
} else {
|
||||
Config::get_permanent_password()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_permanent_password(v: String) -> ResultType<()> {
|
||||
Config::set_permanent_password(&v);
|
||||
set_config("permanent-password", v)
|
||||
}
|
||||
|
||||
pub fn get_id() -> String {
|
||||
@@ -513,20 +590,17 @@ pub fn get_id() -> String {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_password() -> String {
|
||||
if let Ok(Some(v)) = get_config("password") {
|
||||
Config::set_password(&v);
|
||||
v
|
||||
} else {
|
||||
Config::get_password()
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_rendezvous_server(ms_timeout: u64) -> String {
|
||||
pub async fn get_rendezvous_server(ms_timeout: u64) -> (String, Vec<String>) {
|
||||
if let Ok(Some(v)) = get_config_async("rendezvous_server", ms_timeout).await {
|
||||
v
|
||||
let mut urls = v.split(",");
|
||||
let a = urls.next().unwrap_or_default().to_owned();
|
||||
let b: Vec<String> = urls.map(|x| x.to_owned()).collect();
|
||||
(a, b)
|
||||
} else {
|
||||
Config::get_rendezvous_server()
|
||||
(
|
||||
Config::get_rendezvous_server(),
|
||||
Config::get_rendezvous_servers(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -638,3 +712,10 @@ pub async fn set_socks(value: config::Socks5Server) -> ResultType<()> {
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
pub async fn test_rendezvous_server() -> ResultType<()> {
|
||||
let mut c = connect(1000, "").await?;
|
||||
c.send(&Data::TestRendezvousServer).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user