53 lines
1.6 KiB
Rust
53 lines
1.6 KiB
Rust
use hyprmonitors::{create_app, verify_hyprland_connection, Config};
|
|
use tracing::{error, info};
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
// Load configuration
|
|
let config = Config::from_env();
|
|
|
|
// Initialize tracing with configured log level
|
|
let log_level = config
|
|
.server
|
|
.log_level
|
|
.parse()
|
|
.unwrap_or(tracing::Level::INFO);
|
|
tracing_subscriber::fmt()
|
|
.with_target(false)
|
|
.with_max_level(log_level)
|
|
.compact()
|
|
.init();
|
|
|
|
// Print configuration summary
|
|
config.print_summary();
|
|
|
|
// Verify Hyprland connection
|
|
if let Err(e) = verify_hyprland_connection().await {
|
|
error!("Failed to connect to Hyprland: {}", e);
|
|
error!("Make sure you're running this inside a Hyprland session");
|
|
return Err(e);
|
|
}
|
|
|
|
// Create the application
|
|
let app = create_app(&config);
|
|
|
|
// Run the server
|
|
let bind_addr = config.bind_address();
|
|
let listener = tokio::net::TcpListener::bind(&bind_addr).await?;
|
|
|
|
info!(
|
|
"Hyprland Monitor Control Server running on {}",
|
|
config.server_url()
|
|
);
|
|
info!("Available endpoints:");
|
|
info!(" GET /health - Health check");
|
|
info!(" POST /monitors/on - Turn all monitors on");
|
|
info!(" POST /monitors/off - Turn all monitors off");
|
|
info!(" POST /monitors/:monitor/on - Turn specific monitor on");
|
|
info!(" POST /monitors/:monitor/off - Turn specific monitor off");
|
|
info!(" GET /monitors/status - Get monitor status");
|
|
|
|
axum::serve(listener, app).await?;
|
|
Ok(())
|
|
}
|