add flutter start_server & fix cm user environment from linux service

This commit is contained in:
csf 2022-09-07 20:08:12 +08:00
parent d0c438268d
commit 121111b864
2 changed files with 27 additions and 12 deletions

View File

@ -1,6 +1,6 @@
use hbb_common::log; use hbb_common::log;
use crate::{start_os_service, flutter::connection_manager}; use crate::{start_os_service, flutter::connection_manager, start_server};
/// Main entry of the RustDesk Core. /// Main entry of the RustDesk Core.
/// Return true if the app should continue running with UI(possibly Flutter), false if the app should exit. /// Return true if the app should continue running with UI(possibly Flutter), false if the app should exit.
@ -20,7 +20,15 @@ pub fn core_main() -> bool {
return false; return false;
} }
if args[1] == "--server" { if args[1] == "--server" {
// TODO: server log::info!("start --server");
#[cfg(not(target_os = "macos"))]
{
start_server(true);
}
#[cfg(target_os = "macos")]
{
std::thread::spawn(move || start_server(true));
}
return false; return false;
} }
} }

View File

@ -525,20 +525,27 @@ pub fn is_root() -> bool {
crate::username() == "root" crate::username() == "root"
} }
fn is_opensuse() -> bool {
if let Ok(res) = run_cmds("cat /etc/os-release | grep opensuse".to_owned()) {
if !res.is_empty() {
return true;
}
}
false
}
pub fn run_as_user(arg: &str) -> ResultType<Option<std::process::Child>> { pub fn run_as_user(arg: &str) -> ResultType<Option<std::process::Child>> {
let uid = get_active_userid(); let uid = get_active_userid();
let cmd = std::env::current_exe()?; let cmd = std::env::current_exe()?;
let xdg = &format!("XDG_RUNTIME_DIR=/run/user/{}", uid) as &str;
let username = &get_active_username();
let mut args = vec![xdg, "-u", username, cmd.to_str().unwrap_or(""), arg];
// -E required for opensuse // -E required for opensuse
let task = std::process::Command::new("sudo") if is_opensuse() {
.args(vec![ args.insert(0, "-E");
"-E", }
&format!("XDG_RUNTIME_DIR=/run/user/{}", uid) as &str,
"-u", let task = std::process::Command::new("sudo").args(args).spawn()?;
&get_active_username(),
cmd.to_str().unwrap_or(""),
arg,
])
.spawn()?;
Ok(Some(task)) Ok(Some(task))
} }