mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-04-04 08:31:29 +03:00
refact: win, idd control (#7789)
* refact: win, idd control Signed-off-by: fufesou <shuanglongchen@yeah.net> * refact: win device control, better addr of Signed-off-by: fufesou <shuanglongchen@yeah.net> * refact: simple refact Signed-off-by: fufesou <shuanglongchen@yeah.net> --------- Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
@@ -6,12 +6,7 @@ use crate::{
|
||||
display_service,
|
||||
ipc::{connect, Data},
|
||||
};
|
||||
use hbb_common::{
|
||||
anyhow::anyhow,
|
||||
bail, lazy_static,
|
||||
tokio::{self, sync::oneshot},
|
||||
ResultType,
|
||||
};
|
||||
use hbb_common::{anyhow::anyhow, bail, lazy_static, tokio, ResultType};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
@@ -56,8 +51,6 @@ pub enum PrivacyModeState {
|
||||
}
|
||||
|
||||
pub trait PrivacyMode: Sync + Send {
|
||||
fn is_async_privacy_mode(&self) -> bool;
|
||||
|
||||
fn init(&self) -> ResultType<()>;
|
||||
fn clear(&mut self);
|
||||
fn turn_on_privacy(&mut self, conn_id: i32) -> ResultType<bool>;
|
||||
@@ -207,41 +200,7 @@ fn get_supported_impl(impl_key: &str) -> String {
|
||||
cur_impl
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub async fn turn_on_privacy(impl_key: &str, conn_id: i32) -> Option<ResultType<bool>> {
|
||||
if is_async_privacy_mode() {
|
||||
turn_on_privacy_async(impl_key.to_string(), conn_id).await
|
||||
} else {
|
||||
turn_on_privacy_sync(impl_key, conn_id)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_async_privacy_mode() -> bool {
|
||||
PRIVACY_MODE
|
||||
.lock()
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
.map_or(false, |m| m.is_async_privacy_mode())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
async fn turn_on_privacy_async(impl_key: String, conn_id: i32) -> Option<ResultType<bool>> {
|
||||
let (tx, rx) = oneshot::channel();
|
||||
std::thread::spawn(move || {
|
||||
let res = turn_on_privacy_sync(&impl_key, conn_id);
|
||||
let _ = tx.send(res);
|
||||
});
|
||||
match hbb_common::timeout(5000, rx).await {
|
||||
Ok(res) => match res {
|
||||
Ok(res) => res,
|
||||
Err(e) => Some(Err(anyhow!(e.to_string()))),
|
||||
},
|
||||
Err(e) => Some(Err(anyhow!(e.to_string()))),
|
||||
}
|
||||
}
|
||||
|
||||
fn turn_on_privacy_sync(impl_key: &str, conn_id: i32) -> Option<ResultType<bool>> {
|
||||
pub fn turn_on_privacy(impl_key: &str, conn_id: i32) -> Option<ResultType<bool>> {
|
||||
// Check if privacy mode is already on or occupied by another one
|
||||
let mut privacy_mode_lock = PRIVACY_MODE.lock().unwrap();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user