diff --git a/src/client/io_loop.rs b/src/client/io_loop.rs index 54c3be26e..552fea7a8 100644 --- a/src/client/io_loop.rs +++ b/src/client/io_loop.rs @@ -43,7 +43,7 @@ pub struct Remote { last_update_jobs_status: (Instant, HashMap), first_frame: bool, #[cfg(windows)] - clipboard_file_context: Option>, + clipboard_file_context: Option>, data_count: Arc, frame_count: Arc, video_format: CodecFormat, @@ -107,7 +107,7 @@ impl Remote { #[cfg(not(windows))] let (_tx_holder, mut rx_clip_client) = mpsc::unbounded_channel::(); #[cfg(windows)] - let mut rx_clip_client = get_rx_clip_client().lock().await; + let mut rx_clip_client = clipboard::get_rx_clip_client().lock().await; let mut status_timer = time::interval(Duration::new(1, 0)); @@ -153,7 +153,7 @@ impl Remote { #[cfg(windows)] match _msg { Some((_, clip)) => { - allow_err!(peer.send(&clip_2_msg(clip)).await); + allow_err!(peer.send(&crate::clipboard_file::clip_2_msg(clip)).await); } None => { // unreachable!() @@ -357,7 +357,13 @@ impl Remote { to, job.files().len() ); - self.handler.update_folder_files(job.id(), job.files(), path,!is_remote, true); + self.handler.update_folder_files( + job.id(), + job.files(), + path, + !is_remote, + true, + ); #[cfg(not(windows))] let files = job.files().clone(); #[cfg(windows)] @@ -416,7 +422,13 @@ impl Remote { to, job.files().len() ); - self.handler.update_folder_files(job.id(), job.files(), path,!is_remote, true); + self.handler.update_folder_files( + job.id(), + job.files(), + path, + !is_remote, + true, + ); job.is_last_job = true; self.read_jobs.push(job); self.timer = time::interval(MILLI1); @@ -528,7 +540,13 @@ impl Remote { } else { match fs::get_recursive_files(&path, include_hidden) { Ok(entries) => { - self.handler.update_folder_files(id, &entries, path.clone(),!is_remote, false); + self.handler.update_folder_files( + id, + &entries, + path.clone(), + !is_remote, + false, + ); self.remove_jobs .insert(id, RemoveJob::new(entries, path, sep, is_remote)); } @@ -785,8 +803,8 @@ impl Remote { Some(message::Union::Cliprdr(clip)) => { if !self.handler.lc.read().unwrap().disable_clipboard { if let Some(context) = &mut self.clipboard_file_context { - if let Some(clip) = msg_2_clip(clip) { - server_clip_file(context, 0, clip); + if let Some(clip) = crate::clipboard_file::msg_2_clip(clip) { + clipboard::server_clip_file(context, 0, clip); } } } @@ -804,7 +822,13 @@ impl Remote { fs::transform_windows_path(&mut entries); } } - self.handler.update_folder_files(fd.id, &entries, fd.path, false, fd.id > 0); + self.handler.update_folder_files( + fd.id, + &entries, + fd.path, + false, + fd.id > 0, + ); if let Some(job) = fs::get_job(fd.id, &mut self.write_jobs) { log::info!("job set_files: {:?}", entries); job.set_files(entries); @@ -1132,7 +1156,7 @@ impl Remote { && self.handler.lc.read().unwrap().enable_file_transfer; if enabled == self.clipboard_file_context.is_none() { self.clipboard_file_context = if enabled { - match create_clipboard_file_context(true, false) { + match clipboard::create_cliprdr_context(true, false) { Ok(context) => { log::info!("clipboard context for file transfer created."); Some(context) diff --git a/src/flutter.rs b/src/flutter.rs index a3c7ea70f..1c4ed8869 100644 --- a/src/flutter.rs +++ b/src/flutter.rs @@ -396,13 +396,10 @@ pub mod connection_manager { #[cfg(not(any(target_os = "android", target_os = "ios")))] pub fn start_listen_ipc_thread() { - use crate::{ - ipc::start_pa, - ui_cm_interface::{start_ipc, ConnectionManager}, - }; + use crate::ui_cm_interface::{start_ipc, ConnectionManager}; #[cfg(target_os = "linux")] - std::thread::spawn(start_pa); + std::thread::spawn(crate::ipc::start_pa); let cm = ConnectionManager { ui_handler: FlutterHandler {}, @@ -411,7 +408,7 @@ pub mod connection_manager { } #[cfg(target_os = "android")] - use hbb_common::tokio::sync::mpsc::{UnboundedReceiver,UnboundedSender}; + use hbb_common::tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender}; #[cfg(target_os = "android")] pub fn start_channel( diff --git a/src/ui/remote.rs b/src/ui/remote.rs index f6b3acec6..08430110c 100644 --- a/src/ui/remote.rs +++ b/src/ui/remote.rs @@ -1,10 +1,7 @@ use std::{ collections::HashMap, ops::{Deref, DerefMut}, - sync::{ - atomic::Ordering, - Arc, Mutex, - }, + sync::{atomic::Ordering, Arc, Mutex}, }; use sciter::{ @@ -40,9 +37,6 @@ lazy_static::lazy_static! { static ref VIDEO: Arc>> = Default::default(); } -#[cfg(windows)] -static mut IS_ALT_GR: bool = false; - /// SciterHandler /// * element /// * close_state for file path when close diff --git a/src/ui_cm_interface.rs b/src/ui_cm_interface.rs index b9045532b..d416fdd63 100644 --- a/src/ui_cm_interface.rs +++ b/src/ui_cm_interface.rs @@ -268,19 +268,18 @@ pub async fn start_ipc(cm: ConnectionManager) { Data::FS(fs) => { handle_fs(fs, &mut write_jobs, &tx).await; } - // TODO ClipbaordFile - // #[cfg(windows)] - // Data::ClipbaordFile(_clip) => { - // tx_file - // .send(ClipboardFileData::Clip((id, _clip))) - // .ok(); - // } - // #[cfg(windows)] - // Data::ClipboardFileEnabled(enabled) => { - // tx_file - // .send(ClipboardFileData::Enable((id, enabled))) - // .ok(); - // } + #[cfg(windows)] + Data::ClipbaordFile(_clip) => { + tx_file + .send(ClipboardFileData::Clip((conn_id, _clip))) + .ok(); + } + #[cfg(windows)] + Data::ClipboardFileEnabled(enabled) => { + tx_file + .send(ClipboardFileData::Enable((conn_id, enabled))) + .ok(); + } _ => { } @@ -316,7 +315,11 @@ pub async fn start_ipc(cm: ConnectionManager) { #[cfg(target_os = "android")] #[tokio::main(flavor = "current_thread")] -pub async fn start_listen(cm: ConnectionManager, mut rx: mpsc::UnboundedReceiver, tx: mpsc::UnboundedSender) { +pub async fn start_listen( + cm: ConnectionManager, + mut rx: mpsc::UnboundedReceiver, + tx: mpsc::UnboundedSender, +) { let mut current_id = 0; let mut write_jobs: Vec = Vec::new(); loop { @@ -596,19 +599,18 @@ fn send_raw(msg: Message, tx: &UnboundedSender) { #[cfg(windows)] #[tokio::main(flavor = "current_thread")] -pub async fn start_clipboard_file( - cm: ConnectionManager, +pub async fn start_clipboard_file( + cm: ConnectionManager, mut rx: mpsc::UnboundedReceiver, ) { let mut cliprdr_context = None; - let mut rx_clip_client = get_rx_clip_client().lock().await; + let mut rx_clip_client = clipboard::get_rx_clip_client().lock().await; loop { tokio::select! { clip_file = rx_clip_client.recv() => match clip_file { Some((conn_id, clip)) => { cmd_inner_send( - &cm, conn_id, Data::ClipbaordFile(clip) ); @@ -620,12 +622,12 @@ pub async fn start_clipboard_file( server_msg = rx.recv() => match server_msg { Some(ClipboardFileData::Clip((conn_id, clip))) => { if let Some(ctx) = cliprdr_context.as_mut() { - server_clip_file(ctx, conn_id, clip); + clipboard::server_clip_file(ctx, conn_id, clip); } } Some(ClipboardFileData::Enable((id, enabled))) => { if enabled && cliprdr_context.is_none() { - cliprdr_context = Some(match create_cliprdr_context(true, false) { + cliprdr_context = Some(match clipboard::create_cliprdr_context(true, false) { Ok(context) => { log::info!("clipboard context for file transfer created."); context @@ -639,10 +641,10 @@ pub async fn start_clipboard_file( } }); } - set_conn_enabled(id, enabled); + clipboard::set_conn_enabled(id, enabled); if !enabled { if let Some(ctx) = cliprdr_context.as_mut() { - empty_clipboard(ctx, id); + clipboard::empty_clipboard(ctx, id); } } } @@ -655,15 +657,15 @@ pub async fn start_clipboard_file( } #[cfg(windows)] -fn cmd_inner_send(cm: &ConnectionManager, id: i32, data: Data) { - let lock = cm.read().unwrap(); +fn cmd_inner_send(id: i32, data: Data) { + let lock = CLIENTS.read().unwrap(); if id != 0 { - if let Some(s) = lock.senders.get(&id) { - allow_err!(s.send(data)); + if let Some(s) = lock.get(&id) { + allow_err!(s.tx.send(data)); } } else { - for s in lock.senders.values() { - allow_err!(s.send(data.clone())); + for s in lock.values() { + allow_err!(s.tx.send(data.clone())); } } } diff --git a/src/ui_session_interface.rs b/src/ui_session_interface.rs index 9fca2dfbb..717963561 100644 --- a/src/ui_session_interface.rs +++ b/src/ui_session_interface.rs @@ -26,6 +26,9 @@ use std::sync::{Arc, Mutex, RwLock}; pub static IS_IN: AtomicBool = AtomicBool::new(false); static KEYBOARD_HOOKED: AtomicBool = AtomicBool::new(false); +#[cfg(windows)] +static mut IS_ALT_GR: bool = false; + #[derive(Clone, Default)] pub struct Session { pub cmd: String,