remove android build warns

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2023-03-27 19:13:29 +08:00
parent 3c69773e64
commit 8cb361c51e
15 changed files with 101 additions and 43 deletions

View File

@ -297,6 +297,7 @@ pub struct TransferSerde {
pub read_jobs: Vec<String>,
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
fn patch(path: PathBuf) -> PathBuf {
if let Some(_tmp) = path.to_str() {
#[cfg(windows)]

View File

@ -1,7 +1,11 @@
use std::collections::HashMap;
use std::num::NonZeroI64;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{Arc, Mutex};
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use std::sync::Mutex;
use std::sync::{
atomic::{AtomicUsize, Ordering},
Arc,
};
#[cfg(windows)]
use clipboard::{cliprdr::CliprdrClientContext, ContextSend};
@ -13,6 +17,8 @@ use hbb_common::fs::{
use hbb_common::message_proto::permission_info::Permission;
use hbb_common::protobuf::Message as _;
use hbb_common::rendezvous_proto::ConnType;
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use hbb_common::sleep;
use hbb_common::tokio::sync::mpsc::error::TryRecvError;
#[cfg(windows)]
use hbb_common::tokio::sync::Mutex as TokioMutex;
@ -21,18 +27,17 @@ use hbb_common::tokio::{
sync::mpsc,
time::{self, Duration, Instant, Interval},
};
use hbb_common::{allow_err, get_time, message_proto::*, sleep};
use hbb_common::{fs, log, Stream};
use hbb_common::{allow_err, fs, get_time, log, message_proto::*, Stream};
use crate::client::{
new_voice_call_request, Client, CodecFormat, MediaData, MediaSender, QualityStatus, MILLI1,
SEC30,
};
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use crate::common::update_clipboard;
use crate::common::{self, update_clipboard};
use crate::common::{get_default_sound_input, set_sound_input};
use crate::ui_session_interface::{InvokeUiSession, Session};
use crate::{audio_service, common, ConnInner, CLIENT_SERVER};
use crate::{audio_service, ConnInner, CLIENT_SERVER};
use crate::{client::Data, client::Interface};
pub struct Remote<T: InvokeUiSession> {
@ -44,6 +49,7 @@ pub struct Remote<T: InvokeUiSession> {
// Stop sending local audio to remote client.
stop_voice_call_sender: Option<std::sync::mpsc::Sender<()>>,
voice_call_request_timestamp: Option<NonZeroI64>,
#[cfg(not(any(target_os = "android", target_os = "ios")))]
old_clipboard: Arc<Mutex<String>>,
read_jobs: Vec<fs::TransferJob>,
write_jobs: Vec<fs::TransferJob>,
@ -74,6 +80,7 @@ impl<T: InvokeUiSession> Remote<T> {
audio_sender,
receiver,
sender,
#[cfg(not(any(target_os = "android", target_os = "ios")))]
old_clipboard: Default::default(),
read_jobs: Vec::new(),
write_jobs: Vec::new(),
@ -840,7 +847,9 @@ impl<T: InvokeUiSession> Remote<T> {
self.handler.handle_peer_info(pi);
self.check_clipboard_file_context();
if !(self.handler.is_file_transfer() || self.handler.is_port_forward()) {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
let sender = self.sender.clone();
#[cfg(not(any(target_os = "android", target_os = "ios")))]
let permission_config = self.handler.get_permission_config();
#[cfg(feature = "flutter")]

View File

@ -8,6 +8,7 @@ use hbb_common::platform::register_breakdown_handler;
/// [Note]
/// If it returns [`None`], then the process will terminate, and flutter gui will not be started.
/// If it returns [`Some`], then the process will continue, and flutter gui will be started.
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn core_main() -> Option<Vec<String>> {
let mut args = Vec::new();
let mut flutter_args = Vec::new();

View File

@ -168,14 +168,12 @@ pub fn session_reconnect(id: String, force_relay: bool) {
}
pub fn session_toggle_option(id: String, value: String) {
let mut is_found = false;
if let Some(session) = SESSIONS.write().unwrap().get_mut(&id) {
is_found = true;
log::warn!("toggle option {}", &value);
session.toggle_option(value.clone());
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
if is_found && value == "disable-clipboard" {
if SESSIONS.read().unwrap().get(&id).is_some() && value == "disable-clipboard" {
crate::flutter::update_text_clipboard_required();
}
}
@ -338,10 +336,10 @@ pub fn session_handle_flutter_key_event(
}
}
pub fn session_enter_or_leave(id: String, enter: bool) {
pub fn session_enter_or_leave(_id: String, _enter: bool) {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
if let Some(session) = SESSIONS.read().unwrap().get(&id) {
if enter {
if let Some(session) = SESSIONS.read().unwrap().get(&_id) {
if _enter {
session.enter();
} else {
session.leave();
@ -1405,7 +1403,7 @@ pub mod server_side {
#[no_mangle]
pub unsafe extern "system" fn Java_com_carriez_flutter_1hbb_MainService_startService(
env: JNIEnv,
_env: JNIEnv,
_class: JClass,
) {
log::debug!("startService from jvm");

View File

@ -16,6 +16,7 @@ lazy_static::lazy_static! {
static ref SENDER : Mutex<broadcast::Sender<Vec<i32>>> = Mutex::new(start_hbbs_sync());
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn start() {
let _sender = SENDER.lock().unwrap();
}

View File

@ -179,6 +179,7 @@ pub mod client {
}
#[inline]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn lock_screen() {
send_key_event(&event_lock_screen());
}
@ -198,6 +199,7 @@ pub mod client {
}
#[inline]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn ctrl_alt_del() {
send_key_event(&event_ctrl_alt_del());
}
@ -364,6 +366,7 @@ pub fn get_keyboard_mode_enum() -> KeyboardMode {
}
#[inline]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
fn is_numpad_key(event: &Event) -> bool {
matches!(event.event_type, EventType::KeyPress(key) | EventType::KeyRelease(key) if match key {
Key::Kp0 | Key::Kp1 | Key::Kp2 | Key::Kp3 | Key::Kp4 | Key::Kp5 | Key::Kp6 | Key::Kp7 | Key::Kp8 |
@ -373,6 +376,7 @@ fn is_numpad_key(event: &Event) -> bool {
}
#[inline]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
fn is_letter_key(event: &Event) -> bool {
matches!(event.event_type, EventType::KeyPress(key) | EventType::KeyRelease(key) if match key {
Key::KeyA | Key::KeyB | Key::KeyC | Key::KeyD | Key::KeyE | Key::KeyF | Key::KeyG | Key::KeyH |
@ -456,7 +460,7 @@ fn update_modifiers_state(event: &Event) {
pub fn event_to_key_events(
event: &Event,
keyboard_mode: KeyboardMode,
lock_modes: Option<i32>,
_lock_modes: Option<i32>,
) -> Vec<KeyEvent> {
let mut key_event = KeyEvent::new();
update_modifiers_state(event);
@ -475,7 +479,12 @@ pub fn event_to_key_events(
peer.retain(|c| !c.is_whitespace());
key_event.mode = keyboard_mode.into();
let mut key_events = match keyboard_mode {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
let mut key_events;
#[cfg(any(target_os = "android", target_os = "ios"))]
let key_events;
key_events = match keyboard_mode {
KeyboardMode::Map => match map_keyboard_mode(peer.as_str(), event, key_event) {
Some(event) => [event].to_vec(),
None => Vec::new(),
@ -493,12 +502,12 @@ pub fn event_to_key_events(
}
};
#[cfg(not(any(target_os = "android", target_os = "ios")))]
if keyboard_mode != KeyboardMode::Translate {
let is_numpad_key = is_numpad_key(&event);
let is_letter_key = is_letter_key(&event);
for key_event in &mut key_events {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
if let Some(lock_modes) = lock_modes {
if let Some(lock_modes) = _lock_modes {
parse_add_lock_modes_modifiers(key_event, lock_modes, is_numpad_key, is_letter_key);
} else {
add_lock_modes_modifiers(key_event, is_numpad_key, is_letter_key);
@ -778,7 +787,7 @@ pub fn legacy_keyboard_mode(event: &Event, mut key_event: KeyEvent) -> Vec<KeyEv
events
}
pub fn map_keyboard_mode(peer: &str, event: &Event, mut key_event: KeyEvent) -> Option<KeyEvent> {
pub fn map_keyboard_mode(_peer: &str, event: &Event, mut key_event: KeyEvent) -> Option<KeyEvent> {
match event.event_type {
EventType::KeyPress(..) => {
key_event.down = true;
@ -790,7 +799,7 @@ pub fn map_keyboard_mode(peer: &str, event: &Event, mut key_event: KeyEvent) ->
};
#[cfg(target_os = "windows")]
let keycode = match peer {
let keycode = match _peer {
OS_LOWER_WINDOWS => {
// https://github.com/rustdesk/rustdesk/issues/1371
// Filter scancodes that are greater than 255 and the hight word is not 0xE0.
@ -809,13 +818,13 @@ pub fn map_keyboard_mode(peer: &str, event: &Event, mut key_event: KeyEvent) ->
_ => rdev::win_scancode_to_linux_code(event.position_code)?,
};
#[cfg(target_os = "macos")]
let keycode = match peer {
let keycode = match _peer {
OS_LOWER_WINDOWS => rdev::macos_code_to_win_scancode(event.platform_code as _)?,
OS_LOWER_MACOS => event.platform_code as _,
_ => rdev::macos_code_to_linux_code(event.platform_code as _)?,
};
#[cfg(target_os = "linux")]
let keycode = match peer {
let keycode = match _peer {
OS_LOWER_WINDOWS => rdev::linux_code_to_win_scancode(event.position_code as _)?,
OS_LOWER_MACOS => {
if hbb_common::config::LocalConfig::get_kb_layout_type() == "ISO" {
@ -833,6 +842,7 @@ pub fn map_keyboard_mode(peer: &str, event: &Event, mut key_event: KeyEvent) ->
Some(key_event)
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
fn try_fill_unicode(event: &Event, key_event: &KeyEvent, events: &mut Vec<KeyEvent>) {
match &event.unicode {
Some(unicode_info) => {
@ -925,6 +935,8 @@ pub fn translate_keyboard_mode(peer: &str, event: &Event, key_event: KeyEvent) -
return events;
}
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
if is_numpad_key(&event) {
if let Some(evt) = translate_key_code(peer, event, key_event) {
events.push(evt);

View File

@ -1,7 +1,9 @@
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use hbb_common::config::Config;
use hbb_common::{
allow_err,
anyhow::bail,
config::{self, Config, RENDEZVOUS_PORT},
config::{self, RENDEZVOUS_PORT},
log,
protobuf::Message as _,
rendezvous_proto::*,
@ -11,6 +13,7 @@ use hbb_common::{
},
ResultType,
};
use std::{
collections::{HashMap, HashSet},
net::{IpAddr, Ipv4Addr, SocketAddr, ToSocketAddrs, UdpSocket},
@ -19,6 +22,7 @@ use std::{
type Message = RendezvousMessage;
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub(super) fn start_listening() -> ResultType<()> {
let addr = SocketAddr::from(([0, 0, 0, 0], get_broadcast_port()));
let socket = std::net::UdpSocket::bind(addr)?;
@ -98,9 +102,9 @@ fn get_broadcast_port() -> u16 {
(RENDEZVOUS_PORT + 3) as _
}
fn get_mac(ip: &IpAddr) -> String {
fn get_mac(_ip: &IpAddr) -> String {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
if let Ok(mac) = get_mac_by_ip(ip) {
if let Ok(mac) = get_mac_by_ip(_ip) {
mac.to_string()
} else {
"".to_owned()
@ -119,6 +123,7 @@ fn get_all_ipv4s() -> ResultType<Vec<Ipv4Addr>> {
Ok(ipv4s)
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
fn get_mac_by_ip(ip: &IpAddr) -> ResultType<String> {
for interface in default_net::get_interfaces() {
match ip {

View File

@ -19,7 +19,7 @@ pub mod linux;
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use hbb_common::{message_proto::CursorData, ResultType};
#[cfg(not(target_os = "macos"))]
#[cfg(not(any(target_os = "macos", target_os = "android", target_os = "ios")))]
const SERVICE_INTERVAL: u64 = 300;
pub fn is_xfce() -> bool {

View File

@ -365,7 +365,7 @@ pub fn check_zombie() {
/// Otherwise, client will check if there's already a server and start one if not.
#[cfg(any(target_os = "android", target_os = "ios"))]
#[tokio::main]
pub async fn start_server(is_server: bool) {
pub async fn start_server(_is_server: bool) {
crate::RendezvousMediator::start_all().await;
}

View File

@ -64,6 +64,7 @@ mod pa_impl {
)))
.await
);
#[cfg(target_os = "linux")]
let zero_audio_frame: Vec<f32> = vec![0.; AUDIO_DATA_SIZE_U8 / 4];
while sp.ok() && !RESTARTING.load(Ordering::SeqCst) {
sp.snapshot(|sps| {

View File

@ -64,7 +64,9 @@ pub struct ConnInner {
}
enum MessageInput {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
Mouse((MouseEvent, i32)),
#[cfg(not(any(target_os = "android", target_os = "ios")))]
Key((KeyEvent, bool)),
BlockOn,
BlockOff,
@ -125,6 +127,7 @@ pub struct Connection {
#[cfg(windows)]
portable: PortableState,
from_switch: bool,
#[cfg(not(any(target_os = "android", target_os = "ios")))]
origin_resolution: HashMap<String, Resolution>,
voice_call_request_timestamp: Option<NonZeroI64>,
audio_input_device_before_voice_call: Option<String>,
@ -187,9 +190,10 @@ impl Connection {
let (tx_to_cm, rx_to_cm) = mpsc::unbounded_channel::<ipc::Data>();
let (tx, mut rx) = mpsc::unbounded_channel::<(Instant, Arc<Message>)>();
let (tx_video, mut rx_video) = mpsc::unbounded_channel::<(Instant, Arc<Message>)>();
let (tx_input, rx_input) = std_mpsc::channel();
let (tx_input, _rx_input) = std_mpsc::channel();
let mut hbbs_rx = crate::hbbs_http::sync::signal_receiver();
#[cfg(not(any(target_os = "android", target_os = "ios")))]
let tx_cloned = tx.clone();
let mut conn = Self {
inner: ConnInner {
@ -233,6 +237,7 @@ impl Connection {
#[cfg(windows)]
portable: Default::default(),
from_switch: false,
#[cfg(not(any(target_os = "android", target_os = "ios")))]
origin_resolution: Default::default(),
audio_sender: None,
voice_call_request_timestamp: None,
@ -282,7 +287,7 @@ impl Connection {
);
#[cfg(not(any(target_os = "android", target_os = "ios")))]
std::thread::spawn(move || Self::handle_input(rx_input, tx_cloned));
std::thread::spawn(move || Self::handle_input(_rx_input, tx_cloned));
let mut second_timer = time::interval(Duration::from_secs(1));
loop {
@ -1042,11 +1047,13 @@ impl Connection {
}
#[inline]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
fn input_mouse(&self, msg: MouseEvent, conn_id: i32) {
self.tx_input.send(MessageInput::Mouse((msg, conn_id))).ok();
}
#[inline]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
fn input_key(&self, msg: KeyEvent, press: bool) {
self.tx_input.send(MessageInput::Key((msg, press))).ok();
}
@ -1342,8 +1349,10 @@ impl Connection {
self.input_mouse(me, self.inner.id());
}
}
#[cfg(any(target_os = "android", target_os = "ios"))]
Some(message::Union::KeyEvent(..)) => {}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
Some(message::Union::KeyEvent(me)) => {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
if self.peer_keyboard_enabled() {
if is_enter(&me) {
CLICK_TIME.store(get_time(), Ordering::SeqCst);
@ -1371,11 +1380,11 @@ impl Connection {
}
}
}
Some(message::Union::Clipboard(cb)) =>
Some(message::Union::Clipboard(_cb)) =>
{
#[cfg(not(any(target_os = "android", target_os = "ios")))]
if self.clipboard {
update_clipboard(cb, None);
update_clipboard(_cb, None);
}
}
Some(message::Union::Cliprdr(_clip)) => {

View File

@ -831,14 +831,13 @@ pub fn handle_one_frame_encoded(
}
Ok(())
})?;
let mut send_conn_ids: HashSet<i32> = Default::default();
let vp9_frame = EncodedVideoFrame {
data: frame.to_vec().into(),
key: true,
pts: ms,
..Default::default()
};
send_conn_ids = sp.send_video_frame(create_msg(vec![vp9_frame]));
let send_conn_ids = sp.send_video_frame(create_msg(vec![vp9_frame]));
Ok(send_conn_ids)
}

View File

@ -15,7 +15,11 @@ use std::{
use clipboard::{cliprdr::CliprdrClientContext, empty_clipboard, set_conn_enabled, ContextSend};
use serde_derive::Serialize;
use crate::ipc::{self, Connection, Data};
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use crate::ipc::Connection;
use crate::ipc::{self, Data};
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use hbb_common::tokio::sync::mpsc::unbounded_channel;
#[cfg(windows)]
use hbb_common::tokio::sync::Mutex as TokioMutex;
use hbb_common::{
@ -28,7 +32,7 @@ use hbb_common::{
protobuf::Message as _,
tokio::{
self,
sync::mpsc::{self, unbounded_channel, UnboundedSender},
sync::mpsc::{self, UnboundedSender},
task::spawn_blocking,
},
};
@ -55,6 +59,7 @@ pub struct Client {
tx: UnboundedSender<Data>,
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
struct IpcTaskRunner<T: InvokeUiCM> {
stream: Connection,
cm: ConnectionManager<T>,
@ -143,7 +148,7 @@ impl<T: InvokeUiCM> ConnectionManager<T> {
from_switch,
tx,
in_voice_call: false,
incoming_voice_call: false
incoming_voice_call: false,
};
CLIENTS
.write()
@ -183,10 +188,12 @@ impl<T: InvokeUiCM> ConnectionManager<T> {
self.ui_handler.remove_connection(id, close);
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
fn show_elevation(&self, show: bool) {
self.ui_handler.show_elevation(show);
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
fn voice_call_started(&self, id: i32) {
if let Some(client) = CLIENTS.write().unwrap().get_mut(&id) {
client.incoming_voice_call = false;
@ -195,6 +202,7 @@ impl<T: InvokeUiCM> ConnectionManager<T> {
}
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
fn voice_call_incoming(&self, id: i32) {
if let Some(client) = CLIENTS.write().unwrap().get_mut(&id) {
client.incoming_voice_call = true;
@ -203,6 +211,7 @@ impl<T: InvokeUiCM> ConnectionManager<T> {
}
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
fn voice_call_closed(&self, id: i32, _reason: &str) {
if let Some(client) = CLIENTS.write().unwrap().get_mut(&id) {
client.incoming_voice_call = false;
@ -282,6 +291,7 @@ pub fn switch_back(id: i32) {
};
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
impl<T: InvokeUiCM> IpcTaskRunner<T> {
#[cfg(windows)]
async fn enable_cliprdr_file_context(&mut self, conn_id: i32, enabled: bool) {

View File

@ -9,8 +9,12 @@ use hbb_common::password_security;
use hbb_common::{
allow_err,
config::{self, Config, LocalConfig, PeerConfig},
directories_next, log, sleep,
tokio::{self, sync::mpsc, time},
directories_next, log, tokio,
};
#[cfg(not(any(target_os = "android", target_os = "ios")))]
use hbb_common::{
sleep,
tokio::{sync::mpsc, time},
};
use hbb_common::{
@ -339,8 +343,8 @@ pub fn get_socks() -> Vec<String> {
}
#[inline]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn set_socks(proxy: String, username: String, password: String) {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
ipc::set_socks(config::Socks5Server {
proxy,
username,
@ -349,6 +353,9 @@ pub fn set_socks(proxy: String, username: String, password: String) {
.ok();
}
#[cfg(any(target_os = "android", target_os = "ios"))]
pub fn set_socks(_: String, _: String, _: String) {}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
#[inline]
pub fn is_installed() -> bool {
@ -791,14 +798,15 @@ pub fn check_zombie(children: Children) {
}
}
// Make sure `SENDER` is inited here.
#[inline]
#[cfg(not(any(target_os = "android", target_os = "ios")))]
pub fn start_option_status_sync() {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
{
let _sender = SENDER.lock().unwrap();
}
let _sender = SENDER.lock().unwrap();
}
// not call directly
#[cfg(not(any(target_os = "android", target_os = "ios")))]
fn check_connect_status(reconnect: bool) -> mpsc::UnboundedSender<ipc::Data> {
let (tx, rx) = mpsc::unbounded_channel::<ipc::Data>();
std::thread::spawn(move || check_connect_status_(reconnect, rx));
@ -834,6 +842,7 @@ pub fn get_user_default_option(key: String) -> String {
// notice: avoiding create ipc connection repeatedly,
// because windows named pipe has serious memory leak issue.
#[cfg(not(any(target_os = "android", target_os = "ios")))]
#[tokio::main(flavor = "current_thread")]
async fn check_connect_status_(reconnect: bool, rx: mpsc::UnboundedReceiver<ipc::Data>) {
let mut key_confirmed = false;

View File

@ -1053,6 +1053,9 @@ impl<T: InvokeUiSession> Session<T> {
#[tokio::main(flavor = "current_thread")]
pub async fn io_loop<T: InvokeUiSession>(handler: Session<T>) {
#[cfg(any(target_os = "android", target_os = "ios"))]
let (sender, receiver) = mpsc::unbounded_channel::<Data>();
#[cfg(not(any(target_os = "android", target_os = "ios")))]
let (sender, mut receiver) = mpsc::unbounded_channel::<Data>();
*handler.sender.write().unwrap() = Some(sender.clone());
let token = LocalConfig::get_option("access_token");