build linux
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
50d885d3e7
commit
b000fd1ea8
@ -23,9 +23,10 @@ use hbb_common::rendezvous_proto::ConnType;
|
|||||||
use hbb_common::tokio::{
|
use hbb_common::tokio::{
|
||||||
self,
|
self,
|
||||||
sync::mpsc,
|
sync::mpsc,
|
||||||
sync::Mutex as TokioMutex,
|
|
||||||
time::{self, Duration, Instant, Interval},
|
time::{self, Duration, Instant, Interval},
|
||||||
};
|
};
|
||||||
|
#[cfg(windows)]
|
||||||
|
use hbb_common::tokio::sync::Mutex as TokioMutex;
|
||||||
use hbb_common::{
|
use hbb_common::{
|
||||||
allow_err,
|
allow_err,
|
||||||
message_proto::*,
|
message_proto::*,
|
||||||
|
@ -149,12 +149,12 @@ pub fn core_main() -> Option<Vec<String>> {
|
|||||||
std::thread::spawn(move || crate::start_server(true));
|
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.
|
// 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));
|
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
|
// revent server exit when encountering errors from tray
|
||||||
handler.join();
|
hbb_common::allow_err!(handler.join());
|
||||||
}
|
}
|
||||||
} else if args[0] == "--import-config" {
|
} else if args[0] == "--import-config" {
|
||||||
if args.len() == 2 {
|
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;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -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
|
// 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 {
|
fn rust_args_to_c_args(args: Vec<String>, outlen: *mut c_int) -> *mut *mut c_char {
|
||||||
let mut v = vec![];
|
let mut v = vec![];
|
||||||
|
|
||||||
|
@ -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> {
|
pub fn main_get_sound_inputs() -> Vec<String> {
|
||||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||||
return get_sound_inputs();
|
return get_sound_inputs();
|
||||||
#[cfg(any(target_os = "android", target_os = "linux"))]
|
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||||
vec![String::from("")]
|
vec![String::from("")]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,9 @@
|
|||||||
use dbus::blocking::Connection;
|
use dbus::blocking::Connection;
|
||||||
use dbus_crossroads::{Crossroads, IfaceBuilder};
|
use dbus_crossroads::{Crossroads, IfaceBuilder};
|
||||||
use hbb_common::{log};
|
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_NAME: &str = "org.rustdesk.rustdesk";
|
||||||
const DBUS_PREFIX: &str = "/dbus";
|
const DBUS_PREFIX: &str = "/dbus";
|
||||||
@ -65,7 +67,7 @@ fn handle_client_message(builder: &mut IfaceBuilder<()>) {
|
|||||||
DBUS_METHOD_NEW_CONNECTION,
|
DBUS_METHOD_NEW_CONNECTION,
|
||||||
(DBUS_METHOD_NEW_CONNECTION_ID,),
|
(DBUS_METHOD_NEW_CONNECTION_ID,),
|
||||||
(DBUS_METHOD_RETURN,),
|
(DBUS_METHOD_RETURN,),
|
||||||
move |_, _, (peer_id,): (String,)| {
|
move |_, _, (_peer_id,): (String,)| {
|
||||||
#[cfg(feature = "flutter")]
|
#[cfg(feature = "flutter")]
|
||||||
{
|
{
|
||||||
use crate::flutter::{self, APP_TYPE_MAIN};
|
use crate::flutter::{self, APP_TYPE_MAIN};
|
||||||
@ -77,7 +79,7 @@ fn handle_client_message(builder: &mut IfaceBuilder<()>) {
|
|||||||
{
|
{
|
||||||
let data = HashMap::from([
|
let data = HashMap::from([
|
||||||
("name", "new_connection"),
|
("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())) {
|
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.");
|
log::error!("failed to add dbus message to flutter global dbus stream.");
|
||||||
|
@ -33,10 +33,11 @@ use std::{
|
|||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
io::ErrorKind::WouldBlock,
|
io::ErrorKind::WouldBlock,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
sync::Once,
|
|
||||||
time::{self, Duration, Instant},
|
time::{self, Duration, Instant},
|
||||||
};
|
};
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
use std::sync::Once;
|
||||||
|
#[cfg(windows)]
|
||||||
use virtual_display;
|
use virtual_display;
|
||||||
|
|
||||||
pub const SCRAP_UBUNTU_HIGHER_REQUIRED: &str = "Wayland requires Ubuntu 21.04 or higher version.";
|
pub const SCRAP_UBUNTU_HIGHER_REQUIRED: &str = "Wayland requires Ubuntu 21.04 or higher version.";
|
||||||
|
63
src/tray.rs
63
src/tray.rs
@ -4,9 +4,8 @@ use hbb_common::log::{debug, error, info};
|
|||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
use libappindicator::AppIndicator;
|
use libappindicator::AppIndicator;
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
use std::collections::HashMap;
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
use std::env::temp_dir;
|
use std::env::temp_dir;
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
use trayicon::{MenuBuilder, TrayIconBuilder};
|
use trayicon::{MenuBuilder, TrayIconBuilder};
|
||||||
@ -16,6 +15,7 @@ use winit::{
|
|||||||
event_loop::{ControlFlow, EventLoop},
|
event_loop::{ControlFlow, EventLoop},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
#[derive(Clone, Eq, PartialEq, Debug)]
|
#[derive(Clone, Eq, PartialEq, Debug)]
|
||||||
enum Events {
|
enum Events {
|
||||||
DoubleClickTrayIcon,
|
DoubleClickTrayIcon,
|
||||||
@ -44,17 +44,13 @@ pub fn start_tray() {
|
|||||||
} else {
|
} else {
|
||||||
*control_flow = ControlFlow::Wait;
|
*control_flow = ControlFlow::Wait;
|
||||||
}
|
}
|
||||||
let stopped = if let Some(v) = get_option_opt("stop-service") {
|
let stopped = is_service_stoped();
|
||||||
!v.is_empty()
|
let state = if stopped { 2 } else { 1 };
|
||||||
} else {
|
|
||||||
false
|
|
||||||
};
|
|
||||||
let stopped = if stopped { 2 } else { 1 };
|
|
||||||
let old = *old_state.lock().unwrap();
|
let old = *old_state.lock().unwrap();
|
||||||
if stopped != old {
|
if state != old {
|
||||||
hbb_common::log::info!("State changed");
|
hbb_common::log::info!("State changed");
|
||||||
let mut m = MenuBuilder::new();
|
let mut m = MenuBuilder::new();
|
||||||
if stopped == 2 {
|
if state == 2 {
|
||||||
m = m.item(
|
m = m.item(
|
||||||
&crate::client::translate("Start Service".to_owned()),
|
&crate::client::translate("Start Service".to_owned()),
|
||||||
Events::StartService,
|
Events::StartService,
|
||||||
@ -66,7 +62,7 @@ pub fn start_tray() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
tray_icon.set_menu(&m).ok();
|
tray_icon.set_menu(&m).ok();
|
||||||
*old_state.lock().unwrap() = stopped;
|
*old_state.lock().unwrap() = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
@ -91,10 +87,9 @@ pub fn start_tray() {
|
|||||||
/// [Block]
|
/// [Block]
|
||||||
/// This function will block current execution, show the tray icon and handle events.
|
/// This function will block current execution, show the tray icon and handle events.
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
pub fn start_tray(options: Arc<Mutex<HashMap<String, String>>>) {
|
pub fn start_tray() {
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use gtk::traits::{GtkMenuItemExt, MenuShellExt, WidgetExt};
|
use gtk::traits::{GtkMenuItemExt, MenuShellExt, WidgetExt};
|
||||||
|
|
||||||
info!("configuring tray");
|
info!("configuring tray");
|
||||||
// init gtk context
|
// init gtk context
|
||||||
if let Err(err) = gtk::init() {
|
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() {
|
if let Some(mut appindicator) = get_default_app_indicator() {
|
||||||
let mut menu = gtk::Menu::new();
|
let mut menu = gtk::Menu::new();
|
||||||
let running = get_service_status(options.clone());
|
let stoped = is_service_stoped();
|
||||||
// start/stop service
|
// start/stop service
|
||||||
let label = if !running {
|
let label = if stoped {
|
||||||
crate::client::translate("Start Service".to_owned())
|
crate::client::translate("Start Service".to_owned())
|
||||||
} else {
|
} else {
|
||||||
crate::client::translate("Stop service".to_owned())
|
crate::client::translate("Stop service".to_owned())
|
||||||
};
|
};
|
||||||
let menu_item_service = gtk::MenuItem::with_label(label.as_str());
|
let menu_item_service = gtk::MenuItem::with_label(label.as_str());
|
||||||
menu_item_service.connect_activate(move |item| {
|
menu_item_service.connect_activate(move |item| {
|
||||||
let lock = crate::ui_interface::SENDER.lock().unwrap();
|
let _lock = crate::ui_interface::SENDER.lock().unwrap();
|
||||||
update_tray_service_item(options.clone(), item);
|
update_tray_service_item(item);
|
||||||
});
|
});
|
||||||
menu.append(&menu_item_service);
|
menu.append(&menu_item_service);
|
||||||
// show tray item
|
// show tray item
|
||||||
@ -128,19 +123,17 @@ pub fn start_tray(options: Arc<Mutex<HashMap<String, String>>>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn update_tray_service_item(options: Arc<Mutex<HashMap<String, String>>>, item: >k::MenuItem) {
|
fn update_tray_service_item(item: >k::MenuItem) {
|
||||||
use gtk::{
|
use gtk::traits::GtkMenuItemExt;
|
||||||
traits::{GtkMenuItemExt, ListBoxRowExt},
|
|
||||||
MenuItem,
|
if is_service_stoped() {
|
||||||
};
|
|
||||||
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 {
|
|
||||||
debug!("Now try to start service");
|
debug!("Now try to start service");
|
||||||
item.set_label(&crate::client::translate("Stop service".to_owned()));
|
item.set_label(&crate::client::translate("Stop service".to_owned()));
|
||||||
crate::ipc::set_option("stop-service", "");
|
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)
|
Some(appindicator)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get service status
|
/// Check if service is stoped.
|
||||||
/// Return [`true`] if service is running, [`false`] otherwise.
|
/// Return [`true`] if service is stoped, [`false`] otherwise.
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_service_status(options: Arc<Mutex<HashMap<String, String>>>) -> bool {
|
fn is_service_stoped() -> bool {
|
||||||
if let Some(v) = options.lock().unwrap().get("stop-service") {
|
if let Some(v) = get_option_opt("stop-service") {
|
||||||
debug!("service stopped: {}", v);
|
v == "Y"
|
||||||
v.is_empty()
|
|
||||||
} else {
|
} else {
|
||||||
true
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,11 +190,13 @@ pub fn set_local_option(key: String, value: String) {
|
|||||||
LocalConfig::set_option(key, value);
|
LocalConfig::set_option(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_local_flutter_config(key: String) -> String {
|
pub fn get_local_flutter_config(key: String) -> String {
|
||||||
LocalConfig::get_flutter_config(&key)
|
LocalConfig::get_flutter_config(&key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_local_flutter_config(key: String, value: String) {
|
pub fn set_local_flutter_config(key: String, value: String) {
|
||||||
LocalConfig::set_flutter_config(key, value);
|
LocalConfig::set_flutter_config(key, value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user