feat: add config file
This commit is contained in:
parent
75538cc3d3
commit
e6d2d0946a
5 changed files with 123 additions and 5 deletions
|
@ -2,9 +2,29 @@ mod ipc;
|
|||
mod manager;
|
||||
mod socket;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use std::io::Read;
|
||||
|
||||
use anyhow::{Context, Result, anyhow};
|
||||
use microxdg::Xdg;
|
||||
use niri_tag::Config;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// try to read a config
|
||||
let xdg = Xdg::new()?;
|
||||
let mut config_dir = xdg.config()?;
|
||||
config_dir.push("niri-tag");
|
||||
config_dir.push("config.toml");
|
||||
|
||||
let config = std::fs::File::open(config_dir)
|
||||
.map_err(|e| anyhow!(e))
|
||||
.and_then(|mut f| {
|
||||
let mut buf = String::new();
|
||||
f.read_to_string(&mut buf).map_err(|e| anyhow!(e))?;
|
||||
Ok(buf)
|
||||
})
|
||||
.and_then(|buf| toml::from_str::<Config>(&buf).map_err(|e| anyhow!(e)))
|
||||
.inspect_err(|e| tracing::error!("Using default config due to: {}", e))
|
||||
.unwrap_or_default();
|
||||
// let systemd know we're ready
|
||||
let _ = libsystemd::daemon::notify(false, &[libsystemd::daemon::NotifyState::Ready])?;
|
||||
// debug stuff
|
||||
|
@ -25,7 +45,7 @@ fn main() -> Result<()> {
|
|||
smol::spawn(ipc::event_provider(event_rx, fullstate_tx)).detach();
|
||||
// begin managing niri tags
|
||||
smol::block_on(async {
|
||||
let niri_tag = manager::NiriTag::new(event_tx)
|
||||
let niri_tag = manager::NiriTag::new(config, event_tx)
|
||||
.await
|
||||
.context("Initialising niri tag manager")
|
||||
.unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue