mod clipboard;
mod config;
mod discovery;
mod focus;
mod paste;
mod server;
mod session;
use tracing_subscriber::EnvFilter;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::try_from_default_env()
.unwrap_or_else(|_| EnvFilter::new("info")),
)
.with_target(false)
.init();
let config = config::Config::load()?;
tracing::info!(
"ClipLink daemon v{} starting",
env!("CARGO_PKG_VERSION")
);
tracing::info!(
"Service name: \"{}\", listening on {}:{}",
config.service.name,
config.server.bind,
config.server.port
);
if config.auth.pin.is_empty() {
tracing::warn!("No PIN configured — any device can connect without authentication");
}
let disc_config = config.clone();
tokio::spawn(async move {
if let Err(e) = discovery::run(disc_config).await {
tracing::error!("Discovery service stopped: {}", e);
}
});
tokio::select! {
result = server::run(config) => {
if let Err(e) = result {
tracing::error!("Server stopped: {}", e);
}
}
_ = shutdown_signal() => {
tracing::info!("Shutting down...");
}
}
Ok(())
}
async fn shutdown_signal() {
tokio::signal::ctrl_c()
.await
.expect("Failed to install Ctrl+C handler");
}