rustdesk 2024-08-06 12:11:03 +08:00
parent 2662abc5a3
commit 421ddc0016
2 changed files with 34 additions and 18 deletions

View File

@ -261,6 +261,16 @@ pub fn core_main() -> Option<Vec<String>> {
return None;
} else if args[0] == "--server" {
log::info!("start --server with user {}", crate::username());
#[cfg(target_os = "linux")]
{
hbb_common::allow_err!(crate::platform::check_autostart_config());
std::process::Command::new("pkill")
.arg("-f")
.arg(&format!("%s --tray", crate::get_app_name().to_lowercase()))
.status()
.ok();
allow_err!(crate::crate::platform::run_as_user(vec!["--tray"]));
}
#[cfg(windows)]
crate::privacy_mode::restore_reg_connectivity(true);
#[cfg(any(target_os = "linux", target_os = "windows"))]
@ -398,7 +408,8 @@ pub fn core_main() -> Option<Vec<String>> {
"uuid": uuid,
});
let header = "Authorization: Bearer ".to_owned() + &token;
if user_name.is_none() && strategy_name.is_none() && address_book_name.is_none() {
if user_name.is_none() && strategy_name.is_none() && address_book_name.is_none()
{
println!(
"--user_name or --strategy_name or --address_book_name is required!"
);

View File

@ -730,7 +730,8 @@ pub fn block_input(_v: bool) -> (bool, String) {
pub fn is_installed() -> bool {
if let Ok(p) = std::env::current_exe() {
p.to_str().unwrap_or_default().starts_with("/usr") || p.to_str().unwrap_or_default().starts_with("/nix/store")
p.to_str().unwrap_or_default().starts_with("/usr")
|| p.to_str().unwrap_or_default().starts_with("/nix/store")
} else {
false
}
@ -1413,22 +1414,26 @@ pub fn check_autostart_config() -> ResultType<()> {
let app_name = crate::get_app_name().to_lowercase();
let path = format!("{home}/.config/autostart");
let file = format!("{path}/{app_name}.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(
format!(
"
[Desktop Entry]
Type=Application
Exec={app_name} --tray
NoDisplay=false
"
)
.as_bytes(),
)?;
}
// https://github.com/rustdesk/rustdesk/issues/4863
std::fs::remove_file(&file).ok();
/*
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(
format!(
"
[Desktop Entry]
Type=Application
Exec={app_name} --tray
NoDisplay=false
"
)
.as_bytes(),
)?;
}
*/
Ok(())
}