agent-orchestrator/src-tauri/src/commands/misc.rs
2026-03-18 01:22:27 +01:00

48 lines
1.6 KiB
Rust

// Miscellaneous commands — CLI args, URL opening, frontend telemetry
use crate::error::AppError;
#[tauri::command]
pub fn cli_get_group() -> Option<String> {
let args: Vec<String> = std::env::args().collect();
let mut i = 1;
while i < args.len() {
if args[i] == "--group" {
if i + 1 < args.len() {
return Some(args[i + 1].clone());
}
} else if let Some(val) = args[i].strip_prefix("--group=") {
return Some(val.to_string());
}
i += 1;
}
None
}
#[tauri::command]
pub fn open_url(url: String) -> Result<(), AppError> {
if !url.starts_with("http://") && !url.starts_with("https://") {
return Err(AppError::validation("Only http/https URLs are allowed"));
}
std::process::Command::new("xdg-open")
.arg(&url)
.spawn()
.map_err(|e| AppError::internal(format!("Failed to open URL: {e}")))?;
Ok(())
}
#[tauri::command]
pub fn is_test_mode() -> bool {
std::env::var("AGOR_TEST").map_or(false, |v| v == "1")
}
#[tauri::command]
pub fn frontend_log(level: String, message: String, context: Option<serde_json::Value>) {
match level.as_str() {
"error" => tracing::error!(source = "frontend", ?context, "{message}"),
"warn" => tracing::warn!(source = "frontend", ?context, "{message}"),
"info" => tracing::info!(source = "frontend", ?context, "{message}"),
"debug" => tracing::debug!(source = "frontend", ?context, "{message}"),
_ => tracing::trace!(source = "frontend", ?context, "{message}"),
}
}