Don't exit daemon when initial load fails
This commit is contained in:
parent
99fd51dc12
commit
b836549232
2 changed files with 30 additions and 11 deletions
|
@ -18,8 +18,17 @@ pub struct EwwConfig {
|
|||
script_vars: HashMap<VarName, ScriptVarDefinition>,
|
||||
}
|
||||
|
||||
impl Default for EwwConfig {
|
||||
fn default() -> Self {
|
||||
Self { widgets: HashMap::new(), windows: HashMap::new(), initial_variables: HashMap::new(), script_vars: HashMap::new() }
|
||||
}
|
||||
}
|
||||
|
||||
impl EwwConfig {
|
||||
pub fn read_from_file(files: &mut YuckFiles, path: impl AsRef<Path>) -> Result<Self> {
|
||||
if !path.as_ref().exists() {
|
||||
bail!("The configuration file `{}` does not exist", path.as_ref().display());
|
||||
}
|
||||
let config = Config::generate_from_main_file(files, path)?;
|
||||
let Config { widget_definitions, window_definitions, var_definitions, mut script_vars } = config;
|
||||
script_vars.extend(crate::config::inbuilt::get_inbuilt_vars());
|
||||
|
|
|
@ -10,6 +10,27 @@ use std::{
|
|||
use tokio::sync::mpsc::*;
|
||||
|
||||
pub fn initialize_server(paths: EwwPaths) -> Result<()> {
|
||||
let (ui_send, mut ui_recv) = tokio::sync::mpsc::unbounded_channel();
|
||||
|
||||
std::env::set_current_dir(&paths.get_config_dir())
|
||||
.with_context(|| format!("Failed to change working directory to {}", paths.get_config_dir().display()))?;
|
||||
|
||||
log::info!("Loading paths: {}", &paths);
|
||||
|
||||
// disgusting global state, I hate this, but https://github.com/buffet told me that this is what I should do for peak maintainability
|
||||
error_handling_ctx::clear_files();
|
||||
|
||||
let read_config =
|
||||
config::EwwConfig::read_from_file(&mut error_handling_ctx::ERROR_HANDLING_CTX.lock().unwrap(), &paths.get_yuck_path());
|
||||
|
||||
let eww_config = match read_config {
|
||||
Ok(config) => config,
|
||||
Err(err) => {
|
||||
error_handling_ctx::print_error(err);
|
||||
config::EwwConfig::default()
|
||||
}
|
||||
};
|
||||
|
||||
do_detach(&paths.get_log_file())?;
|
||||
|
||||
println!(
|
||||
|
@ -27,17 +48,6 @@ pub fn initialize_server(paths: EwwPaths) -> Result<()> {
|
|||
std::process::exit(1);
|
||||
}
|
||||
});
|
||||
let (ui_send, mut ui_recv) = tokio::sync::mpsc::unbounded_channel();
|
||||
|
||||
std::env::set_current_dir(&paths.get_config_dir())
|
||||
.with_context(|| format!("Failed to change working directory to {}", paths.get_config_dir().display()))?;
|
||||
|
||||
log::info!("Loading paths: {}", &paths);
|
||||
|
||||
// disgusting global state, I hate this, but https://github.com/buffet told me that this is what I should do for peak maintainability
|
||||
error_handling_ctx::clear_files();
|
||||
let eww_config =
|
||||
config::EwwConfig::read_from_file(&mut error_handling_ctx::ERROR_HANDLING_CTX.lock().unwrap(), &paths.get_yuck_path())?;
|
||||
|
||||
gtk::init()?;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue