mirror of
https://github.com/rustdesk/rustdesk.git
synced 2025-12-14 03:56:27 +00:00
better conditional compilation
Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
@@ -1,9 +1,3 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
process::Child,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
use hbb_common::password_security;
|
||||
use hbb_common::{
|
||||
@@ -11,16 +5,21 @@ use hbb_common::{
|
||||
config::{self, Config, LocalConfig, PeerConfig},
|
||||
directories_next, log, tokio,
|
||||
};
|
||||
use hbb_common::{
|
||||
config::{CONNECT_TIMEOUT, RENDEZVOUS_PORT},
|
||||
futures::future::join_all,
|
||||
rendezvous_proto::*,
|
||||
};
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
use hbb_common::{
|
||||
sleep,
|
||||
tokio::{sync::mpsc, time},
|
||||
};
|
||||
|
||||
use hbb_common::{
|
||||
config::{CONNECT_TIMEOUT, RENDEZVOUS_PORT},
|
||||
futures::future::join_all,
|
||||
rendezvous_proto::*,
|
||||
use serde_derive::Serialize;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
process::Child,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use crate::common::SOFTWARE_UPDATE_URL;
|
||||
@@ -32,10 +31,28 @@ use crate::ipc;
|
||||
type Message = RendezvousMessage;
|
||||
|
||||
pub type Children = Arc<Mutex<(bool, HashMap<(String, String), Child>)>>;
|
||||
type Status = (i32, bool, i64, String); // (status_num, key_confirmed, mouse_time, id)
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
pub struct UiStatus {
|
||||
pub status_num: i32,
|
||||
#[cfg(not(feature = "flutter"))]
|
||||
pub key_confirmed: bool,
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
pub mouse_time: i64,
|
||||
#[cfg(not(feature = "flutter"))]
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref UI_STATUS : Arc<Mutex<Status>> = Arc::new(Mutex::new((0, false, 0, "".to_owned())));
|
||||
static ref UI_STATUS : Arc<Mutex<UiStatus>> = Arc::new(Mutex::new(UiStatus{
|
||||
status_num: 0,
|
||||
#[cfg(not(feature = "flutter"))]
|
||||
key_confirmed: false,
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
mouse_time: 0,
|
||||
#[cfg(not(feature = "flutter"))]
|
||||
id: "".to_owned(),
|
||||
}));
|
||||
static ref ASYNC_JOB_STATUS : Arc<Mutex<String>> = Default::default();
|
||||
static ref TEMPORARY_PASSWD : Arc<Mutex<String>> = Arc::new(Mutex::new("".to_owned()));
|
||||
}
|
||||
@@ -115,12 +132,12 @@ pub fn get_license() -> String {
|
||||
pub fn get_option<T: AsRef<str>>(key: T) -> String {
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
{
|
||||
let map = OPTIONS.lock().unwrap();
|
||||
if let Some(v) = map.get(key.as_ref()) {
|
||||
v.to_owned()
|
||||
} else {
|
||||
"".to_owned()
|
||||
}
|
||||
let map = OPTIONS.lock().unwrap();
|
||||
if let Some(v) = map.get(key.as_ref()) {
|
||||
v.to_owned()
|
||||
} else {
|
||||
"".to_owned()
|
||||
}
|
||||
}
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
{
|
||||
@@ -200,14 +217,14 @@ pub fn using_public_server() -> bool {
|
||||
#[inline]
|
||||
pub fn get_options() -> String {
|
||||
let options = {
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
{
|
||||
OPTIONS.lock().unwrap()
|
||||
}
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
{
|
||||
Config::get_options()
|
||||
}
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
{
|
||||
OPTIONS.lock().unwrap()
|
||||
}
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
{
|
||||
Config::get_options()
|
||||
}
|
||||
};
|
||||
let mut m = serde_json::Map::new();
|
||||
for (k, v) in options.iter() {
|
||||
@@ -273,8 +290,8 @@ pub fn get_sound_inputs() -> Vec<String> {
|
||||
pub fn set_options(m: HashMap<String, String>) {
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
{
|
||||
*OPTIONS.lock().unwrap() = m.clone();
|
||||
ipc::set_options(m).ok();
|
||||
*OPTIONS.lock().unwrap() = m.clone();
|
||||
ipc::set_options(m).ok();
|
||||
}
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
Config::set_options(m);
|
||||
@@ -308,13 +325,13 @@ pub fn set_option(key: String, value: String) {
|
||||
}
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
{
|
||||
let mut options = OPTIONS.lock().unwrap();
|
||||
if value.is_empty() {
|
||||
options.remove(&key);
|
||||
} else {
|
||||
options.insert(key.clone(), value.clone());
|
||||
}
|
||||
ipc::set_options(options.clone()).ok();
|
||||
let mut options = OPTIONS.lock().unwrap();
|
||||
if value.is_empty() {
|
||||
options.remove(&key);
|
||||
} else {
|
||||
options.insert(key.clone(), value.clone());
|
||||
}
|
||||
ipc::set_options(options.clone()).ok();
|
||||
}
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
Config::set_option(key, value);
|
||||
@@ -408,10 +425,9 @@ pub fn is_installed_lower_version() -> bool {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
pub fn get_mouse_time() -> f64 {
|
||||
let ui_status = UI_STATUS.lock().unwrap();
|
||||
let res = ui_status.2 as f64;
|
||||
return res;
|
||||
UI_STATUS.lock().unwrap().mouse_time as f64
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -424,10 +440,9 @@ pub fn check_mouse_time() {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_connect_status() -> Status {
|
||||
let ui_statue = UI_STATUS.lock().unwrap();
|
||||
let res = ui_statue.clone();
|
||||
res
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
pub fn get_connect_status() -> UiStatus {
|
||||
UI_STATUS.lock().unwrap().clone()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -872,10 +887,13 @@ pub fn get_hostname() -> String {
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver<ipc::Data>) {
|
||||
#[cfg(not(feature = "flutter"))]
|
||||
let mut key_confirmed = false;
|
||||
let mut rx = rx;
|
||||
let mut mouse_time = 0;
|
||||
#[cfg(not(feature = "flutter"))]
|
||||
let mut id = "".to_owned();
|
||||
#[cfg(target_os = "windows")]
|
||||
let mut enable_file_transfer = "".to_owned();
|
||||
|
||||
loop {
|
||||
@@ -889,9 +907,10 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver<ipc:
|
||||
log::error!("ipc connection closed: {}", err);
|
||||
break;
|
||||
}
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
Ok(Some(ipc::Data::MouseMoveTime(v))) => {
|
||||
mouse_time = v;
|
||||
UI_STATUS.lock().unwrap().2 = v;
|
||||
UI_STATUS.lock().unwrap().mouse_time = v;
|
||||
}
|
||||
Ok(Some(ipc::Data::Options(Some(v)))) => {
|
||||
*OPTIONS.lock().unwrap() = v;
|
||||
@@ -908,17 +927,31 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver<ipc:
|
||||
}
|
||||
Ok(Some(ipc::Data::Config((name, Some(value))))) => {
|
||||
if name == "id" {
|
||||
id = value;
|
||||
#[cfg(not(feature = "flutter"))]
|
||||
{
|
||||
id = value;
|
||||
}
|
||||
} else if name == "temporary-password" {
|
||||
*TEMPORARY_PASSWD.lock().unwrap() = value;
|
||||
}
|
||||
}
|
||||
Ok(Some(ipc::Data::OnlineStatus(Some((mut x, c))))) => {
|
||||
Ok(Some(ipc::Data::OnlineStatus(Some((mut x, _c))))) => {
|
||||
if x > 0 {
|
||||
x = 1
|
||||
}
|
||||
key_confirmed = c;
|
||||
*UI_STATUS.lock().unwrap() = (x as _, key_confirmed, mouse_time, id.clone());
|
||||
#[cfg(not(feature = "flutter"))]
|
||||
{
|
||||
key_confirmed = _c;
|
||||
}
|
||||
*UI_STATUS.lock().unwrap() = UiStatus {
|
||||
status_num: x as _,
|
||||
#[cfg(not(feature = "flutter"))]
|
||||
key_confirmed: _c,
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
mouse_time,
|
||||
#[cfg(not(feature = "flutter"))]
|
||||
id: id.clone(),
|
||||
};
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -942,18 +975,26 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver<ipc:
|
||||
.insert("ipc-closed".to_owned(), "Y".to_owned());
|
||||
break;
|
||||
}
|
||||
*UI_STATUS.lock().unwrap() = (-1, key_confirmed, mouse_time, id.clone());
|
||||
*UI_STATUS.lock().unwrap() = UiStatus {
|
||||
status_num: -1,
|
||||
#[cfg(not(feature = "flutter"))]
|
||||
key_confirmed,
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
mouse_time,
|
||||
#[cfg(not(feature = "flutter"))]
|
||||
id: id.clone(),
|
||||
};
|
||||
sleep(1.).await;
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn option_synced() -> bool {
|
||||
#[cfg(not(any(target_os = "android", target_os= "ios")))]
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
{
|
||||
OPTION_SYNCED.lock().unwrap().clone()
|
||||
}
|
||||
#[cfg(any(target_os = "android", target_os= "ios"))]
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
{
|
||||
true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user