diff --git a/src/client/io_loop.rs b/src/client/io_loop.rs index 52042da06..04d1d4d29 100644 --- a/src/client/io_loop.rs +++ b/src/client/io_loop.rs @@ -23,9 +23,10 @@ use hbb_common::rendezvous_proto::ConnType; use hbb_common::tokio::{ self, sync::mpsc, - sync::Mutex as TokioMutex, time::{self, Duration, Instant, Interval}, }; +#[cfg(windows)] +use hbb_common::tokio::sync::Mutex as TokioMutex; use hbb_common::{ allow_err, message_proto::*, diff --git a/src/core_main.rs b/src/core_main.rs index 2298aaad6..d22d4e71b 100644 --- a/src/core_main.rs +++ b/src/core_main.rs @@ -149,12 +149,12 @@ pub fn core_main() -> Option> { std::thread::spawn(move || crate::start_server(true)); // to-do: for flutter, starting tray not ready yet, or we can reuse sciter's tray implementation. } - #[cfg(all(target_os = "linux"))] + #[cfg(target_os = "linux")] { let handler = std::thread::spawn(move || crate::start_server(true)); - crate::tray::start_tray(crate::ui_interface::OPTIONS.clone()); + crate::tray::start_tray(); // revent server exit when encountering errors from tray - handler.join(); + hbb_common::allow_err!(handler.join()); } } else if args[0] == "--import-config" { if args.len() == 2 { @@ -249,5 +249,6 @@ fn core_main_invoke_new_connection(mut args: std::env::Args) -> Option *mut *mut c_char { } // https://gist.github.com/iskakaushik/1c5b8aa75c77479c33c4320913eebef6 +#[cfg(windows)] fn rust_args_to_c_args(args: Vec, outlen: *mut c_int) -> *mut *mut c_char { let mut v = vec![]; diff --git a/src/flutter_ffi.rs b/src/flutter_ffi.rs index aba8f7e1b..21603227f 100644 --- a/src/flutter_ffi.rs +++ b/src/flutter_ffi.rs @@ -440,7 +440,7 @@ pub fn session_resume_job(id: String, act_id: i32, is_remote: bool) { pub fn main_get_sound_inputs() -> Vec { #[cfg(not(any(target_os = "android", target_os = "ios")))] return get_sound_inputs(); - #[cfg(any(target_os = "android", target_os = "linux"))] + #[cfg(any(target_os = "android", target_os = "ios"))] vec![String::from("")] } diff --git a/src/server/dbus.rs b/src/server/dbus.rs index a7b21f0dc..5a38fe7cb 100644 --- a/src/server/dbus.rs +++ b/src/server/dbus.rs @@ -6,7 +6,9 @@ use dbus::blocking::Connection; use dbus_crossroads::{Crossroads, IfaceBuilder}; use hbb_common::{log}; -use std::{error::Error, fmt, time::Duration, collections::HashMap}; +use std::{error::Error, fmt, time::Duration}; +#[cfg(feature = "flutter")] +use std::collections::HashMap; const DBUS_NAME: &str = "org.rustdesk.rustdesk"; const DBUS_PREFIX: &str = "/dbus"; @@ -65,7 +67,7 @@ fn handle_client_message(builder: &mut IfaceBuilder<()>) { DBUS_METHOD_NEW_CONNECTION, (DBUS_METHOD_NEW_CONNECTION_ID,), (DBUS_METHOD_RETURN,), - move |_, _, (peer_id,): (String,)| { + move |_, _, (_peer_id,): (String,)| { #[cfg(feature = "flutter")] { use crate::flutter::{self, APP_TYPE_MAIN}; @@ -77,7 +79,7 @@ fn handle_client_message(builder: &mut IfaceBuilder<()>) { { let data = HashMap::from([ ("name", "new_connection"), - ("peer_id", peer_id.as_str()) + ("peer_id", _peer_id.as_str()) ]); if !stream.add(serde_json::ser::to_string(&data).unwrap_or("".to_string())) { log::error!("failed to add dbus message to flutter global dbus stream."); diff --git a/src/server/video_service.rs b/src/server/video_service.rs index 5927bddec..9696ef08d 100644 --- a/src/server/video_service.rs +++ b/src/server/video_service.rs @@ -33,10 +33,11 @@ use std::{ collections::HashSet, io::ErrorKind::WouldBlock, ops::{Deref, DerefMut}, - sync::Once, time::{self, Duration, Instant}, }; #[cfg(windows)] +use std::sync::Once; +#[cfg(windows)] use virtual_display; pub const SCRAP_UBUNTU_HIGHER_REQUIRED: &str = "Wayland requires Ubuntu 21.04 or higher version."; diff --git a/src/tray.rs b/src/tray.rs index 3fe43197a..30bdc5a59 100644 --- a/src/tray.rs +++ b/src/tray.rs @@ -4,9 +4,8 @@ use hbb_common::log::{debug, error, info}; #[cfg(target_os = "linux")] use libappindicator::AppIndicator; #[cfg(target_os = "linux")] -use std::collections::HashMap; -#[cfg(target_os = "linux")] use std::env::temp_dir; +#[cfg(target_os = "windows")] use std::sync::{Arc, Mutex}; #[cfg(target_os = "windows")] use trayicon::{MenuBuilder, TrayIconBuilder}; @@ -16,6 +15,7 @@ use winit::{ event_loop::{ControlFlow, EventLoop}, }; +#[cfg(target_os = "windows")] #[derive(Clone, Eq, PartialEq, Debug)] enum Events { DoubleClickTrayIcon, @@ -44,17 +44,13 @@ pub fn start_tray() { } else { *control_flow = ControlFlow::Wait; } - let stopped = if let Some(v) = get_option_opt("stop-service") { - !v.is_empty() - } else { - false - }; - let stopped = if stopped { 2 } else { 1 }; + let stopped = is_service_stoped(); + let state = if stopped { 2 } else { 1 }; let old = *old_state.lock().unwrap(); - if stopped != old { + if state != old { hbb_common::log::info!("State changed"); let mut m = MenuBuilder::new(); - if stopped == 2 { + if state == 2 { m = m.item( &crate::client::translate("Start Service".to_owned()), Events::StartService, @@ -66,7 +62,7 @@ pub fn start_tray() { ); } tray_icon.set_menu(&m).ok(); - *old_state.lock().unwrap() = stopped; + *old_state.lock().unwrap() = state; } match event { @@ -91,10 +87,9 @@ pub fn start_tray() { /// [Block] /// This function will block current execution, show the tray icon and handle events. #[cfg(target_os = "linux")] -pub fn start_tray(options: Arc>>) { - use std::time::Duration; - +pub fn start_tray() { use gtk::traits::{GtkMenuItemExt, MenuShellExt, WidgetExt}; + info!("configuring tray"); // init gtk context if let Err(err) = gtk::init() { @@ -103,17 +98,17 @@ pub fn start_tray(options: Arc>>) { } if let Some(mut appindicator) = get_default_app_indicator() { let mut menu = gtk::Menu::new(); - let running = get_service_status(options.clone()); + let stoped = is_service_stoped(); // start/stop service - let label = if !running { + let label = if stoped { crate::client::translate("Start Service".to_owned()) } else { crate::client::translate("Stop service".to_owned()) }; let menu_item_service = gtk::MenuItem::with_label(label.as_str()); menu_item_service.connect_activate(move |item| { - let lock = crate::ui_interface::SENDER.lock().unwrap(); - update_tray_service_item(options.clone(), item); + let _lock = crate::ui_interface::SENDER.lock().unwrap(); + update_tray_service_item(item); }); menu.append(&menu_item_service); // show tray item @@ -128,19 +123,17 @@ pub fn start_tray(options: Arc>>) { } #[cfg(target_os = "linux")] -fn update_tray_service_item(options: Arc>>, item: >k::MenuItem) { - use gtk::{ - traits::{GtkMenuItemExt, ListBoxRowExt}, - MenuItem, - }; - if get_service_status(options.clone()) { - debug!("Now try to stop service"); - item.set_label(&crate::client::translate("Start Service".to_owned())); - crate::ipc::set_option("stop-service", "Y"); - } else { +fn update_tray_service_item(item: >k::MenuItem) { + use gtk::traits::GtkMenuItemExt; + + if is_service_stoped() { debug!("Now try to start service"); item.set_label(&crate::client::translate("Stop service".to_owned())); crate::ipc::set_option("stop-service", ""); + } else { + debug!("Now try to stop service"); + item.set_label(&crate::client::translate("Start Service".to_owned())); + crate::ipc::set_option("stop-service", "Y"); } } @@ -170,15 +163,13 @@ fn get_default_app_indicator() -> Option { Some(appindicator) } -/// Get service status -/// Return [`true`] if service is running, [`false`] otherwise. -#[cfg(target_os = "linux")] +/// Check if service is stoped. +/// Return [`true`] if service is stoped, [`false`] otherwise. #[inline] -fn get_service_status(options: Arc>>) -> bool { - if let Some(v) = options.lock().unwrap().get("stop-service") { - debug!("service stopped: {}", v); - v.is_empty() +fn is_service_stoped() -> bool { + if let Some(v) = get_option_opt("stop-service") { + v == "Y" } else { - true + false } } diff --git a/src/ui_interface.rs b/src/ui_interface.rs index d7d1b9979..7d520662d 100644 --- a/src/ui_interface.rs +++ b/src/ui_interface.rs @@ -190,11 +190,13 @@ pub fn set_local_option(key: String, value: String) { LocalConfig::set_option(key, value); } +#[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))] #[inline] pub fn get_local_flutter_config(key: String) -> String { LocalConfig::get_flutter_config(&key) } +#[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))] #[inline] pub fn set_local_flutter_config(key: String, value: String) { LocalConfig::set_flutter_config(key, value);