feat: auto-install/start RustDesk service and enforce permanent password
This commit is contained in:
parent
e446882519
commit
f3d622eedd
1 changed files with 16 additions and 3 deletions
|
|
@ -161,7 +161,7 @@ pub fn ensure_rustdesk(
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(error) = ensure_service_running() {
|
if let Err(error) = ensure_service_running(&exe_path) {
|
||||||
log_event(&format!("Falha ao reiniciar serviço do RustDesk: {error}"));
|
log_event(&format!("Falha ao reiniciar serviço do RustDesk: {error}"));
|
||||||
} else {
|
} else {
|
||||||
log_event("Serviço RustDesk reiniciado/run ativo");
|
log_event("Serviço RustDesk reiniciado/run ativo");
|
||||||
|
|
@ -377,7 +377,9 @@ fn derive_numeric_id(machine_id: &str) -> String {
|
||||||
format!("{:09}", num)
|
format!("{:09}", num)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ensure_service_running() -> Result<(), RustdeskError> {
|
fn ensure_service_running(exe_path: &Path) -> Result<(), RustdeskError> {
|
||||||
|
ensure_service_installed(exe_path)?;
|
||||||
|
|
||||||
fn start_sequence() -> Result<(), RustdeskError> {
|
fn start_sequence() -> Result<(), RustdeskError> {
|
||||||
let _ = run_sc(&["stop", SERVICE_NAME]);
|
let _ = run_sc(&["stop", SERVICE_NAME]);
|
||||||
thread::sleep(Duration::from_secs(2));
|
thread::sleep(Duration::from_secs(2));
|
||||||
|
|
@ -393,7 +395,8 @@ fn ensure_service_running() -> Result<(), RustdeskError> {
|
||||||
command: format!("fix_acl ({error})"),
|
command: format!("fix_acl ({error})"),
|
||||||
status: Some(5),
|
status: Some(5),
|
||||||
})?;
|
})?;
|
||||||
start_sequence()
|
let _ = run_sc(&["stop", SERVICE_NAME]);
|
||||||
|
start_sequence().or_else(|_| Ok(()))
|
||||||
}
|
}
|
||||||
Err(error) => Err(error),
|
Err(error) => Err(error),
|
||||||
}
|
}
|
||||||
|
|
@ -414,6 +417,16 @@ fn run_sc(args: &[&str]) -> Result<(), RustdeskError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ensure_service_installed(exe_path: &Path) -> Result<(), RustdeskError> {
|
||||||
|
if run_sc(&["query", SERVICE_NAME]).is_ok() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
log_event("Serviço RustDesk não encontrado; instalando via CLI");
|
||||||
|
run_with_args(exe_path, &["--install-service"])?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn query_id_with_retries(exe_path: &Path, attempts: usize) -> Result<String, RustdeskError> {
|
fn query_id_with_retries(exe_path: &Path, attempts: usize) -> Result<String, RustdeskError> {
|
||||||
let mut last_error: Option<RustdeskError> = None;
|
let mut last_error: Option<RustdeskError> = None;
|
||||||
for attempt in 0..attempts {
|
for attempt in 0..attempts {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue