Skip to content

Commit

Permalink
refact: file copy&paste, cross platform (no macOS) (rustdesk#10671)
Browse files Browse the repository at this point in the history
* feat: unix, file copy&paste

Signed-off-by: fufesou <linlong1266@gmail.com>

* refact: unix file c&p, check peer version

Signed-off-by: fufesou <linlong1266@gmail.com>

* Update pubspec.yaml

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
Co-authored-by: RustDesk <71636191+rustdesk@users.noreply.github.com>
  • Loading branch information
fufesou and rustdesk authored Feb 4, 2025
1 parent a27fa43 commit fbba8f0
Show file tree
Hide file tree
Showing 42 changed files with 2,021 additions and 1,773 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/flutter-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
# vcpkg version: 2025.01.13
VCPKG_COMMIT_ID: "6f29f12e82a8293156836ad81cc9bf5af41fe836"
VERSION: "1.3.7"
VERSION: "1.3.8"
NDK_VERSION: "r27c"
#signing keys env variable checks
ANDROID_SIGNING_KEY: "${{ secrets.ANDROID_SIGNING_KEY }}"
Expand Down Expand Up @@ -415,7 +415,7 @@ jobs:

- name: Build rustdesk
run: |
./build.py --flutter --hwcodec
./build.py --flutter --hwcodec --unix-file-copy-paste
- name: create unsigned dmg
if: env.UPLOAD_ARTIFACT == 'true'
Expand Down Expand Up @@ -796,7 +796,7 @@ jobs:
sed -i -e "s/osx_minimum_system_version = \"[0-9]*.[0-9]*\"/osx_minimum_system_version = \"${MIN_MACOS_VERSION}\"/" Cargo.toml
sed -i -e "s/MACOSX_DEPLOYMENT_TARGET = [0-9]*.[0-9]*;/MACOSX_DEPLOYMENT_TARGET = ${MIN_MACOS_VERSION};/" flutter/macos/Runner.xcodeproj/project.pbxproj
fi
./build.py --flutter --hwcodec ${{ matrix.job.extra-build-args }}
./build.py --flutter --hwcodec --unix-file-copy-paste ${{ matrix.job.extra-build-args }}
- name: create unsigned dmg
if: env.UPLOAD_ARTIFACT == 'true'
Expand Down Expand Up @@ -1554,7 +1554,7 @@ jobs:
export JOBS=""
fi
echo $JOBS
cargo build --lib $JOBS --features hwcodec,flutter --release
cargo build --lib $JOBS --features hwcodec,flutter,unix-file-copy-paste --release
rm -rf target/release/deps target/release/build
rm -rf ~/.cargo
Expand Down Expand Up @@ -1706,7 +1706,7 @@ jobs:
deb_arch: amd64,
sciter_arch: x64,
vcpkg-triplet: x64-linux,
extra_features: ",hwcodec",
extra_features: ",hwcodec,unix-file-copy-paste",
}
- {
arch: armv7,
Expand All @@ -1716,7 +1716,7 @@ jobs:
deb_arch: armhf,
sciter_arch: arm32,
vcpkg-triplet: arm-linux,
extra_features: "",
extra_features: ",unix-file-copy-paste",
}
steps:
- name: Export GitHub Actions cache environment variables
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/playground.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
# vcpkg version: 2024.11.16
VCPKG_COMMIT_ID: "b2cb0da531c2f1f740045bfe7c4dac59f0b2b69c"
VERSION: "1.3.7"
VERSION: "1.3.8"
NDK_VERSION: "r26d"
#signing keys env variable checks
ANDROID_SIGNING_KEY: "${{ secrets.ANDROID_SIGNING_KEY }}"
Expand Down
44 changes: 22 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustdesk"
version = "1.3.7"
version = "1.3.8"
authors = ["rustdesk <info@rustdesk.com>"]
edition = "2021"
build= "build.rs"
Expand Down
2 changes: 1 addition & 1 deletion appimage/AppImageBuilder-aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ AppDir:
id: rustdesk
name: rustdesk
icon: rustdesk
version: 1.3.7
version: 1.3.8
exec: usr/share/rustdesk/rustdesk
exec_args: $@
apt:
Expand Down
2 changes: 1 addition & 1 deletion appimage/AppImageBuilder-x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ AppDir:
id: rustdesk
name: rustdesk
icon: rustdesk
version: 1.3.7
version: 1.3.8
exec: usr/share/rustdesk/rustdesk
exec_args: $@
apt:
Expand Down
2 changes: 1 addition & 1 deletion flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# 1.1.9-1 works for android, but for ios it becomes 1.1.91, need to set it to 1.1.9-a.1 for iOS, will get 1.1.9.1, but iOS store not allow 4 numbers
version: 1.3.7+56
version: 1.3.8+57

environment:
sdk: '^3.1.0'
Expand Down
2 changes: 1 addition & 1 deletion libs/clipboard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ parking_lot = {version = "0.12"}

[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies]
rand = {version = "0.8", optional = true}
fuser = {version = "0.13", optional = true}
libc = {version = "0.2", optional = true}
dashmap = {version ="5.5", optional = true}
utf16string = {version = "0.2", optional = true}
Expand All @@ -44,6 +43,7 @@ once_cell = {version = "1.18", optional = true}
percent-encoding = {version ="2.3", optional = true}
x11-clipboard = {git="https://github.com/clslaid/x11-clipboard", branch = "feat/store-batch", optional = true}
x11rb = {version = "0.12", features = ["all-extensions"], optional = true}
fuser = {version = "0.15", default-features = false, optional = true}

[target.'cfg(target_os = "macos")'.dependencies]
cacao = {git="https://github.com/clslaid/cacao", branch = "feat/set-file-urls", optional = true}
63 changes: 40 additions & 23 deletions libs/clipboard/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
#[allow(dead_code)]
use std::{
path::PathBuf,
sync::{Arc, Mutex, RwLock},
};
use std::sync::{Arc, Mutex, RwLock};

#[cfg(any(target_os = "windows", feature = "unix-file-copy-paste",))]
use hbb_common::{allow_err, bail};
#[cfg(target_os = "windows")]
use hbb_common::ResultType;
#[cfg(any(target_os = "windows", feature = "unix-file-copy-paste"))]
use hbb_common::{allow_err, log};
use hbb_common::{
lazy_static,
tokio::sync::{
mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender},
Mutex as TokioMutex,
},
ResultType,
};
use serde_derive::{Deserialize, Serialize};
use thiserror::Error;

#[cfg(target_os = "windows")]
pub mod context_send;
pub mod platform;
#[cfg(target_os = "windows")]
pub use context_send::*;

#[cfg(target_os = "windows")]
Expand All @@ -28,8 +27,10 @@ const ERR_CODE_INVALID_PARAMETER: u32 = 0x00000002;
#[cfg(target_os = "windows")]
const ERR_CODE_SEND_MSG: u32 = 0x00000003;

#[cfg(target_os = "windows")]
pub(crate) use platform::create_cliprdr_context;

// to-do: This trait may be removed, because unix file copy paste does not need it.
/// Ability to handle Clipboard File from remote rustdesk client
///
/// # Note
Expand All @@ -41,7 +42,6 @@ pub trait CliprdrServiceContext: Send + Sync {
fn set_is_stopped(&mut self) -> Result<(), CliprdrError>;
/// clear the content on clipboard
fn empty_clipboard(&mut self, conn_id: i32) -> Result<bool, CliprdrError>;

/// run as a server for clipboard RPC
fn server_clip_file(&mut self, conn_id: i32, msg: ClipboardFile) -> Result<(), CliprdrError>;
}
Expand All @@ -63,9 +63,11 @@ pub enum CliprdrError {
#[error("failure to read clipboard")]
OpenClipboard,
#[error("failure to read file metadata or content")]
FileError { path: PathBuf, err: std::io::Error },
FileError { path: String, err: std::io::Error },
#[error("invalid request")]
InvalidRequest { description: String },
#[error("common request")]
CommonError { description: String },
#[error("unknown cliprdr error")]
Unknown(u32),
}
Expand Down Expand Up @@ -199,52 +201,67 @@ pub fn get_rx_cliprdr_server(conn_id: i32) -> Arc<TokioMutex<UnboundedReceiver<C
}
}

#[cfg(any(target_os = "windows", feature = "unix-file-copy-paste",))]
pub fn remove_channel_by_conn_id(conn_id: i32) {
let mut lock = VEC_MSG_CHANNEL.write().unwrap();
if let Some(index) = lock.iter().position(|x| x.conn_id == conn_id) {
lock.remove(index);
}
}

#[cfg(any(target_os = "windows", feature = "unix-file-copy-paste"))]
#[inline]
fn send_data(conn_id: i32, data: ClipboardFile) -> ResultType<()> {
pub fn send_data(conn_id: i32, data: ClipboardFile) -> Result<(), CliprdrError> {
#[cfg(target_os = "windows")]
return send_data_to_channel(conn_id, data);
#[cfg(not(target_os = "windows"))]
if conn_id == 0 {
send_data_to_all(data);
let _ = send_data_to_all(data);
Ok(())
} else {
send_data_to_channel(conn_id, data);
send_data_to_channel(conn_id, data)
}
}
#[cfg(any(target_os = "windows", feature = "unix-file-copy-paste",))]

#[inline]
fn send_data_to_channel(conn_id: i32, data: ClipboardFile) -> ResultType<()> {
#[cfg(any(target_os = "windows", feature = "unix-file-copy-paste"))]
fn send_data_to_channel(conn_id: i32, data: ClipboardFile) -> Result<(), CliprdrError> {
if let Some(msg_channel) = VEC_MSG_CHANNEL
.read()
.unwrap()
.iter()
.find(|x| x.conn_id == conn_id)
{
msg_channel.sender.send(data)?;
Ok(())
msg_channel
.sender
.send(data)
.map_err(|e| CliprdrError::CommonError {
description: e.to_string(),
})
} else {
bail!("conn_id not found");
Err(CliprdrError::InvalidRequest {
description: "conn_id not found".to_string(),
})
}
}

#[inline]
#[cfg(target_os = "windows")]
pub fn send_data_exclude(conn_id: i32, data: ClipboardFile) {
use hbb_common::log;
// Need more tests to see if it's necessary to handle the error.
for msg_channel in VEC_MSG_CHANNEL.read().unwrap().iter() {
if msg_channel.conn_id != conn_id {
allow_err!(msg_channel.sender.send(data.clone()));
}
}
}

#[cfg(feature = "unix-file-copy-paste")]
#[inline]
fn send_data_to_all(data: ClipboardFile) -> ResultType<()> {
#[cfg(feature = "unix-file-copy-paste")]
fn send_data_to_all(data: ClipboardFile) {
// Need more tests to see if it's necessary to handle the error.
for msg_channel in VEC_MSG_CHANNEL.read().unwrap().iter() {
allow_err!(msg_channel.sender.send(data.clone()));
}
Ok(())
}

#[cfg(test)]
Expand Down
Loading

0 comments on commit fbba8f0

Please sign in to comment.