generalbots/botdevice/src/lib.rs
Rodrigo Rodriguez (Pragmatismo) 037db5c381 feat: Major workspace reorganization and documentation update
- Add comprehensive documentation in botbook/ with 12 chapters
- Add botapp/ Tauri desktop application
- Add botdevice/ IoT device support
- Add botlib/ shared library crate
- Add botmodels/ Python ML models service
- Add botplugin/ browser extension
- Add botserver/ reorganized server code
- Add bottemplates/ bot templates
- Add bottest/ integration tests
- Add botui/ web UI server
- Add CI/CD workflows in .forgejo/workflows/
- Add AGENTS.md and PROD.md documentation
- Add dependency management scripts (DEPENDENCIES.sh/ps1)
- Remove legacy src/ structure and migrations
- Clean up temporary and backup files
2026-04-19 08:14:25 -03:00

65 lines
1.8 KiB
Rust

#[cfg(target_os = "android")]
fn init_logger() {
android_logger::init_once(
android_logger::Config::default()
.with_max_level(log::LevelFilter::Info)
.with_tag("BotOS"),
);
}
#[cfg(not(target_os = "android"))]
fn init_logger() {
env_logger::init();
}
#[tauri::command]
fn get_device_info() -> serde_json::Value {
serde_json::json!({
"platform": "android",
"app": "BotOS",
"version": env!("CARGO_PKG_VERSION")
})
}
#[tauri::command]
async fn send_to_bot(message: String, server_url: String) -> Result<String, String> {
let client = reqwest::Client::new();
let response = client
.post(format!("{server_url}/api/messages"))
.json(&serde_json::json!({ "text": message }))
.send()
.await
.map_err(|e| e.to_string())?;
response.text().await.map_err(|e| e.to_string())
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
init_logger();
log::info!("BotOS starting...");
tauri::Builder::default()
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_notification::init())
.plugin(tauri_plugin_http::init())
.plugin(tauri_plugin_geolocation::init())
.invoke_handler(tauri::generate_handler![get_device_info, send_to_bot])
.setup(|_app| {
log::info!("BotOS initialized, loading botui...");
#[cfg(debug_assertions)]
{
use tauri::Manager;
if let Some(window) = _app.get_webview_window("main") {
window.open_devtools();
}
}
Ok(())
})
.run(tauri::generate_context!())
.unwrap_or_else(|e| log::error!("BotOS failed to start: {e}"));
}