@@ -14,12 +14,11 @@ use flutter_rust_bridge::{StreamSink, SyncReturn};
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
use hbb_common::allow_err;
|
||||
use hbb_common::{
|
||||
config::{self, LocalConfig, PeerConfig, PeerInfoSerde, ONLINE},
|
||||
config::{self, get_online_statue, LocalConfig, PeerConfig, PeerInfoSerde},
|
||||
fs, log,
|
||||
message_proto::KeyboardMode,
|
||||
ResultType,
|
||||
};
|
||||
use serde_json::json;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
ffi::{CStr, CString},
|
||||
@@ -680,14 +679,18 @@ pub fn main_get_lan_peers() -> String {
|
||||
}
|
||||
|
||||
pub fn main_get_connect_status() -> String {
|
||||
let status = get_connect_status();
|
||||
// (status_num, key_confirmed, mouse_time, id)
|
||||
let mut m = serde_json::Map::new();
|
||||
m.insert("status_num".to_string(), json!(status.0));
|
||||
m.insert("key_confirmed".to_string(), json!(status.1));
|
||||
m.insert("mouse_time".to_string(), json!(status.2));
|
||||
m.insert("id".to_string(), json!(status.3));
|
||||
serde_json::to_string(&m).unwrap_or("".to_string())
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
{
|
||||
serde_json::to_string(&get_connect_status()).unwrap_or("".to_string())
|
||||
}
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
{
|
||||
let mut state = get_online_statue();
|
||||
if state > 0 {
|
||||
state = 1;
|
||||
}
|
||||
serde_json::json!({ "status_num": get_online_statue() }).to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main_check_connect_status() {
|
||||
@@ -996,7 +999,7 @@ pub fn main_get_fingerprint() -> String {
|
||||
}
|
||||
|
||||
pub fn main_get_online_statue() -> i64 {
|
||||
ONLINE.lock().unwrap().values().max().unwrap_or(&0).clone()
|
||||
get_online_statue()
|
||||
}
|
||||
|
||||
pub fn cm_get_clients_state() -> String {
|
||||
@@ -1194,7 +1197,15 @@ pub fn main_check_mouse_time() {
|
||||
}
|
||||
|
||||
pub fn main_get_mouse_time() -> f64 {
|
||||
get_mouse_time()
|
||||
let mut mouse_time = 0.0;
|
||||
#[cfg(all(
|
||||
not(any(target_os = "android", target_os = "ios")),
|
||||
feature = "flutter"
|
||||
))]
|
||||
{
|
||||
mouse_time = get_mouse_time();
|
||||
}
|
||||
mouse_time
|
||||
}
|
||||
|
||||
pub fn main_wol(id: String) {
|
||||
|
||||
16
src/ipc.rs
16
src/ipc.rs
@@ -186,6 +186,10 @@ pub enum Data {
|
||||
},
|
||||
SystemInfo(Option<String>),
|
||||
ClickTime(i64),
|
||||
#[cfg(all(
|
||||
not(any(target_os = "android", target_os = "ios")),
|
||||
feature = "flutter"
|
||||
))]
|
||||
MouseMoveTime(i64),
|
||||
Authorize,
|
||||
Close,
|
||||
@@ -332,6 +336,10 @@ async fn handle(data: Data, stream: &mut Connection) {
|
||||
let t = crate::server::CLICK_TIME.load(Ordering::SeqCst);
|
||||
allow_err!(stream.send(&Data::ClickTime(t)).await);
|
||||
}
|
||||
#[cfg(all(
|
||||
not(any(target_os = "android", target_os = "ios")),
|
||||
feature = "flutter"
|
||||
))]
|
||||
Data::MouseMoveTime(_) => {
|
||||
let t = crate::server::MOUSE_MOVE_TIME.load(Ordering::SeqCst);
|
||||
allow_err!(stream.send(&Data::MouseMoveTime(t)).await);
|
||||
@@ -345,13 +353,7 @@ async fn handle(data: Data, stream: &mut Connection) {
|
||||
}
|
||||
}
|
||||
Data::OnlineStatus(_) => {
|
||||
let x = config::ONLINE
|
||||
.lock()
|
||||
.unwrap()
|
||||
.values()
|
||||
.max()
|
||||
.unwrap_or(&0)
|
||||
.clone();
|
||||
let x = config::get_online_statue();
|
||||
let confirmed = Config::get_key_confirmed();
|
||||
allow_err!(stream.send(&Data::OnlineStatus(Some((x, confirmed)))).await);
|
||||
}
|
||||
|
||||
@@ -63,6 +63,10 @@ lazy_static::lazy_static! {
|
||||
static ref SWITCH_SIDES_UUID: Arc::<Mutex<HashMap<String, (Instant, uuid::Uuid)>>> = Default::default();
|
||||
}
|
||||
pub static CLICK_TIME: AtomicI64 = AtomicI64::new(0);
|
||||
#[cfg(all(
|
||||
not(any(target_os = "android", target_os = "ios")),
|
||||
feature = "flutter"
|
||||
))]
|
||||
pub static MOUSE_MOVE_TIME: AtomicI64 = AtomicI64::new(0);
|
||||
|
||||
#[cfg(all(feature = "flutter", feature = "plugin_framework"))]
|
||||
@@ -163,6 +167,7 @@ pub struct Connection {
|
||||
// by peer
|
||||
disable_audio: bool,
|
||||
// by peer
|
||||
#[cfg(windows)]
|
||||
enable_file_transfer: bool,
|
||||
// by peer
|
||||
audio_sender: Option<MediaSender>,
|
||||
@@ -291,6 +296,7 @@ impl Connection {
|
||||
show_remote_cursor: false,
|
||||
ip: "".to_owned(),
|
||||
disable_audio: false,
|
||||
#[cfg(windows)]
|
||||
enable_file_transfer: false,
|
||||
disable_clipboard: false,
|
||||
disable_keyboard: false,
|
||||
@@ -1112,6 +1118,7 @@ impl Connection {
|
||||
self.audio && !self.disable_audio
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn file_transfer_enabled(&self) -> bool {
|
||||
self.file && self.enable_file_transfer
|
||||
}
|
||||
@@ -1563,6 +1570,10 @@ impl Connection {
|
||||
if is_left_up(&me) {
|
||||
CLICK_TIME.store(get_time(), Ordering::SeqCst);
|
||||
} else {
|
||||
#[cfg(all(
|
||||
not(any(target_os = "android", target_os = "ios")),
|
||||
feature = "flutter"
|
||||
))]
|
||||
MOUSE_MOVE_TIME.store(get_time(), Ordering::SeqCst);
|
||||
}
|
||||
self.input_mouse(me, self.inner.id());
|
||||
|
||||
@@ -362,9 +362,9 @@ impl UI {
|
||||
fn get_connect_status(&mut self) -> Value {
|
||||
let mut v = Value::array(0);
|
||||
let x = get_connect_status();
|
||||
v.push(x.0);
|
||||
v.push(x.1);
|
||||
v.push(x.3);
|
||||
v.push(x.status_num);
|
||||
v.push(x.key_confirmed);
|
||||
v.push(x.id);
|
||||
v
|
||||
}
|
||||
|
||||
|
||||
@@ -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::{
|
||||
@@ -16,6 +10,12 @@ use hbb_common::{
|
||||
sleep,
|
||||
tokio::{sync::mpsc, time},
|
||||
};
|
||||
use serde_derive::Serialize;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
process::Child,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use hbb_common::{
|
||||
config::{CONNECT_TIMEOUT, RENDEZVOUS_PORT},
|
||||
@@ -32,10 +32,34 @@ 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(all(
|
||||
not(any(target_os = "android", target_os = "ios")),
|
||||
feature = "flutter"
|
||||
))]
|
||||
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(all(
|
||||
not(any(target_os = "android", target_os = "ios")),
|
||||
feature = "flutter"
|
||||
))]
|
||||
mouse_time: 0,
|
||||
#[cfg(not(feature = "flutter"))]
|
||||
id: "".to_owned(),
|
||||
}));
|
||||
static ref OPTIONS : Arc<Mutex<HashMap<String, String>>> = Arc::new(Mutex::new(Config::get_options()));
|
||||
static ref ASYNC_JOB_STATUS : Arc<Mutex<String>> = Default::default();
|
||||
static ref TEMPORARY_PASSWD : Arc<Mutex<String>> = Arc::new(Mutex::new("".to_owned()));
|
||||
@@ -393,15 +417,20 @@ pub fn is_installed_lower_version() -> bool {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(all(
|
||||
not(any(target_os = "android", target_os = "ios")),
|
||||
feature = "flutter"
|
||||
))]
|
||||
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]
|
||||
pub fn check_mouse_time() {
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
#[cfg(all(
|
||||
not(any(target_os = "android", target_os = "ios")),
|
||||
feature = "flutter"
|
||||
))]
|
||||
{
|
||||
let sender = SENDER.lock().unwrap();
|
||||
allow_err!(sender.send(ipc::Data::MouseMoveTime(0)));
|
||||
@@ -409,10 +438,8 @@ 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
|
||||
pub fn get_connect_status() -> UiStatus {
|
||||
UI_STATUS.lock().unwrap().clone()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -874,9 +901,13 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver<ipc:
|
||||
log::error!("ipc connection closed: {}", err);
|
||||
break;
|
||||
}
|
||||
#[cfg(all(
|
||||
not(any(target_os = "android", target_os = "ios")),
|
||||
feature = "flutter"
|
||||
))]
|
||||
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;
|
||||
@@ -902,8 +933,18 @@ async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver<ipc:
|
||||
if x > 0 {
|
||||
x = 1
|
||||
}
|
||||
key_confirmed = c;
|
||||
*UI_STATUS.lock().unwrap() = (x as _, key_confirmed, mouse_time, id.clone());
|
||||
*UI_STATUS.lock().unwrap() = UiStatus {
|
||||
status_num: x as _,
|
||||
#[cfg(not(feature = "flutter"))]
|
||||
key_confirmed: c,
|
||||
#[cfg(all(
|
||||
not(any(target_os = "android", target_os = "ios")),
|
||||
feature = "flutter"
|
||||
))]
|
||||
mouse_time,
|
||||
#[cfg(not(feature = "flutter"))]
|
||||
id: id.clone(),
|
||||
};
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -927,7 +968,18 @@ 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(all(
|
||||
not(any(target_os = "android", target_os = "ios")),
|
||||
feature = "flutter"
|
||||
))]
|
||||
mouse_time,
|
||||
#[cfg(not(feature = "flutter"))]
|
||||
id: id.clone(),
|
||||
};
|
||||
sleep(1.).await;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user