Merge pull request #1328 from Heap-Hop/flutter_desktop_fix_windows_build
flutter_desktop_cm fix Windows build & TODO clipboard_file
This commit is contained in:
commit
1d51023f44
@ -1660,9 +1660,6 @@ pub mod connection_manager {
|
|||||||
#[cfg(any(target_os = "android"))]
|
#[cfg(any(target_os = "android"))]
|
||||||
use scrap::android::call_main_service_set_by_name;
|
use scrap::android::call_main_service_set_by_name;
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
use crate::ipc::start_clipboard_file;
|
|
||||||
|
|
||||||
use crate::ipc::Data;
|
use crate::ipc::Data;
|
||||||
use crate::ipc::{self, new_listener, Connection};
|
use crate::ipc::{self, new_listener, Connection};
|
||||||
|
|
||||||
@ -1688,11 +1685,12 @@ pub mod connection_manager {
|
|||||||
|
|
||||||
static CLICK_TIME: AtomicI64 = AtomicI64::new(0);
|
static CLICK_TIME: AtomicI64 = AtomicI64::new(0);
|
||||||
|
|
||||||
enum ClipboardFileData {
|
// // TODO clipboard_file
|
||||||
#[cfg(windows)]
|
// enum ClipboardFileData {
|
||||||
Clip((i32, ipc::ClipbaordFile)),
|
// #[cfg(windows)]
|
||||||
Enable((i32, bool)),
|
// Clip((i32, ipc::ClipbaordFile)),
|
||||||
}
|
// Enable((i32, bool)),
|
||||||
|
// }
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
pub fn start_listen_ipc_thread() {
|
pub fn start_listen_ipc_thread() {
|
||||||
@ -1702,11 +1700,12 @@ pub mod connection_manager {
|
|||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
async fn start_ipc() {
|
async fn start_ipc() {
|
||||||
let (tx_file, _rx_file) = mpsc::unbounded_channel::<ClipboardFileData>();
|
// TODO clipboard_file
|
||||||
#[cfg(windows)]
|
// let (tx_file, _rx_file) = mpsc::unbounded_channel::<ClipboardFileData>();
|
||||||
let cm_clip = cm.clone();
|
// #[cfg(windows)]
|
||||||
#[cfg(windows)]
|
// let cm_clip = cm.clone();
|
||||||
std::thread::spawn(move || start_clipboard_file(cm_clip, _rx_file));
|
// #[cfg(windows)]
|
||||||
|
// std::thread::spawn(move || start_clipboard_file(cm_clip, _rx_file));
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
@ -1730,7 +1729,7 @@ pub mod connection_manager {
|
|||||||
Ok(stream) => {
|
Ok(stream) => {
|
||||||
log::debug!("Got new connection");
|
log::debug!("Got new connection");
|
||||||
let mut stream = Connection::new(stream);
|
let mut stream = Connection::new(stream);
|
||||||
let tx_file = tx_file.clone();
|
// let tx_file = tx_file.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
// for tmp use, without real conn id
|
// for tmp use, without real conn id
|
||||||
let conn_id_tmp = -1;
|
let conn_id_tmp = -1;
|
||||||
@ -1750,11 +1749,11 @@ pub mod connection_manager {
|
|||||||
Data::Login{id, is_file_transfer, port_forward, peer_id, name, authorized, keyboard, clipboard, audio, file, file_transfer_enabled, restart} => {
|
Data::Login{id, is_file_transfer, port_forward, peer_id, name, authorized, keyboard, clipboard, audio, file, file_transfer_enabled, restart} => {
|
||||||
log::debug!("conn_id: {}", id);
|
log::debug!("conn_id: {}", id);
|
||||||
conn_id = id;
|
conn_id = id;
|
||||||
tx_file.send(ClipboardFileData::Enable((id, file_transfer_enabled))).ok();
|
// tx_file.send(ClipboardFileData::Enable((id, file_transfer_enabled))).ok();
|
||||||
on_login(id, is_file_transfer, port_forward, peer_id, name, authorized, keyboard, clipboard, audio, file, restart, tx.clone());
|
on_login(id, is_file_transfer, port_forward, peer_id, name, authorized, keyboard, clipboard, audio, file, restart, tx.clone());
|
||||||
}
|
}
|
||||||
Data::Close => {
|
Data::Close => {
|
||||||
tx_file.send(ClipboardFileData::Enable((conn_id, false))).ok();
|
// tx_file.send(ClipboardFileData::Enable((conn_id, false))).ok();
|
||||||
log::info!("cm ipc connection closed from connection request");
|
log::info!("cm ipc connection closed from connection request");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1771,18 +1770,19 @@ pub mod connection_manager {
|
|||||||
Data::FS(fs) => {
|
Data::FS(fs) => {
|
||||||
handle_fs(fs, &mut write_jobs, &tx).await;
|
handle_fs(fs, &mut write_jobs, &tx).await;
|
||||||
}
|
}
|
||||||
#[cfg(windows)]
|
// TODO ClipbaordFile
|
||||||
Data::ClipbaordFile(_clip) => {
|
// #[cfg(windows)]
|
||||||
tx_file
|
// Data::ClipbaordFile(_clip) => {
|
||||||
.send(ClipboardFileData::Clip((id, _clip)))
|
// tx_file
|
||||||
.ok();
|
// .send(ClipboardFileData::Clip((id, _clip)))
|
||||||
}
|
// .ok();
|
||||||
#[cfg(windows)]
|
// }
|
||||||
Data::ClipboardFileEnabled(enabled) => {
|
// #[cfg(windows)]
|
||||||
tx_file
|
// Data::ClipboardFileEnabled(enabled) => {
|
||||||
.send(ClipboardFileData::Enable((id, enabled)))
|
// tx_file
|
||||||
.ok();
|
// .send(ClipboardFileData::Enable((id, enabled)))
|
||||||
}
|
// .ok();
|
||||||
|
// }
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
78
src/ipc.rs
78
src/ipc.rs
@ -1,7 +1,3 @@
|
|||||||
#[cfg(windows)]
|
|
||||||
use clipboard::{
|
|
||||||
create_cliprdr_context, empty_clipboard, get_rx_clip_client, server_clip_file, set_conn_enabled,
|
|
||||||
};
|
|
||||||
use std::{collections::HashMap, sync::atomic::Ordering};
|
use std::{collections::HashMap, sync::atomic::Ordering};
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
use std::{fs::File, io::prelude::*};
|
use std::{fs::File, io::prelude::*};
|
||||||
@ -494,80 +490,6 @@ pub async fn start_pa() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
|
||||||
pub async fn start_clipboard_file(
|
|
||||||
cm: ConnectionManager,
|
|
||||||
mut rx: mpsc::UnboundedReceiver<ClipboardFileData>,
|
|
||||||
) {
|
|
||||||
let mut cliprdr_context = None;
|
|
||||||
let mut rx_clip_client = 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)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
},
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(ClipboardFileData::Enable((id, enabled))) => {
|
|
||||||
if enabled && cliprdr_context.is_none() {
|
|
||||||
cliprdr_context = Some(match create_cliprdr_context(true, false) {
|
|
||||||
Ok(context) => {
|
|
||||||
log::info!("clipboard context for file transfer created.");
|
|
||||||
context
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
log::error!(
|
|
||||||
"Create clipboard context for file transfer: {}",
|
|
||||||
err.to_string()
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
set_conn_enabled(id, enabled);
|
|
||||||
if !enabled {
|
|
||||||
if let Some(ctx) = cliprdr_context.as_mut() {
|
|
||||||
empty_clipboard(ctx, id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
fn cmd_inner_send(cm: &ConnectionManager, id: i32, data: Data) {
|
|
||||||
let lock = cm.read().unwrap();
|
|
||||||
if id != 0 {
|
|
||||||
if let Some(s) = lock.senders.get(&id) {
|
|
||||||
allow_err!(s.send(data));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for s in lock.senders.values() {
|
|
||||||
allow_err!(s.send(data.clone()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
fn get_pid_file(postfix: &str) -> String {
|
fn get_pid_file(postfix: &str) -> String {
|
||||||
|
87
src/ui/cm.rs
87
src/ui/cm.rs
@ -1,7 +1,11 @@
|
|||||||
use crate::ipc::{self, new_listener, Connection, Data, start_pa};
|
#[cfg(target_os = "linux")]
|
||||||
#[cfg(windows)]
|
use crate::ipc::start_pa;
|
||||||
use crate::ipc::start_clipboard_file;
|
use crate::ipc::{self, new_listener, Connection, Data};
|
||||||
use crate::VERSION;
|
use crate::VERSION;
|
||||||
|
#[cfg(windows)]
|
||||||
|
use clipboard::{
|
||||||
|
create_cliprdr_context, empty_clipboard, get_rx_clip_client, server_clip_file, set_conn_enabled,
|
||||||
|
};
|
||||||
use hbb_common::fs::{
|
use hbb_common::fs::{
|
||||||
can_enable_overwrite_detection, get_string, is_write_need_confirmation, new_send_confirm,
|
can_enable_overwrite_detection, get_string, is_write_need_confirmation, new_send_confirm,
|
||||||
DigestCheckResult,
|
DigestCheckResult,
|
||||||
@ -158,7 +162,7 @@ impl ConnectionManager {
|
|||||||
id,
|
id,
|
||||||
file_num,
|
file_num,
|
||||||
mut files,
|
mut files,
|
||||||
overwrite_detection
|
overwrite_detection,
|
||||||
} => {
|
} => {
|
||||||
// cm has no show_hidden context
|
// cm has no show_hidden context
|
||||||
// dummy remote, show_hidden, is_remote
|
// dummy remote, show_hidden, is_remote
|
||||||
@ -435,7 +439,7 @@ impl sciter::EventHandler for ConnectionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ClipboardFileData {
|
pub enum ClipboardFileData {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
Clip((i32, ipc::ClipbaordFile)),
|
Clip((i32, ipc::ClipbaordFile)),
|
||||||
Enable((i32, bool)),
|
Enable((i32, bool)),
|
||||||
@ -537,3 +541,76 @@ async fn start_ipc(cm: ConnectionManager) {
|
|||||||
crate::platform::quit_gui();
|
crate::platform::quit_gui();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
#[tokio::main(flavor = "current_thread")]
|
||||||
|
pub async fn start_clipboard_file(
|
||||||
|
cm: ConnectionManager,
|
||||||
|
mut rx: mpsc::UnboundedReceiver<ClipboardFileData>,
|
||||||
|
) {
|
||||||
|
let mut cliprdr_context = None;
|
||||||
|
let mut rx_clip_client = 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)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
},
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(ClipboardFileData::Enable((id, enabled))) => {
|
||||||
|
if enabled && cliprdr_context.is_none() {
|
||||||
|
cliprdr_context = Some(match create_cliprdr_context(true, false) {
|
||||||
|
Ok(context) => {
|
||||||
|
log::info!("clipboard context for file transfer created.");
|
||||||
|
context
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
log::error!(
|
||||||
|
"Create clipboard context for file transfer: {}",
|
||||||
|
err.to_string()
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
set_conn_enabled(id, enabled);
|
||||||
|
if !enabled {
|
||||||
|
if let Some(ctx) = cliprdr_context.as_mut() {
|
||||||
|
empty_clipboard(ctx, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn cmd_inner_send(cm: &ConnectionManager, id: i32, data: Data) {
|
||||||
|
let lock = cm.read().unwrap();
|
||||||
|
if id != 0 {
|
||||||
|
if let Some(s) = lock.senders.get(&id) {
|
||||||
|
allow_err!(s.send(data));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for s in lock.senders.values() {
|
||||||
|
allow_err!(s.send(data.clone()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user