Fix warnings

This commit is contained in:
Henrik Friedrichsen
2022-01-09 21:20:15 +01:00
parent 75a7aed4b1
commit 68b3b9b510
9 changed files with 22 additions and 44 deletions

View File

@@ -397,10 +397,10 @@ pub fn parse(input: &str) -> Result<Vec<Command>, CommandParseError> {
} }
"seek" => { "seek" => {
if args.is_empty() { if args.is_empty() {
Err(InsufficientArgs { return Err(InsufficientArgs {
cmd: command.into(), cmd: command.into(),
hint: Some("a duration".into()), hint: Some("a duration".into()),
})?; });
} }
let arg = args.join(" "); let arg = args.join(" ");
let first_char = arg.chars().next(); let first_char = arg.chars().next();
@@ -429,9 +429,7 @@ pub fn parse(input: &str) -> Result<Vec<Command>, CommandParseError> {
}; };
let seek_direction = match first_char { let seek_direction = match first_char {
// handle i32::MAX < unsigned_millis < u32::MAX gracefully // handle i32::MAX < unsigned_millis < u32::MAX gracefully
Some('+') => { Some('+') => i32::try_from(unsigned_millis).map(SeekDirection::Relative),
i32::try_from(unsigned_millis).map(|millis| SeekDirection::Relative(millis))
}
Some('-') => i32::try_from(unsigned_millis) Some('-') => i32::try_from(unsigned_millis)
.map(|millis| SeekDirection::Relative(-millis)), .map(|millis| SeekDirection::Relative(-millis)),
_ => Ok(SeekDirection::Absolute(unsigned_millis)), _ => Ok(SeekDirection::Absolute(unsigned_millis)),
@@ -718,9 +716,11 @@ pub fn parse(input: &str) -> Result<Vec<Command>, CommandParseError> {
} }
"redraw" => Command::Redraw, "redraw" => Command::Redraw,
"exec" => Command::Execute(args.join(" ")), "exec" => Command::Execute(args.join(" ")),
_ => Err(NoSuchCommand { _ => {
cmd: command.into(), return Err(NoSuchCommand {
})?, // I'm surprised this compiles lol cmd: command.into(),
})
} // I'm surprised this compiles lol
}; };
commands.push(command); commands.push(command);
} }

View File

@@ -94,7 +94,7 @@ struct UserDataInner {
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), String> { async fn main() -> Result<(), String> {
#[cfg(not(windows))] #[cfg(not(windows))]
print!("\x1b]2;{}\x07", "ncspot"); print!("\x1b]2;ncspot\x07");
let backends = { let backends = {
let backends: Vec<&str> = audio_backend::BACKENDS.iter().map(|b| b.0).collect(); let backends: Vec<&str> = audio_backend::BACKENDS.iter().map(|b| b.0).collect();
@@ -231,7 +231,7 @@ async fn main() -> Result<(), String> {
.values() .values()
.initial_screen .initial_screen
.clone() .clone()
.unwrap_or("library".to_string()); .unwrap_or_else(|| "library".to_string());
if layout.has_screen(&initial_screen) { if layout.has_screen(&initial_screen) {
layout.set_screen(initial_screen); layout.set_screen(initial_screen);
} else { } else {

View File

@@ -61,13 +61,6 @@ impl Playable {
} }
} }
pub fn added_at(&self) -> Option<DateTime<Utc>> {
match self {
Playable::Track(track) => track.added_at,
Playable::Episode(episode) => episode.added_at,
}
}
pub fn set_added_at(&mut self, added_at: Option<DateTime<Utc>>) { pub fn set_added_at(&mut self, added_at: Option<DateTime<Utc>>) {
match self { match self {
Playable::Track(track) => track.added_at = added_at, Playable::Track(track) => track.added_at = added_at,

View File

@@ -152,12 +152,10 @@ fn get_metadata(playable: Option<Playable>, spotify: Spotify, library: Arc<Libra
Variant(Box::new( Variant(Box::new(
playable playable
.and_then(|p| p.track()) .and_then(|p| p.track())
.map( .map(|t| match library.is_saved_track(&Playable::Track(t)) {
|t| match library.is_saved_track(&Playable::Track(t.clone())) { true => 1.0,
true => 1.0, false => 0.0,
false => 0.0, })
},
)
.unwrap_or(0.0) as f64, .unwrap_or(0.0) as f64,
)), )),
); );
@@ -608,7 +606,7 @@ fn run_dbus_server(
if let Some(tracks) = &playlist.tracks { if let Some(tracks) = &playlist.tracks {
let should_shuffle = queue.get_shuffle(); let should_shuffle = queue.get_shuffle();
queue.clear(); queue.clear();
let index = queue.append_next(&tracks.iter().cloned().collect()); let index = queue.append_next(&tracks.to_vec());
queue.play(index, should_shuffle, should_shuffle) queue.play(index, should_shuffle, should_shuffle)
} }
} }
@@ -735,7 +733,6 @@ pub struct MprisManager {
tx: mpsc::Sender<MprisState>, tx: mpsc::Sender<MprisState>,
queue: Arc<Queue>, queue: Arc<Queue>,
spotify: Spotify, spotify: Spotify,
library: Arc<Library>,
} }
impl MprisManager { impl MprisManager {
@@ -750,18 +747,12 @@ impl MprisManager {
{ {
let spotify = spotify.clone(); let spotify = spotify.clone();
let queue = queue.clone(); let queue = queue.clone();
let library = library.clone();
std::thread::spawn(move || { std::thread::spawn(move || {
run_dbus_server(ev, spotify.clone(), queue.clone(), library.clone(), rx); run_dbus_server(ev, spotify.clone(), queue.clone(), library.clone(), rx);
}); });
} }
MprisManager { MprisManager { tx, queue, spotify }
tx,
queue,
spotify,
library,
}
} }
pub fn update(&self) { pub fn update(&self) {

View File

@@ -410,9 +410,9 @@ impl Queue {
} }
} }
pub fn send_notification(track_name: &str, cover_url: Option<String>) { pub fn send_notification(track_name: &str, _cover_url: Option<String>) {
#[cfg(all(feature = "notify", feature = "cover"))] #[cfg(all(feature = "notify", feature = "cover"))]
let res = if let Some(u) = cover_url { let res = if let Some(u) = _cover_url {
// download album cover image // download album cover image
let path = ui::cover::cache_path_for_url(u.to_string()); let path = ui::cover::cache_path_for_url(u.to_string());

View File

@@ -63,11 +63,7 @@ pub fn read_share() -> Option<String> {
} }
} }
} }
if let Some(s) = string { string
Some(s)
} else {
None
}
} else { } else {
//use x11 clipboard //use x11 clipboard
ClipboardProvider::new() ClipboardProvider::new()

View File

@@ -47,7 +47,6 @@ pub struct Spotify {
pub api: WebApi, pub api: WebApi,
elapsed: Arc<RwLock<Option<Duration>>>, elapsed: Arc<RwLock<Option<Duration>>>,
since: Arc<RwLock<Option<SystemTime>>>, since: Arc<RwLock<Option<SystemTime>>>,
token_issued: Arc<RwLock<Option<SystemTime>>>,
channel: Arc<RwLock<Option<mpsc::UnboundedSender<WorkerCommand>>>>, channel: Arc<RwLock<Option<mpsc::UnboundedSender<WorkerCommand>>>>,
user: Option<String>, user: Option<String>,
} }
@@ -66,7 +65,6 @@ impl Spotify {
api: WebApi::new(), api: WebApi::new(),
elapsed: Arc::new(RwLock::new(None)), elapsed: Arc::new(RwLock::new(None)),
since: Arc::new(RwLock::new(None)), since: Arc::new(RwLock::new(None)),
token_issued: Arc::new(RwLock::new(None)),
channel: Arc::new(RwLock::new(None)), channel: Arc::new(RwLock::new(None)),
user: None, user: None,
}; };

View File

@@ -39,7 +39,7 @@ enum ContextMenuAction {
SelectArtist(Vec<Artist>), SelectArtist(Vec<Artist>),
ShareUrl(String), ShareUrl(String),
AddToPlaylist(Box<Track>), AddToPlaylist(Box<Track>),
ShowRecommendations(Track), ShowRecommendations(Box<Track>),
ToggleTrackSavedStatus(Box<Track>), ToggleTrackSavedStatus(Box<Track>),
} }
@@ -167,7 +167,7 @@ impl ContextMenu {
); );
content.add_item( content.add_item(
"Similar tracks", "Similar tracks",
ContextMenuAction::ShowRecommendations(t.clone()), ContextMenuAction::ShowRecommendations(Box::new(t.clone())),
); );
content.add_item( content.add_item(
match library.is_saved_track(&Playable::Track(t.clone())) { match library.is_saved_track(&Playable::Track(t.clone())) {

View File

@@ -586,7 +586,7 @@ impl<I: ListItem + Clone> ViewExt for ListView<I> {
}; };
if let Some(mut target) = target { if let Some(mut target) = target {
let view = target.open_recommendations(queue.clone(), library.clone()); let view = target.open_recommendations(queue, library);
return match view { return match view {
Some(view) => Ok(CommandResult::View(view)), Some(view) => Ok(CommandResult::View(view)),
None => Ok(CommandResult::Consumed(None)), None => Ok(CommandResult::Consumed(None)),