diff --git a/src/command.rs b/src/command.rs index 4d1ef77..ce4b4c0 100644 --- a/src/command.rs +++ b/src/command.rs @@ -138,6 +138,7 @@ pub enum Command { VolumeDown(u16), Repeat(Option), Shuffle(Option), + #[cfg(feature = "share_clipboard")] Share(TargetMode), Back, Open(TargetMode), @@ -174,6 +175,7 @@ impl fmt::Display for Command { Some(b) => vec![(if *b { "on" } else { "off" }).into()], None => vec![], }, + #[cfg(feature = "share_clipboard")] Command::Share(mode) => vec![mode.to_string()], Command::Open(mode) => vec![mode.to_string()], Command::Goto(mode) => vec![mode.to_string()], @@ -243,6 +245,7 @@ impl Command { Command::VolumeDown(_) => "voldown", Command::Repeat(_) => "repeat", Command::Shuffle(_) => "shuffle", + #[cfg(feature = "share_clipboard")] Command::Share(_) => "share", Command::Back => "back", Command::Open(_) => "open", @@ -499,6 +502,7 @@ pub fn parse(input: &str) -> Result, CommandParseError> { }?; Command::Shuffle(switch) } + #[cfg(feature = "share_clipboard")] "share" => { let &target_mode_raw = args.get(0).ok_or(InsufficientArgs { cmd: command.into(), @@ -631,18 +635,18 @@ pub fn parse(input: &str) -> Result, CommandParseError> { match args.get(0).cloned() { #[cfg(feature = "share_clipboard")] Some("") | None => Ok(InsertSource::Clipboard), + // if clipboard feature is disabled and args is empty + #[cfg(not(feature = "share_clipboard"))] + None => Err(InsufficientArgs { + cmd: command.into(), + hint: Some("a Spotify URL".into()), + }), Some(url) => SpotifyUrl::from_url(url).map(InsertSource::Input).ok_or( ArgParseError { arg: url.into(), err: "Invalid Spotify URL".into(), }, ), - // if clipboard feature is disabled and args is empty - #[allow(unreachable_patterns)] - None => Err(InsufficientArgs { - cmd: command.into(), - hint: Some("a Spotify URL".into()), - }), }?; Command::Insert(insert_source) } diff --git a/src/commands.rs b/src/commands.rs index fe0a891..03f1405 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -3,8 +3,7 @@ use std::sync::Arc; use std::time::Duration; use crate::command::{ - parse, Command, GotoMode, InsertSource, JumpMode, MoveAmount, MoveMode, SeekDirection, - ShiftMode, TargetMode, + parse, Command, GotoMode, JumpMode, MoveAmount, MoveMode, SeekDirection, ShiftMode, TargetMode, }; use crate::config::Config; use crate::events::EventManager; @@ -275,7 +274,6 @@ impl CommandManager { | Command::SaveQueue | Command::Delete | Command::Focus(_) - | Command::Share(_) | Command::Back | Command::Open(_) | Command::Goto(_) @@ -288,6 +286,11 @@ impl CommandManager { "The command \"{}\" is unsupported in this view", cmd.basename() )), + #[cfg(feature = "share_clipboard")] + Command::Share(_) => Err(format!( + "The command \"{}\" is unsupported in this view", + cmd.basename() + )), } } @@ -424,8 +427,12 @@ impl CommandManager { kb.insert("r".into(), vec![Command::Repeat(None)]); kb.insert("z".into(), vec![Command::Shuffle(None)]); - kb.insert("x".into(), vec![Command::Share(TargetMode::Selected)]); - kb.insert("Shift+x".into(), vec![Command::Share(TargetMode::Current)]); + + #[cfg(feature = "share_clipboard")] + { + kb.insert("x".into(), vec![Command::Share(TargetMode::Selected)]); + kb.insert("Shift+x".into(), vec![Command::Share(TargetMode::Current)]); + } kb.insert("F1".into(), vec![Command::Focus("queue".into())]); kb.insert("F2".into(), vec![Command::Focus("search".into())]); @@ -528,7 +535,7 @@ impl CommandManager { #[cfg(feature = "share_clipboard")] kb.insert( "Ctrl+v".into(), - vec![Command::Insert(InsertSource::Clipboard)], + vec![Command::Insert(crate::command::InsertSource::Clipboard)], ); kb diff --git a/src/queue.rs b/src/queue.rs index b876f9b..84bb5f3 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -1,4 +1,5 @@ use std::cmp::Ordering; +#[cfg(feature = "notify")] use std::sync::atomic::AtomicU32; use std::sync::{Arc, RwLock}; @@ -14,9 +15,6 @@ use crate::model::playable::Playable; use crate::spotify::Spotify; use crate::{config::Config, spotify::PlayerEvent}; -#[cfg(feature = "cover")] -use crate::ui; - #[derive(Display, Clone, Copy, PartialEq, Debug, Serialize, Deserialize)] pub enum RepeatSetting { #[serde(rename = "off")] @@ -38,6 +36,7 @@ pub struct Queue { current_track: RwLock>, spotify: Spotify, cfg: Arc, + #[cfg(feature = "notify")] notification_id: Arc, } @@ -51,6 +50,7 @@ impl Queue { current_track: RwLock::new(queue_state.current_track), random_order: RwLock::new(queue_state.random_order), cfg, + #[cfg(feature = "notify")] notification_id: Arc::new(AtomicU32::new(0)), }; diff --git a/src/sharing.rs b/src/sharing.rs index 7e23a06..3779a1a 100644 --- a/src/sharing.rs +++ b/src/sharing.rs @@ -14,7 +14,7 @@ use { #[cfg(feature = "share_selection")] use clipboard::{x11_clipboard, x11_clipboard::X11ClipboardContext}; -#[cfg(feature = "share_selection")] +#[cfg(all(feature = "share_selection", feature = "wayland_clipboard"))] use wl_clipboard_rs::utils::{is_primary_selection_supported, PrimarySelectionCheckError}; #[cfg(not(feature = "share_selection"))] @@ -80,8 +80,8 @@ pub fn read_share() -> Option { #[cfg(feature = "wayland_clipboard")] { //use wayland clipboard - match is_primary_selection_supported() { - Ok(supported) => { + string = match is_primary_selection_supported() { + Ok(_supported) => { let result = get_contents( paste::ClipboardType::Primary, Seat::Unspecified, @@ -124,11 +124,7 @@ pub fn read_share() -> Option { } } } - if let Some(s) = string { - Some(s) - } else { - None - } + string } else { //use x11 clipboard ClipboardProvider::new() diff --git a/src/ui/contextmenu.rs b/src/ui/contextmenu.rs index 16bb575..2cadd50 100644 --- a/src/ui/contextmenu.rs +++ b/src/ui/contextmenu.rs @@ -43,6 +43,7 @@ enum ContextMenuAction { PlayTrack(Box), ShowItem(Box), SelectArtist(Vec), + #[cfg(feature = "share_clipboard")] ShareUrl(String), AddToPlaylist(Box), ShowRecommendations(Box), @@ -183,13 +184,14 @@ impl ContextMenu { if let Some(a) = item.album(queue.clone()) { content.add_item("Show album", ContextMenuAction::ShowItem(Box::new(a))); } - if let Some(url) = item.share_url() { - #[cfg(feature = "share_clipboard")] - content.add_item("Share", ContextMenuAction::ShareUrl(url)); - } - if let Some(url) = item.album(queue.clone()).and_then(|a| a.share_url()) { - #[cfg(feature = "share_clipboard")] - content.add_item("Share album", ContextMenuAction::ShareUrl(url)); + #[cfg(feature = "share_clipboard")] + { + if let Some(url) = item.share_url() { + content.add_item("Share", ContextMenuAction::ShareUrl(url)); + } + if let Some(url) = item.album(queue.clone()).and_then(|a| a.share_url()) { + content.add_item("Share album", ContextMenuAction::ShareUrl(url)); + } } if let Some(t) = item.track() { content.insert_item( @@ -232,8 +234,8 @@ impl ContextMenu { s.call_on_name("main", move |v: &mut Layout| v.push_view(view)); } } + #[cfg(feature = "share_clipboard")] ContextMenuAction::ShareUrl(url) => { - #[cfg(feature = "share_clipboard")] write_share(url.to_string()); } ContextMenuAction::AddToPlaylist(track) => { diff --git a/src/ui/cover.rs b/src/ui/cover.rs index 4cd7940..e0ef4d2 100644 --- a/src/ui/cover.rs +++ b/src/ui/cover.rs @@ -1,5 +1,4 @@ use std::collections::HashSet; -use std::fs::File; use std::io::Write; use std::path::PathBuf; use std::process::{Child, Stdio}; @@ -240,6 +239,7 @@ impl ViewExt for CoverView { track.unsave(self.library.clone()); } } + #[cfg(feature = "share_clipboard")] Command::Share(_mode) => { let url = self .queue @@ -247,7 +247,6 @@ impl ViewExt for CoverView { .and_then(|t| t.as_listitem().share_url()); if let Some(url) = url { - #[cfg(feature = "share_clipboard")] crate::sharing::write_share(url); } diff --git a/src/ui/listview.rs b/src/ui/listview.rs index 6b5e3f7..0e69020 100644 --- a/src/ui/listview.rs +++ b/src/ui/listview.rs @@ -24,12 +24,12 @@ use crate::model::track::Track; use crate::queue::Queue; #[cfg(feature = "share_clipboard")] use crate::sharing::{read_share, write_share}; +use crate::spotify::UriType; use crate::traits::{IntoBoxedViewExt, ListItem, ViewExt}; use crate::ui::album::AlbumView; use crate::ui::artist::ArtistView; use crate::ui::contextmenu::ContextMenu; use crate::ui::pagination::Pagination; -use crate::{spotify::UriType, spotify_url::SpotifyUrl}; pub struct ListView { content: Arc>>, @@ -400,6 +400,7 @@ impl ViewExt for ListView { return Ok(CommandResult::Consumed(None)); } + #[cfg(feature = "share_clipboard")] Command::Share(mode) => { let url = match mode { TargetMode::Selected => self.content.read().ok().and_then(|content| { @@ -412,7 +413,6 @@ impl ViewExt for ListView { }; if let Some(url) = url { - #[cfg(feature = "share_clipboard")] write_share(url); } @@ -550,7 +550,9 @@ impl ViewExt for ListView { let url = match source { InsertSource::Input(url) => Some(url.clone()), #[cfg(feature = "share_clipboard")] - InsertSource::Clipboard => read_share().and_then(SpotifyUrl::from_url), + InsertSource::Clipboard => { + read_share().and_then(crate::spotify_url::SpotifyUrl::from_url) + } }; let spotify = self.queue.get_spotify(); diff --git a/src/utils.rs b/src/utils.rs index ac5c1c3..1fdc811 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,3 +1,5 @@ +#![allow(dead_code)] + /// Returns a human readable String of a Duration /// /// Example: `3h 12m 53s`