Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

## Features

- yofi.toml is now supported.

## Changes

- yofi.config is deprecated.

## Fixes

# 0.2.2 - 2024-03-10
Expand Down
7 changes: 5 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@

devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
rustc
cargo
pkg-config
clippy
libxkbcommon
pkg-config
rust-analyzer
rustc
rustfmt
];

LD_LIBRARY_PATH = rpath;
Expand Down
31 changes: 20 additions & 11 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use serde::Deserialize;
use crate::style::{Margin, Padding, Radius};
use crate::Color;

const DEFAULT_CONFIG_NAME: &str = concat!(crate::prog_name!(), ".config");
const DEFAULT_CONFIG_NAMES: [&str; 2] = [
concat!(crate::prog_name!(), ".toml"),
concat!(crate::prog_name!(), ".config"),
];

const DEFAULT_ICON_SIZE: u16 = 16;
const DEFAULT_FONT_SIZE: u16 = 24;
Expand Down Expand Up @@ -112,17 +115,23 @@ struct Icon {
}

fn default_config_path() -> Result<Option<PathBuf>> {
let file = xdg::BaseDirectories::with_prefix(crate::prog_name!())
.context("failed to get xdg dirs")?
.get_config_file(DEFAULT_CONFIG_NAME);
if file
.try_exists()
.with_context(|| format!("reading default config at {}", file.display()))?
{
Ok(Some(file))
} else {
Ok(None)
let xdg_dirs =
xdg::BaseDirectories::with_prefix(crate::prog_name!()).context("failed to get xdg dirs")?;

for (index, &filename) in DEFAULT_CONFIG_NAMES.iter().enumerate() {
let file = xdg_dirs.get_config_file(filename);
if file
.try_exists()
.with_context(|| format!("reading default config at {}", file.display()))?
{
if index != 0 {
eprintln!("warning: yofi.config is deprecated, please rename your configuration file to yofi.toml");
}
return Ok(Some(file));
}
}

Ok(None)
}

impl Config {
Expand Down