improve ffi enum data size, fix compile warning on mac
This commit is contained in:
parent
7c13be5876
commit
4134b77680
@ -25,7 +25,7 @@ use hbb_common::{allow_err, get_time, message_proto::*, sleep};
|
|||||||
use hbb_common::{fs, log, Stream};
|
use hbb_common::{fs, log, Stream};
|
||||||
|
|
||||||
use crate::client::{
|
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,
|
QualityStatus, MILLI1, SEC30, SERVER_CLIPBOARD_ENABLED, SERVER_FILE_TRANSFER_ENABLED,
|
||||||
SERVER_KEYBOARD_ENABLED,
|
SERVER_KEYBOARD_ENABLED,
|
||||||
};
|
};
|
||||||
|
@ -30,7 +30,7 @@ use hbb_common::{
|
|||||||
// #[cfg(any(target_os = "android", target_os = "ios", feature = "cli"))]
|
// #[cfg(any(target_os = "android", target_os = "ios", feature = "cli"))]
|
||||||
use hbb_common::{config::RENDEZVOUS_PORT, futures::future::join_all};
|
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 = ()>;
|
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));
|
fd_json.insert("entries".into(), json!(entries_out));
|
||||||
serde_json::to_string(&fd_json).unwrap_or("".into())
|
serde_json::to_string(&fd_json).unwrap_or("".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod test_common {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
use std::future::Future;
|
use hbb_common::log;
|
||||||
|
|
||||||
use hbb_common::{log, ResultType};
|
|
||||||
|
|
||||||
/// shared by flutter and sciter main function
|
/// shared by flutter and sciter main function
|
||||||
///
|
///
|
||||||
|
28
src/ipc.rs
28
src/ipc.rs
@ -16,10 +16,10 @@ use hbb_common::{
|
|||||||
config::{self, Config, Config2},
|
config::{self, Config, Config2},
|
||||||
futures::StreamExt as _,
|
futures::StreamExt as _,
|
||||||
futures_util::sink::SinkExt,
|
futures_util::sink::SinkExt,
|
||||||
log, password_security as password, ResultType, timeout,
|
log, password_security as password, timeout, tokio,
|
||||||
tokio,
|
|
||||||
tokio::io::{AsyncRead, AsyncWrite},
|
tokio::io::{AsyncRead, AsyncWrite},
|
||||||
tokio_util::codec::Framed,
|
tokio_util::codec::Framed,
|
||||||
|
ResultType,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::rendezvous_mediator::RendezvousMediator;
|
use crate::rendezvous_mediator::RendezvousMediator;
|
||||||
@ -190,7 +190,7 @@ pub enum Data {
|
|||||||
Socks(Option<config::Socks5Server>),
|
Socks(Option<config::Socks5Server>),
|
||||||
FS(FS),
|
FS(FS),
|
||||||
Test,
|
Test,
|
||||||
SyncConfig(Option<(Config, Config2)>),
|
SyncConfig(Option<Box<(Config, Config2)>>),
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
ClipboardFile(ClipboardFile),
|
ClipboardFile(ClipboardFile),
|
||||||
ClipboardFileEnabled(bool),
|
ClipboardFileEnabled(bool),
|
||||||
@ -419,7 +419,8 @@ async fn handle(data: Data, stream: &mut Connection) {
|
|||||||
let t = Config::get_nat_type();
|
let t = Config::get_nat_type();
|
||||||
allow_err!(stream.send(&Data::NatType(Some(t))).await);
|
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();
|
let _chk = CheckIfRestart::new();
|
||||||
Config::set(config);
|
Config::set(config);
|
||||||
Config2::set(config2);
|
Config2::set(config2);
|
||||||
@ -428,7 +429,9 @@ async fn handle(data: Data, stream: &mut Connection) {
|
|||||||
Data::SyncConfig(None) => {
|
Data::SyncConfig(None) => {
|
||||||
allow_err!(
|
allow_err!(
|
||||||
stream
|
stream
|
||||||
.send(&Data::SyncConfig(Some((Config::get(), Config2::get()))))
|
.send(&Data::SyncConfig(Some(
|
||||||
|
(Config::get(), Config2::get()).into()
|
||||||
|
)))
|
||||||
.await
|
.await
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -840,6 +843,19 @@ pub async fn test_rendezvous_server() -> ResultType<()> {
|
|||||||
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
pub async fn send_url_scheme(url: String) -> ResultType<()> {
|
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(())
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -212,7 +212,7 @@ pub fn start_grab_loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut _keyboard_mode = KeyboardMode::Map;
|
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) {
|
let res = if KEYBOARD_HOOKED.load(Ordering::SeqCst) {
|
||||||
_keyboard_mode = client::process_event(&event, None);
|
_keyboard_mode = client::process_event(&event, None);
|
||||||
if is_press {
|
if is_press {
|
||||||
@ -225,7 +225,7 @@ pub fn start_grab_loop() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
match scan_code {
|
match _scan_code {
|
||||||
0x1D | 0x021D => rdev::set_modifier(Key::ControlLeft, is_press),
|
0x1D | 0x021D => rdev::set_modifier(Key::ControlLeft, is_press),
|
||||||
0xE01D => rdev::set_modifier(Key::ControlRight, is_press),
|
0xE01D => rdev::set_modifier(Key::ControlRight, is_press),
|
||||||
0x2A => rdev::set_modifier(Key::ShiftLeft, is_press),
|
0x2A => rdev::set_modifier(Key::ShiftLeft, is_press),
|
||||||
@ -241,7 +241,7 @@ pub fn start_grab_loop() {
|
|||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
unsafe {
|
unsafe {
|
||||||
// AltGr
|
// AltGr
|
||||||
if scan_code == 0x021D {
|
if _scan_code == 0x021D {
|
||||||
IS_0X021D_DOWN = is_press;
|
IS_0X021D_DOWN = is_press;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,9 @@ use std::{
|
|||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
|
||||||
pub use connection::*;
|
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::{
|
use hbb_common::{
|
||||||
allow_err,
|
allow_err,
|
||||||
anyhow::{anyhow, Context},
|
anyhow::{anyhow, Context},
|
||||||
@ -17,18 +20,15 @@ use hbb_common::{
|
|||||||
message_proto::*,
|
message_proto::*,
|
||||||
protobuf::{Enum, Message as _},
|
protobuf::{Enum, Message as _},
|
||||||
rendezvous_proto::*,
|
rendezvous_proto::*,
|
||||||
ResultType,
|
|
||||||
socket_client,
|
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")))]
|
#[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::ServiceTmpl;
|
||||||
|
use service::{GenericService, Service, Subscriber};
|
||||||
|
|
||||||
use crate::ipc::{connect, Data};
|
use crate::ipc::Data;
|
||||||
|
|
||||||
pub mod audio_service;
|
pub mod audio_service;
|
||||||
cfg_if::cfg_if! {
|
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 conn.send(&Data::SyncConfig(None)).await.is_ok() {
|
||||||
if let Ok(Some(data)) = conn.next_timeout(1000).await {
|
if let Ok(Some(data)) = conn.next_timeout(1000).await {
|
||||||
match data {
|
match data {
|
||||||
Data::SyncConfig(Some((config, config2))) => {
|
Data::SyncConfig(Some(configs)) => {
|
||||||
|
let (config, config2) = *configs;
|
||||||
if Config::set(config) {
|
if Config::set(config) {
|
||||||
log::info!("config synced");
|
log::info!("config synced");
|
||||||
}
|
}
|
||||||
@ -450,14 +451,14 @@ pub async fn start_ipc_url_server() {
|
|||||||
while let Some(Ok(conn)) = incoming.next().await {
|
while let Some(Ok(conn)) = incoming.next().await {
|
||||||
let mut conn = crate::ipc::Connection::new(conn);
|
let mut conn = crate::ipc::Connection::new(conn);
|
||||||
match conn.next_timeout(1000).await {
|
match conn.next_timeout(1000).await {
|
||||||
Ok(Some(data)) => {
|
Ok(Some(data)) => match data {
|
||||||
match data {
|
|
||||||
Data::UrlLink(url) => {
|
|
||||||
#[cfg(feature = "flutter")]
|
#[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();
|
let mut m = HashMap::new();
|
||||||
m.insert("name", "on_url_scheme_received");
|
m.insert("name", "on_url_scheme_received");
|
||||||
m.insert("url", url.as_str());
|
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!("No main window app found!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
_ => {
|
_ => {
|
||||||
log::warn!("An unexpected data was sent to the ipc url server.")
|
log::warn!("An unexpected data was sent to the ipc url server.")
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
log::error!("{}", 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 conn.send(&Data::SyncConfig(None)).await.is_ok() {
|
||||||
if let Ok(Some(data)) = conn.next_timeout(1000).await {
|
if let Ok(Some(data)) = conn.next_timeout(1000).await {
|
||||||
match data {
|
match data {
|
||||||
Data::SyncConfig(Some((config, config2))) => {
|
Data::SyncConfig(Some(configs)) => {
|
||||||
|
let (config, config2) = *configs;
|
||||||
let _chk = crate::ipc::CheckIfRestart::new();
|
let _chk = crate::ipc::CheckIfRestart::new();
|
||||||
if cfg0.0 != config {
|
if cfg0.0 != config {
|
||||||
cfg0.0 = config.clone();
|
cfg0.0 = config.clone();
|
||||||
@ -534,7 +534,7 @@ async fn sync_and_watch_config_dir() {
|
|||||||
let cfg = (Config::get(), Config2::get());
|
let cfg = (Config::get(), Config2::get());
|
||||||
if cfg != cfg0 {
|
if cfg != cfg0 {
|
||||||
log::info!("config updated, sync to root");
|
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) => {
|
Err(e) => {
|
||||||
log::error!("sync config to root failed: {}", e);
|
log::error!("sync config to root failed: {}", e);
|
||||||
break;
|
break;
|
||||||
|
@ -14,12 +14,9 @@ use objc::{
|
|||||||
sel, sel_impl,
|
sel, sel_impl,
|
||||||
};
|
};
|
||||||
use objc::runtime::Class;
|
use objc::runtime::Class;
|
||||||
use objc_id::WeakId;
|
|
||||||
use sciter::{Host, make_args};
|
use sciter::{Host, make_args};
|
||||||
|
|
||||||
use hbb_common::{log, tokio};
|
use hbb_common::log;
|
||||||
|
|
||||||
use crate::ui_cm_interface::start_ipc;
|
|
||||||
|
|
||||||
static APP_HANDLER_IVAR: &str = "GoDeskAppHandler";
|
static APP_HANDLER_IVAR: &str = "GoDeskAppHandler";
|
||||||
|
|
||||||
@ -141,7 +138,7 @@ extern "C" fn application_should_handle_open_untitled_file(
|
|||||||
if !LAUNCHED {
|
if !LAUNCHED {
|
||||||
return YES;
|
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()) {
|
if std::env::args().nth(1) == Some("--server".to_owned()) {
|
||||||
crate::platform::macos::check_main_window();
|
crate::platform::macos::check_main_window();
|
||||||
}
|
}
|
||||||
|
@ -845,6 +845,7 @@ pub fn elevate_portable(_id: i32) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn handle_incoming_voice_call(id: i32, accept: bool) {
|
pub fn handle_incoming_voice_call(id: i32, accept: bool) {
|
||||||
if let Some(client) = CLIENTS.write().unwrap().get_mut(&id) {
|
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]
|
#[inline]
|
||||||
pub fn close_voice_call(id: i32) {
|
pub fn close_voice_call(id: i32) {
|
||||||
if let Some(client) = CLIENTS.write().unwrap().get_mut(&id) {
|
if let Some(client) = CLIENTS.write().unwrap().get_mut(&id) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user