mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
refact, separate remote window
Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
@@ -186,7 +186,7 @@ pub type FlutterRgbaRendererPluginOnRgba = unsafe extern "C" fn(
|
||||
#[derive(Clone)]
|
||||
struct VideoRenderer {
|
||||
// TextureRgba pointer in flutter native.
|
||||
ptr: usize,
|
||||
ptr: Arc<RwLock<usize>>,
|
||||
width: usize,
|
||||
height: usize,
|
||||
on_rgba_func: Option<Symbol<'static, FlutterRgbaRendererPluginOnRgba>>,
|
||||
@@ -214,7 +214,7 @@ impl Default for VideoRenderer {
|
||||
}
|
||||
};
|
||||
Self {
|
||||
ptr: 0,
|
||||
ptr: Default::default(),
|
||||
width: 0,
|
||||
height: 0,
|
||||
on_rgba_func,
|
||||
@@ -231,7 +231,8 @@ impl VideoRenderer {
|
||||
}
|
||||
|
||||
pub fn on_rgba(&self, rgba: &mut scrap::ImageRgb) {
|
||||
if self.ptr == usize::default() {
|
||||
let ptr = self.ptr.read().unwrap();
|
||||
if *ptr == usize::default() {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -243,7 +244,7 @@ impl VideoRenderer {
|
||||
if let Some(func) = &self.on_rgba_func {
|
||||
unsafe {
|
||||
func(
|
||||
self.ptr as _,
|
||||
*ptr as _,
|
||||
rgba.raw.as_ptr() as _,
|
||||
rgba.raw.len() as _,
|
||||
rgba.w as _,
|
||||
@@ -328,7 +329,7 @@ impl FlutterHandler {
|
||||
#[inline]
|
||||
#[cfg(feature = "flutter_texture_render")]
|
||||
pub fn register_texture(&mut self, ptr: usize) {
|
||||
self.renderer.write().unwrap().ptr = ptr;
|
||||
*self.renderer.read().unwrap().ptr.write().unwrap() = ptr;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -15,7 +15,7 @@ use flutter_rust_bridge::{StreamSink, SyncReturn};
|
||||
use hbb_common::allow_err;
|
||||
use hbb_common::{
|
||||
config::{self, LocalConfig, PeerConfig, PeerInfoSerde},
|
||||
fs, log,
|
||||
fs, lazy_static, log,
|
||||
message_proto::KeyboardMode,
|
||||
ResultType,
|
||||
};
|
||||
@@ -24,11 +24,19 @@ use std::{
|
||||
ffi::{CStr, CString},
|
||||
os::raw::c_char,
|
||||
str::FromStr,
|
||||
sync::{
|
||||
atomic::{AtomicI32, Ordering},
|
||||
Arc,
|
||||
},
|
||||
time::SystemTime,
|
||||
};
|
||||
|
||||
pub type SessionID = uuid::Uuid;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref TEXTURE_RENDER_KEY: Arc<AtomicI32> = Arc::new(AtomicI32::new(0));
|
||||
}
|
||||
|
||||
fn initialize(app_dir: &str) {
|
||||
*config::APP_DIR.write().unwrap() = app_dir.to_owned();
|
||||
#[cfg(target_os = "android")]
|
||||
@@ -197,6 +205,11 @@ pub fn session_set_flutter_config(session_id: SessionID, k: String, v: String) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_next_texture_key() -> SyncReturn<i32> {
|
||||
let k = TEXTURE_RENDER_KEY.fetch_add(1, Ordering::SeqCst) + 1;
|
||||
SyncReturn(k)
|
||||
}
|
||||
|
||||
pub fn get_local_flutter_config(k: String) -> SyncReturn<String> {
|
||||
SyncReturn(ui_interface::get_local_flutter_config(k))
|
||||
}
|
||||
|
||||
69
src/ui.rs
69
src/ui.rs
@@ -94,8 +94,7 @@ pub fn start(args: &mut [String]) {
|
||||
args[1] = id;
|
||||
}
|
||||
if args.is_empty() {
|
||||
let children: Children = Default::default();
|
||||
std::thread::spawn(move || check_zombie(children));
|
||||
std::thread::spawn(move || check_zombie());
|
||||
crate::common::check_software_update();
|
||||
frame.event_handler(UI {});
|
||||
frame.sciter_handler(UIHostHandler {});
|
||||
@@ -693,28 +692,6 @@ impl sciter::host::HostHandler for UIHostHandler {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn check_zombie(children: Children) {
|
||||
let mut deads = Vec::new();
|
||||
loop {
|
||||
let mut lock = children.lock().unwrap();
|
||||
let mut n = 0;
|
||||
for (id, c) in lock.1.iter_mut() {
|
||||
if let Ok(Some(_)) = c.try_wait() {
|
||||
deads.push(id.clone());
|
||||
n += 1;
|
||||
}
|
||||
}
|
||||
for ref id in deads.drain(..) {
|
||||
lock.1.remove(id);
|
||||
}
|
||||
if n > 0 {
|
||||
lock.0 = true;
|
||||
}
|
||||
drop(lock);
|
||||
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
fn get_sound_inputs() -> Vec<String> {
|
||||
let mut out = Vec::new();
|
||||
@@ -748,50 +725,6 @@ pub fn value_crash_workaround(values: &[Value]) -> Arc<Vec<Value>> {
|
||||
persist
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new_remote(id: String, remote_type: String, force_relay: bool) {
|
||||
let mut lock = CHILDREN.lock().unwrap();
|
||||
let mut args = vec![format!("--{}", remote_type), id.clone()];
|
||||
if force_relay {
|
||||
args.push("".to_string()); // password
|
||||
args.push("--relay".to_string());
|
||||
}
|
||||
let key = (id.clone(), remote_type.clone());
|
||||
if let Some(c) = lock.1.get_mut(&key) {
|
||||
if let Ok(Some(_)) = c.try_wait() {
|
||||
lock.1.remove(&key);
|
||||
} else {
|
||||
if remote_type == "rdp" {
|
||||
allow_err!(c.kill());
|
||||
std::thread::sleep(std::time::Duration::from_millis(30));
|
||||
c.try_wait().ok();
|
||||
lock.1.remove(&key);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
match crate::run_me(args) {
|
||||
Ok(child) => {
|
||||
lock.1.insert(key, child);
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!("Failed to spawn remote: {}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn recent_sessions_updated() -> bool {
|
||||
let mut children = CHILDREN.lock().unwrap();
|
||||
if children.0 {
|
||||
children.0 = false;
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_icon() -> String {
|
||||
// 128x128
|
||||
#[cfg(target_os = "macos")]
|
||||
|
||||
@@ -65,6 +65,7 @@ lazy_static::lazy_static! {
|
||||
static ref OPTION_SYNCED: Arc<Mutex<bool>> = Default::default();
|
||||
static ref OPTIONS : Arc<Mutex<HashMap<String, String>>> = Arc::new(Mutex::new(Config::get_options()));
|
||||
pub static ref SENDER : Mutex<mpsc::UnboundedSender<ipc::Data>> = Mutex::new(check_connect_status(true));
|
||||
static ref CHILDREN : Children = Default::default();
|
||||
}
|
||||
|
||||
const INIT_ASYNC_JOB_STATUS: &str = " ";
|
||||
@@ -827,11 +828,11 @@ pub fn check_super_user_permission() -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn check_zombie(children: Children) {
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios", feature = "flutter")))]
|
||||
pub fn check_zombie() {
|
||||
let mut deads = Vec::new();
|
||||
loop {
|
||||
let mut lock = children.lock().unwrap();
|
||||
let mut lock = CHILDREN.lock().unwrap();
|
||||
let mut n = 0;
|
||||
for (id, c) in lock.1.iter_mut() {
|
||||
if let Ok(Some(_)) = c.try_wait() {
|
||||
@@ -850,6 +851,51 @@ pub fn check_zombie(children: Children) {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios", feature = "flutter")))]
|
||||
pub fn recent_sessions_updated() -> bool {
|
||||
let mut children = CHILDREN.lock().unwrap();
|
||||
if children.0 {
|
||||
children.0 = false;
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios", feature = "flutter")))]
|
||||
pub fn new_remote(id: String, remote_type: String, force_relay: bool) {
|
||||
let mut lock = CHILDREN.lock().unwrap();
|
||||
let mut args = vec![format!("--{}", remote_type), id.clone()];
|
||||
if force_relay {
|
||||
args.push("".to_string()); // password
|
||||
args.push("--relay".to_string());
|
||||
}
|
||||
let key = (id.clone(), remote_type.clone());
|
||||
if let Some(c) = lock.1.get_mut(&key) {
|
||||
if let Ok(Some(_)) = c.try_wait() {
|
||||
lock.1.remove(&key);
|
||||
} else {
|
||||
if remote_type == "rdp" {
|
||||
allow_err!(c.kill());
|
||||
std::thread::sleep(std::time::Duration::from_millis(30));
|
||||
c.try_wait().ok();
|
||||
lock.1.remove(&key);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
match crate::run_me(args) {
|
||||
Ok(child) => {
|
||||
lock.1.insert(key, child);
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!("Failed to spawn remote: {}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure `SENDER` is inited here.
|
||||
#[inline]
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
|
||||
Reference in New Issue
Block a user