Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): add option to disable easter eggs #48

Merged
merged 5 commits into from
Oct 18, 2023
Merged
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
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
Loading