Skip to content

Commit

Permalink
feat(config): add option to disable easter eggs (#48)
Browse files Browse the repository at this point in the history
* feat(config): Add option to disable easter egs

* style(readme): apply formatting

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
  • Loading branch information
3 people committed Oct 18, 2023
1 parent 666cf57 commit 7d347ad
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ daktilo --device pipewire

Also, you can use `--list-devices` to list the available output devices.

<details>
<summary>Spoiler warning</summary>

There are easter eggs. If that is something you do not like you can disable them either via the config file option `no_surprises = true` or using the command-line flag:

```sh
daktilo --no-surprises
```

</details>

## Supported Platforms

- [x] Linux
Expand Down
3 changes: 3 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ pub struct Args {
/// Writes the default configuration file.
#[arg(short, long)]
pub init: bool,
/// Disables the easter eggs.
#[arg(long, hide = true)]
pub no_surprises: bool,
}

#[cfg(test)]
Expand Down
5 changes: 4 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub struct Config {
/// Sound presets.
#[serde(rename = "sound_preset")]
pub sound_presets: Vec<SoundPreset>,
/// Disable the easter eggs.
#[serde(rename = "no_surprises", default)]
pub disable_easter_eggs: bool,
}

impl Config {
Expand Down Expand Up @@ -54,7 +57,7 @@ impl Config {

/// Returns a preset by its name if it exists.
pub fn select_preset(&self, name: &str) -> Result<SoundPreset> {
if fastrand::usize(0..1000) == 42 || name == "ak47" {
if !self.disable_easter_eggs && fastrand::usize(0..1000) == 42 || name == "ak47" {
return Ok(SoundPreset {
name: String::new(),
key_config: vec![
Expand Down
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ async fn main() -> Result<()> {
return Ok(());
}
let config_path = args.config.or(Config::get_default_location());
let config = if config_path.as_ref().is_some_and(|v| v.exists()) {
let mut config = if config_path.as_ref().is_some_and(|v| v.exists()) {
// unwrap is checked above.
Config::parse(&config_path.unwrap())?
} else {
tracing::warn!("Using the default configuration (run with `--init` to save it to a file).");
EmbeddedConfig::parse()?
};

if args.no_surprises {
tracing::debug!("I bet you're fun at parties.");
config.disable_easter_eggs = true;
}

tracing::debug!("{:#?}", config);

// Start the typewriter.
Expand Down

0 comments on commit 7d347ad

Please sign in to comment.