fix(desktop): corrige reinstalacao do RavenService e uso via IPC
- NSIS: remove servico antigo antes de instalar novo (corrige reinstalacoes) - NSIS: adiciona retry ao iniciar servico - agent.rs: usa service_client para aplicar politica USB via IPC primeiro - Fallback para aplicacao direta se servico indisponivel 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
f6efc0d678
commit
8863fffc37
2 changed files with 80 additions and 21 deletions
|
|
@ -1225,7 +1225,8 @@ async fn check_and_apply_usb_policy(base_url: &str, token: &str) {
|
|||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
use crate::usb_control::{apply_usb_policy, get_current_policy, UsbPolicy};
|
||||
use crate::usb_control::{get_current_policy, UsbPolicy};
|
||||
use crate::service_client;
|
||||
|
||||
let policy = match UsbPolicy::from_str(&policy_str) {
|
||||
Some(p) => p,
|
||||
|
|
@ -1259,24 +1260,58 @@ async fn check_and_apply_usb_policy(base_url: &str, token: &str) {
|
|||
// Reporta APPLYING para progress bar real no frontend
|
||||
let _ = report_usb_policy_status(base_url, token, "APPLYING", None, None).await;
|
||||
|
||||
match apply_usb_policy(policy) {
|
||||
// Tenta primeiro via RavenService (privilegiado)
|
||||
crate::log_info!("Tentando aplicar politica via RavenService...");
|
||||
match service_client::apply_usb_policy(&policy_str) {
|
||||
Ok(result) => {
|
||||
crate::log_info!("Politica USB aplicada com sucesso: {:?}", result);
|
||||
let reported = report_usb_policy_status(base_url, token, "APPLIED", None, Some(policy_str.clone())).await;
|
||||
if !reported {
|
||||
crate::log_error!("CRITICO: Politica aplicada mas falha ao reportar ao servidor!");
|
||||
// Agenda retry em background
|
||||
let base_url = base_url.to_string();
|
||||
let token = token.to_string();
|
||||
tokio::spawn(async move {
|
||||
tokio::time::sleep(Duration::from_secs(60)).await;
|
||||
crate::log_info!("Retry agendado: reportando politica USB...");
|
||||
let _ = report_usb_policy_status(&base_url, &token, "APPLIED", None, Some(policy_str)).await;
|
||||
});
|
||||
if result.success {
|
||||
crate::log_info!("Politica USB aplicada com sucesso via RavenService: {:?}", result);
|
||||
let reported = report_usb_policy_status(base_url, token, "APPLIED", None, Some(policy_str.clone())).await;
|
||||
if !reported {
|
||||
crate::log_error!("CRITICO: Politica aplicada mas falha ao reportar ao servidor!");
|
||||
let base_url = base_url.to_string();
|
||||
let token = token.to_string();
|
||||
tokio::spawn(async move {
|
||||
tokio::time::sleep(Duration::from_secs(60)).await;
|
||||
crate::log_info!("Retry agendado: reportando politica USB...");
|
||||
let _ = report_usb_policy_status(&base_url, &token, "APPLIED", None, Some(policy_str)).await;
|
||||
});
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
let err_msg = result.error.unwrap_or_else(|| "Erro desconhecido".to_string());
|
||||
crate::log_error!("RavenService retornou erro: {}", err_msg);
|
||||
report_usb_policy_status(base_url, token, "FAILED", Some(err_msg), None).await;
|
||||
}
|
||||
}
|
||||
Err(service_client::ServiceClientError::ServiceUnavailable(msg)) => {
|
||||
crate::log_warn!("RavenService nao disponivel: {}", msg);
|
||||
// Tenta fallback direto (vai falhar se nao tiver privilegio)
|
||||
crate::log_info!("Tentando aplicar politica diretamente...");
|
||||
match crate::usb_control::apply_usb_policy(policy) {
|
||||
Ok(result) => {
|
||||
crate::log_info!("Politica USB aplicada com sucesso (direto): {:?}", result);
|
||||
let reported = report_usb_policy_status(base_url, token, "APPLIED", None, Some(policy_str.clone())).await;
|
||||
if !reported {
|
||||
crate::log_error!("CRITICO: Politica aplicada mas falha ao reportar ao servidor!");
|
||||
let base_url = base_url.to_string();
|
||||
let token = token.to_string();
|
||||
tokio::spawn(async move {
|
||||
tokio::time::sleep(Duration::from_secs(60)).await;
|
||||
crate::log_info!("Retry agendado: reportando politica USB...");
|
||||
let _ = report_usb_policy_status(&base_url, &token, "APPLIED", None, Some(policy_str)).await;
|
||||
});
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
let err_msg = format!("RavenService indisponivel e aplicacao direta falhou: {}. Instale ou inicie o RavenService.", e);
|
||||
crate::log_error!("{}", err_msg);
|
||||
report_usb_policy_status(base_url, token, "FAILED", Some(err_msg), None).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
crate::log_error!("Falha ao aplicar politica USB: {e}");
|
||||
crate::log_error!("Falha ao comunicar com RavenService: {e}");
|
||||
report_usb_policy_status(base_url, token, "FAILED", Some(e.to_string()), None).await;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue