Provisiona RustDesk automaticamente
This commit is contained in:
parent
967d4bf1c6
commit
ef1db284fa
6 changed files with 565 additions and 9 deletions
|
|
@ -1,8 +1,19 @@
|
|||
mod agent;
|
||||
#[cfg(target_os = "windows")]
|
||||
mod rustdesk;
|
||||
|
||||
use agent::{collect_inventory_plain, collect_profile, AgentRuntime, MachineProfile};
|
||||
use tauri_plugin_store::Builder as StorePluginBuilder;
|
||||
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RustdeskProvisioningResult {
|
||||
pub id: String,
|
||||
pub password: String,
|
||||
pub installed_version: Option<String>,
|
||||
pub updated: bool,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn collect_machine_profile() -> Result<MachineProfile, String> {
|
||||
collect_profile().map_err(|error| error.to_string())
|
||||
|
|
@ -38,6 +49,26 @@ fn open_devtools(window: tauri::WebviewWindow) -> Result<(), String> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn provision_rustdesk(machine_id: Option<String>) -> Result<RustdeskProvisioningResult, String> {
|
||||
let machine_id = machine_id
|
||||
.filter(|value| !value.trim().is_empty())
|
||||
.ok_or_else(|| "Informe o identificador da máquina para provisionar o RustDesk.".to_string())?;
|
||||
tauri::async_runtime::spawn_blocking(move || run_rustdesk_provision(machine_id))
|
||||
.await
|
||||
.map_err(|error| error.to_string())?
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
fn run_rustdesk_provision(machine_id: String) -> Result<RustdeskProvisioningResult, String> {
|
||||
rustdesk::provision(&machine_id).map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
fn run_rustdesk_provision(_machine_id: String) -> Result<RustdeskProvisioningResult, String> {
|
||||
Err("Provisionamento automático do RustDesk está disponível apenas no Windows.".to_string())
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
|
|
@ -51,7 +82,8 @@ pub fn run() {
|
|||
collect_machine_inventory,
|
||||
start_machine_agent,
|
||||
stop_machine_agent,
|
||||
open_devtools
|
||||
open_devtools,
|
||||
provision_rustdesk
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue