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