diff --git a/src/bin/main.rs b/src/bin/main.rs index ca50465..ae83f6c 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -1,8 +1,7 @@ use clap::Parser; -use cmus_notify::arguments::Arguments; use cmus_notify::{ - arguments, + settings::Settings, cmus::{self, query::CmusQueryResponse, CmusError}, }; @@ -13,17 +12,17 @@ macro_rules! sleep { } fn main() { - // Load the configs - let settings = Arguments::load_config_and_parse_args(); + // Load the configs and parse the arguments, and combine them together. + let settings = Settings::load_config_and_parse_args(); // Build the command, or use the default. (to speed up the main loop, because we don't need to build it every time) let mut query_command = cmus::build_query_command( - &args + &settings .cmus_remote_bin_path .unwrap_or("cmus-remote".to_string()) .as_str(), - &args.cmus_socket_address, - &args.cmus_socket_password, + &settings.cmus_socket_address, + &settings.cmus_socket_password, ); // Initialize the buffer to store the response from cmus, to compare it with the next one. @@ -36,11 +35,11 @@ fn main() { loop { // Get the track info, and compare it with the previous one. let Ok(response) = cmus::ping_cmus(&mut query_command) else { - if args.link { + if settings.link { std::process::exit(0) } else { // If the track info is the same as the previous one, just sleep for a while and try again. - sleep!(args.interval); + sleep!(settings.interval); continue; } }; @@ -55,6 +54,6 @@ fn main() { let changes = track.get_changes(&previous_track); */ - sleep!(args.interval); + sleep!(settings.interval); } } diff --git a/src/lib.rs b/src/lib.rs index f2e00fe..2b90a78 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ use std::path::Path; -pub mod arguments; +pub mod settings; pub mod cmus; /// Extracts the first embedded picture from an ID3 tag of an Audio file. diff --git a/src/arguments.rs b/src/settings.rs similarity index 99% rename from src/arguments.rs rename to src/settings.rs index 8dbc836..9b1dbf5 100644 --- a/src/arguments.rs +++ b/src/settings.rs @@ -11,7 +11,7 @@ const DEFAULT_INTERVAL_TIME: u64 = 1000; // 1000 ms #[derive(Parser, Debug, Serialize, Deserialize)] #[command(author, about, version, long_about = None)] -pub struct Arguments { +pub struct Settings { /// The notification timeout, in seconds #[arg(short, long, default_value_t = NOTIFICATION_TIMEOUT)] pub timeout: u8, @@ -150,7 +150,7 @@ pub struct Arguments { pub no_use_external_lyrics: bool, } -impl Default for Arguments { +impl Default for Settings { fn default() -> Self { Self { timeout: NOTIFICATION_TIMEOUT, @@ -178,7 +178,7 @@ impl Default for Arguments { } } -impl Arguments { +impl Settings { pub fn load_config_and_parse_args() -> Self { // load config file let cfg: Self = match confy::load("cmus-notify", "config") { @@ -190,7 +190,7 @@ impl Arguments { }; // parse the args - let mut args = Arguments::parse(); + let mut args = Settings::parse(); // Combine the config and args(the args will override the config) if args.timeout == NOTIFICATION_TIMEOUT {