mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-09-18 10:21:03 +03:00
add the base crate and repoint the moved modules at it (#16107)
* add the base crate and repoint the moved modules at it `libs/base` (crate `base`) takes the parts of hbb_common that only this app uses: `fs`, `platform`, `keyboard`, `message.proto`, and 145 of the 177 `config::keys` constants. hbb_common keeps what the server names, and the 32 keys it reads itself are re-exported from `base::config::keys` so call sites still see the full set through one path. Sources move verbatim. The only edits inside them are `crate::` prefixes that now have to say `hbb_common::`; `keyboard.rs` and `platform/windows.rs` are byte-identical. The crate stays on edition 2018, the edition the moved code was written under. `log`, `lazy_static` and `anyhow` become direct dependencies so the bare paths in that code resolve exactly as before, and its winapi features are spelled out rather than left to feature unification. Two call sites outside Rust and Cargo had to follow the move: the Android protobuf source dir, which still pointed at hbb_common/protos for message.proto, and the three AGENTS.md entries that named hbb_common for options, protos and file transfer. `scrap`'s `drm` feature now forwards to `base/wayland_probe`. Left pointing at hbb_common it would still have compiled, silently dropping the Wayland socket-probe fallback, so that forward is verified by a build with and without the feature. `config::keys` carries a test asserting its names stay disjoint from the ones hbb_common kept: the glob re-export and the local constants share a namespace, and Rust prefers the local item silently, so a name added to both sides would otherwise let client and server disagree with no diagnostic. Verified: macOS and Linux, debug and release, `--all-targets`; the 177 key constants diffed name-for-name and value-for-value; the generated protobuf types compared before and after; every `#[cfg]` gate on a moved import checked against its original; and every file that was `rustfmt`-clean before this change still is, compared against master file by file. Windows is checked by inspection only -- it cannot be compiled here. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EZ49AbZJYfm8NTp5yDPMab * one `use` per crate, and write the rule down `fs.rs` came out of the move with two ungated `use hbb_common::` statements, because the original single `use crate::{...}` had to give up `message_proto` to the new crate and the rest was left in a second block. Fold it back into one. A scan of the whole tree for the same shape finds nothing else: every other file with more than one top-level `use base::` or `use hbb_common::` is split by a `#[cfg]` that does not cover the whole block, or by `pub use` next to `use`. Those are the cases that cannot merge, so AGENTS.md now states both the rule and the exemption. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EZ49AbZJYfm8NTp5yDPMab --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,12 +11,14 @@ pub use crate::{
|
||||
clipboard::{check_clipboard_files, FILE_CLIPBOARD_NAME as FILE_NAME},
|
||||
clipboard_file::unix_file_clip,
|
||||
};
|
||||
#[cfg(target_os = "android")]
|
||||
use base::config::keys;
|
||||
#[cfg(all(feature = "unix-file-copy-paste", target_os = "linux"))]
|
||||
use clipboard::platform::unix::fuse::{init_fuse_context, uninit_fuse_context};
|
||||
#[cfg(not(target_os = "android"))]
|
||||
use clipboard_master::CallbackResult;
|
||||
#[cfg(target_os = "android")]
|
||||
use hbb_common::config::{keys, option2bool};
|
||||
use hbb_common::config::option2bool;
|
||||
#[cfg(target_os = "android")]
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::{
|
||||
|
||||
@@ -30,13 +30,11 @@ use hbb_common::protobuf::EnumOrUnknown;
|
||||
use hbb_common::{
|
||||
config::{
|
||||
self, decode_permanent_password_h1_from_storage, decode_preset_password_h1_from_storage,
|
||||
keys, local_permanent_password_storage_is_usable_for_auth,
|
||||
local_permanent_password_storage_is_usable_for_auth,
|
||||
preset_permanent_password_storage_is_usable_for_auth, Config, TrustedDevice,
|
||||
},
|
||||
fs::{self, can_enable_overwrite_detection, JobType},
|
||||
futures::{SinkExt, StreamExt},
|
||||
get_time, get_version_number,
|
||||
message_proto::{option_message::BoolOption, permission_info::Permission},
|
||||
password_security::{self as password, ApproveMode},
|
||||
sha2::{Digest, Sha256},
|
||||
sleep, timeout,
|
||||
@@ -47,6 +45,11 @@ use hbb_common::{
|
||||
},
|
||||
tokio_util::codec::{BytesCodec, Framed},
|
||||
};
|
||||
use base::{
|
||||
config::keys,
|
||||
fs::{self, can_enable_overwrite_detection, JobType},
|
||||
message_proto::{option_message::BoolOption, permission_info::Permission},
|
||||
};
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
use scrap::android::{call_main_service_key_event, call_main_service_pointer_input};
|
||||
use scrap::camera;
|
||||
@@ -5980,7 +5983,7 @@ impl Connection {
|
||||
"Process clipboard message from clip, stop: {}, is_stopping_allowed: {}, file_transfer_enabled: {}",
|
||||
stop, is_stopping_allowed, file_transfer_enabled);
|
||||
if !stop {
|
||||
use hbb_common::config::keys::OPTION_ONE_WAY_FILE_TRANSFER;
|
||||
use base::config::keys::OPTION_ONE_WAY_FILE_TRANSFER;
|
||||
// Note: Code will not reach here if `crate::get_builtin_option(OPTION_ONE_WAY_FILE_TRANSFER) == "Y"` is true.
|
||||
// Because `file-clipboard` service will not be subscribed.
|
||||
// But we still check it here to keep the same logic to windows version in `ui_cm_interface.rs`.
|
||||
|
||||
@@ -158,7 +158,7 @@ pub(super) fn set_wayland_layout_baseline(baseline: Vec<scrap::wayland::display:
|
||||
/// before taking that layout. See `WaylandLayout::note_capturer`.
|
||||
#[cfg(all(target_os = "linux", feature = "drm"))]
|
||||
pub(super) fn note_capturer_layout(
|
||||
displays: &[hbb_common::platform::linux::WaylandDisplayInfo],
|
||||
displays: &[base::platform::linux::WaylandDisplayInfo],
|
||||
built_gen: u64,
|
||||
) {
|
||||
if displays.is_empty() {
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
// privileged export (open + grab the scanout dma-buf fd), the EGL detile / RGBA convert runs here.
|
||||
|
||||
use crate::ipc::{connect_drm, Data, DrmDisplayInfo};
|
||||
use hbb_common::{anyhow::anyhow, bail, log, message_proto::DisplayInfo, tokio, ResultType};
|
||||
use hbb_common::{anyhow::anyhow, bail, log, tokio, ResultType};
|
||||
use base::message_proto::DisplayInfo;
|
||||
use scrap::drm_render::RenderConverter;
|
||||
use scrap::drmtap_dl::drmtap_dmabuf_desc;
|
||||
use scrap::{Frame, Pixfmt, PixelBuffer, TraitCapturer};
|
||||
@@ -1581,7 +1582,7 @@ fn augment_with_wayland_geometry_from(
|
||||
/// earlier connector must never steal an exact name match from a later one.
|
||||
fn identity_matches(
|
||||
drm: &[DrmDisplayInfo],
|
||||
wl: &[hbb_common::platform::linux::WaylandDisplayInfo],
|
||||
wl: &[base::platform::linux::WaylandDisplayInfo],
|
||||
) -> Vec<Option<usize>> {
|
||||
let mut taken = vec![false; wl.len()];
|
||||
let mut matched: Vec<Option<usize>> = vec![None; drm.len()];
|
||||
@@ -1621,7 +1622,7 @@ fn identity_matches(
|
||||
|
||||
fn assign_wayland_outputs(
|
||||
drm: &[DrmDisplayInfo],
|
||||
wl: &[hbb_common::platform::linux::WaylandDisplayInfo],
|
||||
wl: &[base::platform::linux::WaylandDisplayInfo],
|
||||
) -> Vec<Option<usize>> {
|
||||
let mut matched = identity_matches(drm, wl);
|
||||
let mut taken = vec![false; wl.len()];
|
||||
@@ -2107,8 +2108,8 @@ mod drm_capturer_tests {
|
||||
y: i32,
|
||||
w: i32,
|
||||
h: i32,
|
||||
) -> hbb_common::platform::linux::WaylandDisplayInfo {
|
||||
hbb_common::platform::linux::WaylandDisplayInfo {
|
||||
) -> base::platform::linux::WaylandDisplayInfo {
|
||||
base::platform::linux::WaylandDisplayInfo {
|
||||
name: name.to_owned(),
|
||||
x,
|
||||
y,
|
||||
|
||||
@@ -4,14 +4,13 @@ use super::*;
|
||||
use crate::input::*;
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
use crate::whiteboard;
|
||||
use base::message_proto::{
|
||||
pointer_device_event::Union::TouchEvent, touch_event::Union::ScaleUpdate,
|
||||
};
|
||||
#[cfg(target_os = "macos")]
|
||||
use dispatch::Queue;
|
||||
use enigo::{Enigo, Key, KeyboardControllable, MouseButton, MouseControllable};
|
||||
use hbb_common::{
|
||||
get_time,
|
||||
message_proto::{pointer_device_event::Union::TouchEvent, touch_event::Union::ScaleUpdate},
|
||||
protobuf::EnumOrUnknown,
|
||||
};
|
||||
use hbb_common::{get_time, protobuf::EnumOrUnknown};
|
||||
use rdev::{self, EventType, Key as RdevKey, KeyCode, RawKey};
|
||||
#[cfg(target_os = "macos")]
|
||||
use rdev::{CGEventSourceStateID, CGEventTapLocation, VirtualInput};
|
||||
|
||||
@@ -6,10 +6,10 @@ use crate::port_forward_mux::{
|
||||
use hbb_common::{
|
||||
bytes::Bytes,
|
||||
log,
|
||||
message_proto::*,
|
||||
timeout,
|
||||
tokio::{self, net::TcpStream, sync::{mpsc, watch}},
|
||||
};
|
||||
use base::message_proto::*;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
sync::{Arc, Mutex},
|
||||
@@ -262,7 +262,6 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::port_forward_mux::{CHANNEL_WINDOW, INITIAL_WINDOW, MAX_CHANNELS, MIN_FRAME_CHARGE};
|
||||
use hbb_common::{
|
||||
message_proto::{message, port_forward_channel},
|
||||
tokio::{
|
||||
self,
|
||||
io::{AsyncReadExt, AsyncWriteExt},
|
||||
@@ -271,6 +270,7 @@ mod tests {
|
||||
time::Instant,
|
||||
},
|
||||
};
|
||||
use base::message_proto::{message, port_forward_channel};
|
||||
|
||||
fn rt() -> tokio::runtime::Runtime {
|
||||
tokio::runtime::Builder::new_current_thread()
|
||||
|
||||
@@ -6,12 +6,12 @@ use crate::{
|
||||
validate_path_for_portable_service_shmem_dir,
|
||||
},
|
||||
};
|
||||
use base::message_proto::{KeyEvent, MouseEvent};
|
||||
use core::slice;
|
||||
use hbb_common::{
|
||||
allow_err,
|
||||
anyhow::anyhow,
|
||||
bail, libc, log,
|
||||
message_proto::{KeyEvent, MouseEvent},
|
||||
protobuf::Message,
|
||||
tokio::{self, sync::mpsc},
|
||||
ResultType,
|
||||
@@ -435,7 +435,7 @@ mod utils {
|
||||
|
||||
// functions called in separate SYSTEM user process.
|
||||
pub mod server {
|
||||
use hbb_common::message_proto::PointerDeviceEvent;
|
||||
use base::message_proto::PointerDeviceEvent;
|
||||
|
||||
use crate::display_service;
|
||||
|
||||
@@ -826,7 +826,8 @@ pub mod server {
|
||||
pub mod client {
|
||||
use super::*;
|
||||
use crate::display_service;
|
||||
use hbb_common::{anyhow::Context, message_proto::PointerDeviceEvent};
|
||||
use base::message_proto::PointerDeviceEvent;
|
||||
use hbb_common::anyhow::Context;
|
||||
use scrap::PixelBuffer;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
|
||||
@@ -9,7 +9,7 @@ use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub mod client {
|
||||
use hbb_common::platform::linux::{DISPLAY_DESKTOP_KDE, XDG_CURRENT_DESKTOP};
|
||||
use base::platform::linux::{DISPLAY_DESKTOP_KDE, XDG_CURRENT_DESKTOP};
|
||||
|
||||
use super::*;
|
||||
|
||||
|
||||
@@ -1076,7 +1076,7 @@ fn get_recorder(
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
fn check_change_scale(hardware: bool) -> ResultType<()> {
|
||||
use hbb_common::config::keys::OPTION_ENABLE_ANDROID_SOFTWARE_ENCODING_HALF_SCALE as SCALE_SOFT;
|
||||
use base::config::keys::OPTION_ENABLE_ANDROID_SOFTWARE_ENCODING_HALF_SCALE as SCALE_SOFT;
|
||||
|
||||
// isStart flag is set at the end of startCapture() in Android, wait it to be set.
|
||||
let n = 60; // 3s
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use super::*;
|
||||
use hbb_common::{allow_err, anyhow, platform::linux::DISTRO};
|
||||
use hbb_common::{allow_err, anyhow};
|
||||
use base::platform::linux::DISTRO;
|
||||
use scrap::{
|
||||
is_cursor_embedded, set_map_err,
|
||||
wayland::pipewire::{fill_displays, try_fix_logical_size},
|
||||
|
||||
Reference in New Issue
Block a user