use autostart for --tray in linux because pkexec not work well when start it with --server

This commit is contained in:
rustdesk 2023-06-10 01:55:32 +08:00
parent b14ae250b7
commit 87b32ad8c4
5 changed files with 37 additions and 8 deletions

View File

@ -8,4 +8,3 @@ Icon=rustdesk
Terminal=false Terminal=false
Type=Application Type=Application
StartupNotify=false StartupNotify=false
Version=1.5

View File

@ -1,5 +1,5 @@
[Desktop Entry] [Desktop Entry]
Version=1.5 Version=1.2.0
Name=RustDesk Name=RustDesk
GenericName=Remote Desktop GenericName=Remote Desktop
Comment=Remote Desktop Comment=Remote Desktop

View File

@ -1071,17 +1071,17 @@ pub fn check_process(arg: &str, same_uid: bool) -> bool {
.map(|x| x.user_id()) .map(|x| x.user_id())
.unwrap_or_default(); .unwrap_or_default();
for (_, p) in sys.processes().iter() { for (_, p) in sys.processes().iter() {
if p.pid().to_string() == std::process::id().to_string() {
continue;
}
if same_uid && p.user_id() != my_uid { if same_uid && p.user_id() != my_uid {
continue; continue;
} }
if p.cmd().is_empty() || p.cmd()[0] != app { if p.exe().to_string_lossy() != app {
continue; continue;
} }
if arg.is_empty() { let parg = if p.cmd().len() <= 1 { "" } else { &p.cmd()[1] };
if p.cmd().len() == 1 { if arg == parg {
return true;
}
} else if p.cmd().len() > 1 && p.cmd()[1] == arg {
return true; return true;
} }
} }

View File

@ -41,6 +41,14 @@ pub fn core_main() -> Option<Vec<String>> {
} }
i += 1; i += 1;
} }
#[cfg(any(target_os = "linux", target_os = "windows"))]
if args.is_empty() {
#[cfg(target_os = "linux")]
hbb_common::allow_err!(crate::platform::check_autostart_config());
if crate::check_process("--server", false) && !crate::check_process("--tray", true) {
hbb_common::allow_err!(crate::run_me(vec!["--tray"]));
}
}
#[cfg(not(debug_assertions))] #[cfg(not(debug_assertions))]
#[cfg(not(any(target_os = "android", target_os = "ios")))] #[cfg(not(any(target_os = "android", target_os = "ios")))]
register_breakdown_handler(breakdown_callback); register_breakdown_handler(breakdown_callback);

View File

@ -11,6 +11,7 @@ use hbb_common::{
}; };
use std::{ use std::{
cell::RefCell, cell::RefCell,
io::Write,
path::{Path, PathBuf}, path::{Path, PathBuf},
process::{Child, Command}, process::{Child, Command},
string::String, string::String,
@ -1170,3 +1171,24 @@ fn check_if_stop_service() {
)); ));
} }
} }
pub fn check_autostart_config() -> ResultType<()> {
let home = std::env::var("HOME").unwrap_or_default();
let path = format!("{home}/.config/autostart");
let file = format!("{path}/rustdesk.desktop");
std::fs::create_dir_all(&path).ok();
if !Path::new(&file).exists() {
// write text to the desktop file
let mut file = std::fs::File::create(&file)?;
file.write_all(
"
[Desktop Entry]
Type=Application
Exec=rustdesk --tray
NoDisplay=false
"
.as_bytes(),
)?;
}
Ok(())
}