Just reformat the code
This commit is contained in:
parent
25cce99b80
commit
1ea44b528c
3 changed files with 14 additions and 15 deletions
|
@ -1,8 +1,7 @@
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
use cmus_notify::arguments::Arguments;
|
|
||||||
use cmus_notify::{
|
use cmus_notify::{
|
||||||
arguments,
|
settings::Settings,
|
||||||
cmus::{self, query::CmusQueryResponse, CmusError},
|
cmus::{self, query::CmusQueryResponse, CmusError},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,17 +12,17 @@ macro_rules! sleep {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Load the configs
|
// Load the configs and parse the arguments, and combine them together.
|
||||||
let settings = Arguments::load_config_and_parse_args();
|
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)
|
// 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(
|
let mut query_command = cmus::build_query_command(
|
||||||
&args
|
&settings
|
||||||
.cmus_remote_bin_path
|
.cmus_remote_bin_path
|
||||||
.unwrap_or("cmus-remote".to_string())
|
.unwrap_or("cmus-remote".to_string())
|
||||||
.as_str(),
|
.as_str(),
|
||||||
&args.cmus_socket_address,
|
&settings.cmus_socket_address,
|
||||||
&args.cmus_socket_password,
|
&settings.cmus_socket_password,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Initialize the buffer to store the response from cmus, to compare it with the next one.
|
// Initialize the buffer to store the response from cmus, to compare it with the next one.
|
||||||
|
@ -36,11 +35,11 @@ fn main() {
|
||||||
loop {
|
loop {
|
||||||
// Get the track info, and compare it with the previous one.
|
// Get the track info, and compare it with the previous one.
|
||||||
let Ok(response) = cmus::ping_cmus(&mut query_command) else {
|
let Ok(response) = cmus::ping_cmus(&mut query_command) else {
|
||||||
if args.link {
|
if settings.link {
|
||||||
std::process::exit(0)
|
std::process::exit(0)
|
||||||
} else {
|
} else {
|
||||||
// If the track info is the same as the previous one, just sleep for a while and try again.
|
// 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;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -55,6 +54,6 @@ fn main() {
|
||||||
let changes = track.get_changes(&previous_track);
|
let changes = track.get_changes(&previous_track);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
sleep!(args.interval);
|
sleep!(settings.interval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
pub mod arguments;
|
pub mod settings;
|
||||||
pub mod cmus;
|
pub mod cmus;
|
||||||
|
|
||||||
/// Extracts the first embedded picture from an ID3 tag of an Audio file.
|
/// Extracts the first embedded picture from an ID3 tag of an Audio file.
|
||||||
|
|
|
@ -11,7 +11,7 @@ const DEFAULT_INTERVAL_TIME: u64 = 1000; // 1000 ms
|
||||||
|
|
||||||
#[derive(Parser, Debug, Serialize, Deserialize)]
|
#[derive(Parser, Debug, Serialize, Deserialize)]
|
||||||
#[command(author, about, version, long_about = None)]
|
#[command(author, about, version, long_about = None)]
|
||||||
pub struct Arguments {
|
pub struct Settings {
|
||||||
/// The notification timeout, in seconds
|
/// The notification timeout, in seconds
|
||||||
#[arg(short, long, default_value_t = NOTIFICATION_TIMEOUT)]
|
#[arg(short, long, default_value_t = NOTIFICATION_TIMEOUT)]
|
||||||
pub timeout: u8,
|
pub timeout: u8,
|
||||||
|
@ -150,7 +150,7 @@ pub struct Arguments {
|
||||||
pub no_use_external_lyrics: bool,
|
pub no_use_external_lyrics: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Arguments {
|
impl Default for Settings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
timeout: NOTIFICATION_TIMEOUT,
|
timeout: NOTIFICATION_TIMEOUT,
|
||||||
|
@ -178,7 +178,7 @@ impl Default for Arguments {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Arguments {
|
impl Settings {
|
||||||
pub fn load_config_and_parse_args() -> Self {
|
pub fn load_config_and_parse_args() -> Self {
|
||||||
// load config file
|
// load config file
|
||||||
let cfg: Self = match confy::load("cmus-notify", "config") {
|
let cfg: Self = match confy::load("cmus-notify", "config") {
|
||||||
|
@ -190,7 +190,7 @@ impl Arguments {
|
||||||
};
|
};
|
||||||
|
|
||||||
// parse the args
|
// parse the args
|
||||||
let mut args = Arguments::parse();
|
let mut args = Settings::parse();
|
||||||
|
|
||||||
// Combine the config and args(the args will override the config)
|
// Combine the config and args(the args will override the config)
|
||||||
if args.timeout == NOTIFICATION_TIMEOUT {
|
if args.timeout == NOTIFICATION_TIMEOUT {
|
Loading…
Reference in a new issue