improve ffi enum data size, fix compile warning on mac

This commit is contained in:
rustdesk 2023-02-08 19:17:59 +08:00
parent 7c13be5876
commit 4134b77680
8 changed files with 65 additions and 57 deletions

View File

@ -25,7 +25,7 @@ use hbb_common::{allow_err, get_time, message_proto::*, sleep};
use hbb_common::{fs, log, Stream};
use crate::client::{
new_voice_call_request, Client, CodecFormat, LoginConfigHandler, MediaData, MediaSender,
new_voice_call_request, Client, CodecFormat, MediaData, MediaSender,
QualityStatus, MILLI1, SEC30, SERVER_CLIPBOARD_ENABLED, SERVER_FILE_TRANSFER_ENABLED,
SERVER_KEYBOARD_ENABLED,
};

View File

@ -30,7 +30,7 @@ use hbb_common::{
// #[cfg(any(target_os = "android", target_os = "ios", feature = "cli"))]
use hbb_common::{config::RENDEZVOUS_PORT, futures::future::join_all};
use crate::ui_interface::{set_option, get_option};
use crate::ui_interface::{get_option, set_option};
pub type NotifyMessageBox = fn(String, String, String, String) -> dyn Future<Output = ()>;
@ -762,8 +762,3 @@ pub fn make_fd_to_json(id: i32, path: String, entries: &Vec<FileEntry>) -> Strin
fd_json.insert("entries".into(), json!(entries_out));
serde_json::to_string(&fd_json).unwrap_or("".into())
}
#[cfg(test)]
mod test_common {
}

View File

@ -1,6 +1,4 @@
use std::future::Future;
use hbb_common::{log, ResultType};
use hbb_common::log;
/// shared by flutter and sciter main function
///

View File

@ -16,10 +16,10 @@ use hbb_common::{
config::{self, Config, Config2},
futures::StreamExt as _,
futures_util::sink::SinkExt,
log, password_security as password, ResultType, timeout,
tokio,
log, password_security as password, timeout, tokio,
tokio::io::{AsyncRead, AsyncWrite},
tokio_util::codec::Framed,
ResultType,
};
use crate::rendezvous_mediator::RendezvousMediator;
@ -190,7 +190,7 @@ pub enum Data {
Socks(Option<config::Socks5Server>),
FS(FS),
Test,
SyncConfig(Option<(Config, Config2)>),
SyncConfig(Option<Box<(Config, Config2)>>),
#[cfg(not(any(target_os = "android", target_os = "ios")))]
ClipboardFile(ClipboardFile),
ClipboardFileEnabled(bool),
@ -419,7 +419,8 @@ async fn handle(data: Data, stream: &mut Connection) {
let t = Config::get_nat_type();
allow_err!(stream.send(&Data::NatType(Some(t))).await);
}
Data::SyncConfig(Some((config, config2))) => {
Data::SyncConfig(Some(configs)) => {
let (config, config2) = *configs;
let _chk = CheckIfRestart::new();
Config::set(config);
Config2::set(config2);
@ -428,7 +429,9 @@ async fn handle(data: Data, stream: &mut Connection) {
Data::SyncConfig(None) => {
allow_err!(
stream
.send(&Data::SyncConfig(Some((Config::get(), Config2::get()))))
.send(&Data::SyncConfig(Some(
(Config::get(), Config2::get()).into()
)))
.await
);
}
@ -840,6 +843,19 @@ pub async fn test_rendezvous_server() -> ResultType<()> {
#[tokio::main(flavor = "current_thread")]
pub async fn send_url_scheme(url: String) -> ResultType<()> {
connect(1_000, "_url").await?.send(&Data::UrlLink(url)).await?;
connect(1_000, "_url")
.await?
.send(&Data::UrlLink(url))
.await?;
Ok(())
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn verify_ffi_enum_data_size() {
println!("{}", std::mem::size_of::<Data>());
assert!(std::mem::size_of::<Data>() < 96);
}
}

View File

@ -212,7 +212,7 @@ pub fn start_grab_loop() {
}
let mut _keyboard_mode = KeyboardMode::Map;
let scan_code = event.scan_code;
let _scan_code = event.scan_code;
let res = if KEYBOARD_HOOKED.load(Ordering::SeqCst) {
_keyboard_mode = client::process_event(&event, None);
if is_press {
@ -225,7 +225,7 @@ pub fn start_grab_loop() {
};
#[cfg(target_os = "windows")]
match scan_code {
match _scan_code {
0x1D | 0x021D => rdev::set_modifier(Key::ControlLeft, is_press),
0xE01D => rdev::set_modifier(Key::ControlRight, is_press),
0x2A => rdev::set_modifier(Key::ShiftLeft, is_press),
@ -241,7 +241,7 @@ pub fn start_grab_loop() {
#[cfg(target_os = "windows")]
unsafe {
// AltGr
if scan_code == 0x021D {
if _scan_code == 0x021D {
IS_0X021D_DOWN = is_press;
}
}

View File

@ -8,6 +8,9 @@ use std::{
use bytes::Bytes;
pub use connection::*;
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use hbb_common::config::Config2;
use hbb_common::tcp::new_listener;
use hbb_common::{
allow_err,
anyhow::{anyhow, Context},
@ -17,18 +20,15 @@ use hbb_common::{
message_proto::*,
protobuf::{Enum, Message as _},
rendezvous_proto::*,
ResultType,
socket_client,
sodiumoxide::crypto::{box_, secretbox, sign}, Stream, timeout, tokio,
sodiumoxide::crypto::{box_, secretbox, sign},
timeout, tokio, ResultType, Stream,
};
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use hbb_common::config::Config2;
use hbb_common::tcp::new_listener;
use service::{GenericService, Service, Subscriber};
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use service::ServiceTmpl;
use service::{GenericService, Service, Subscriber};
use crate::ipc::{connect, Data};
use crate::ipc::Data;
pub mod audio_service;
cfg_if::cfg_if! {
@ -420,7 +420,8 @@ pub async fn start_server(is_server: bool) {
if conn.send(&Data::SyncConfig(None)).await.is_ok() {
if let Ok(Some(data)) = conn.next_timeout(1000).await {
match data {
Data::SyncConfig(Some((config, config2))) => {
Data::SyncConfig(Some(configs)) => {
let (config, config2) = *configs;
if Config::set(config) {
log::info!("config synced");
}
@ -450,14 +451,14 @@ pub async fn start_ipc_url_server() {
while let Some(Ok(conn)) = incoming.next().await {
let mut conn = crate::ipc::Connection::new(conn);
match conn.next_timeout(1000).await {
Ok(Some(data)) => {
match data {
Data::UrlLink(url) => {
Ok(Some(data)) => match data {
#[cfg(feature = "flutter")]
Data::UrlLink(url) => {
if let Some(stream) = crate::flutter::GLOBAL_EVENT_STREAM
.read()
.unwrap()
.get(crate::flutter::APP_TYPE_MAIN)
{
if let Some(stream) = crate::flutter::GLOBAL_EVENT_STREAM.read().unwrap().get(
crate::flutter::APP_TYPE_MAIN
) {
let mut m = HashMap::new();
m.insert("name", "on_url_scheme_received");
m.insert("url", url.as_str());
@ -466,12 +467,10 @@ pub async fn start_ipc_url_server() {
log::warn!("No main window app found!");
}
}
}
_ => {
log::warn!("An unexpected data was sent to the ipc url server.")
}
}
}
},
Err(err) => {
log::error!("{}", err);
}
@ -509,7 +508,8 @@ async fn sync_and_watch_config_dir() {
if conn.send(&Data::SyncConfig(None)).await.is_ok() {
if let Ok(Some(data)) = conn.next_timeout(1000).await {
match data {
Data::SyncConfig(Some((config, config2))) => {
Data::SyncConfig(Some(configs)) => {
let (config, config2) = *configs;
let _chk = crate::ipc::CheckIfRestart::new();
if cfg0.0 != config {
cfg0.0 = config.clone();
@ -534,7 +534,7 @@ async fn sync_and_watch_config_dir() {
let cfg = (Config::get(), Config2::get());
if cfg != cfg0 {
log::info!("config updated, sync to root");
match conn.send(&Data::SyncConfig(Some(cfg.clone()))).await {
match conn.send(&Data::SyncConfig(Some(cfg.clone().into()))).await {
Err(e) => {
log::error!("sync config to root failed: {}", e);
break;

View File

@ -14,12 +14,9 @@ use objc::{
sel, sel_impl,
};
use objc::runtime::Class;
use objc_id::WeakId;
use sciter::{Host, make_args};
use hbb_common::{log, tokio};
use crate::ui_cm_interface::start_ipc;
use hbb_common::log;
static APP_HANDLER_IVAR: &str = "GoDeskAppHandler";
@ -141,7 +138,7 @@ extern "C" fn application_should_handle_open_untitled_file(
if !LAUNCHED {
return YES;
}
hbb_common::log::debug!("icon clicked on finder");
log::debug!("icon clicked on finder");
if std::env::args().nth(1) == Some("--server".to_owned()) {
crate::platform::macos::check_main_window();
}

View File

@ -845,6 +845,7 @@ pub fn elevate_portable(_id: i32) {
}
}
#[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))]
#[inline]
pub fn handle_incoming_voice_call(id: i32, accept: bool) {
if let Some(client) = CLIENTS.write().unwrap().get_mut(&id) {
@ -852,6 +853,7 @@ pub fn handle_incoming_voice_call(id: i32, accept: bool) {
};
}
#[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))]
#[inline]
pub fn close_voice_call(id: i32) {
if let Some(client) = CLIENTS.write().unwrap().get_mut(&id) {