Skip to content

Commit

Permalink
Remove etcetera dependency (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunacookies authored Nov 2, 2023
1 parent bc0aa46 commit b91e974
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
13 changes: 1 addition & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/pipes-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version = "1.6.2"

[dependencies]
anyhow = "1.0.70"
etcetera = "0.8.0"
home = "0.5.5"
mimalloc = { version = "0.1.36", default-features = false }
model = { path = "../model" }
rng = { path = "../rng" }
Expand Down
26 changes: 16 additions & 10 deletions crates/pipes-rs/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use anyhow::Context;
use etcetera::app_strategy::{AppStrategy, AppStrategyArgs, Xdg};
use model::pipe::{ColorMode, Kind, KindSet, Palette};
use serde::{Deserialize, Serialize};
use std::fs;
use std::path::PathBuf;
use std::time::Duration;
use std::{env, fs};

#[derive(Serialize, Deserialize, Default)]
pub struct Config {
Expand Down Expand Up @@ -40,14 +39,21 @@ impl Config {
}

fn path() -> anyhow::Result<PathBuf> {
let path = Xdg::new(AppStrategyArgs {
top_level_domain: "io.github".to_string(),
author: "lhvy".to_string(),
app_name: "pipes-rs".to_string(),
})?
.in_config_dir("config.toml");

Ok(path)
let config_dir = 'config_dir: {
if let Ok(d) = env::var("XDG_CONFIG_HOME") {
let d = PathBuf::from(d);
if d.is_absolute() {
break 'config_dir d;
}
}

match home::home_dir() {
Some(d) => d.join(".config/"),
None => anyhow::bail!("could not determine home directory"),
}
};

Ok(config_dir.join("pipes-rs/config.toml"))
}

fn read_from_disk(path: PathBuf) -> anyhow::Result<Self> {
Expand Down

0 comments on commit b91e974

Please sign in to comment.