pub mod paths;
#[cfg(unix)]
pub mod client;
#[cfg(unix)]
pub mod lifecycle;
#[cfg(unix)]
pub mod protocol;
#[cfg(unix)]
pub mod registry;
#[cfg(unix)]
pub mod server;
#[cfg(unix)]
pub mod service;
#[cfg(unix)]
pub mod services;
#[cfg(unix)]
pub mod single_instance;
#[cfg(target_os = "macos")]
pub mod launchd;
#[cfg(all(target_os = "macos", feature = "menu-bar"))]
pub mod tray;
#[cfg(unix)]
use std::path::Path;
#[cfg(unix)]
use std::path::PathBuf;
#[cfg(unix)]
use std::sync::Arc;
#[cfg(unix)]
use anyhow::Result;
#[cfg(unix)]
use crate::browser::BridgeConfig;
#[cfg(unix)]
use crate::snowflake::SnowflakeEngineConfig;
#[cfg(unix)]
use registry::ServiceRegistry;
#[cfg(unix)]
use server::DaemonOptions;
#[cfg(unix)]
use services::bridge::BridgeService;
#[cfg(unix)]
use services::snowflake::SnowflakeService;
#[cfg(unix)]
use services::worktrees::WorktreesService;
#[cfg(unix)]
#[derive(Debug, Clone)]
pub struct DaemonRunConfig {
pub socket_path: PathBuf,
pub bridge_config: BridgeConfig,
pub bridge_token_file: Option<PathBuf>,
pub bridge_token_path: PathBuf,
}
#[cfg(unix)]
pub async fn build_default_registry(
bridge_config: BridgeConfig,
bridge_token_file: Option<&Path>,
bridge_token_path: PathBuf,
) -> Result<ServiceRegistry> {
let mut registry = ServiceRegistry::new();
let bridge = BridgeService::start(bridge_config, bridge_token_file, bridge_token_path).await?;
registry.register(Arc::new(bridge));
let snowflake = SnowflakeService::new(SnowflakeEngineConfig::from_env_and_settings()?);
registry.register(Arc::new(snowflake));
registry.register(Arc::new(WorktreesService::new()));
Ok(registry)
}
#[cfg(unix)]
pub async fn run_headless(cfg: DaemonRunConfig) -> Result<()> {
let registry = build_default_registry(
cfg.bridge_config,
cfg.bridge_token_file.as_deref(),
cfg.bridge_token_path,
)
.await?;
server::run(
registry,
DaemonOptions {
socket_path: cfg.socket_path,
},
)
.await
}