use crate::{commands::DelphiCmd, config::DelphiConfig};
use abscissa_core::{
application::{self, AppCell},
config::{self, CfgCell},
trace, Application, EntryPoint, FrameworkError, StandardPaths,
};
pub static APP: AppCell<DelphiApp> = AppCell::new();
#[derive(Debug)]
pub struct DelphiApp {
config: CfgCell<DelphiConfig>,
state: application::State<Self>,
}
impl Default for DelphiApp {
fn default() -> Self {
Self {
config: CfgCell::default(),
state: application::State::default(),
}
}
}
impl Application for DelphiApp {
type Cmd = EntryPoint<DelphiCmd>;
type Cfg = DelphiConfig;
type Paths = StandardPaths;
fn config(&self) -> config::Reader<DelphiConfig> {
self.config.read()
}
fn state(&self) -> &application::State<Self> {
&self.state
}
fn register_components(&mut self, command: &Self::Cmd) -> Result<(), FrameworkError> {
let mut components = self.framework_components(command)?;
components.push(Box::new(abscissa_tokio::TokioComponent::new()?));
let mut component_registry = self.state.components_mut();
component_registry.register(components)
}
fn after_config(&mut self, config: Self::Cfg) -> Result<(), FrameworkError> {
let mut component_registry = self.state.components_mut();
component_registry.after_config(&config)?;
self.config.set_once(config);
Ok(())
}
fn tracing_config(&self, command: &EntryPoint<DelphiCmd>) -> trace::Config {
if command.verbose {
trace::Config::verbose()
} else {
trace::Config::default()
}
}
}