build linux

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou 2022-11-10 07:26:09 -08:00
parent 50d885d3e7
commit b000fd1ea8
8 changed files with 44 additions and 45 deletions

View File

@ -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::*,

View File

@ -149,12 +149,12 @@ pub fn core_main() -> Option<Vec<String>> {
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<Vec<Strin
}
}
}
#[cfg(not(target_os = "linux"))]
return None;
}

View File

@ -54,6 +54,7 @@ pub extern "C" fn rustdesk_core_main(args_len: *mut c_int) -> *mut *mut c_char {
}
// https://gist.github.com/iskakaushik/1c5b8aa75c77479c33c4320913eebef6
#[cfg(windows)]
fn rust_args_to_c_args(args: Vec<String>, outlen: *mut c_int) -> *mut *mut c_char {
let mut v = vec![];

View File

@ -440,7 +440,7 @@ pub fn session_resume_job(id: String, act_id: i32, is_remote: bool) {
pub fn main_get_sound_inputs() -> Vec<String> {
#[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("")]
}

View File

@ -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.");

View File

@ -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.";

View File

@ -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<Mutex<HashMap<String, String>>>) {
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<Mutex<HashMap<String, String>>>) {
}
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<Mutex<HashMap<String, String>>>) {
}
#[cfg(target_os = "linux")]
fn update_tray_service_item(options: Arc<Mutex<HashMap<String, String>>>, item: &gtk::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: &gtk::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<AppIndicator> {
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<Mutex<HashMap<String, String>>>) -> 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
}
}

View File

@ -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);