Add desktop entry & notification icon hint (#822)
* Add desktop entry & notification icon hint * Fix build for non-linux * Set notification priority with hints
This commit is contained in:
@@ -88,5 +88,6 @@ It is heavily inspired by ncurses MPD clients, such as ncmpc."""
|
|||||||
license-file = ["LICENSE"]
|
license-file = ["LICENSE"]
|
||||||
assets = [
|
assets = [
|
||||||
["target/release/ncspot", "usr/bin/", "755"],
|
["target/release/ncspot", "usr/bin/", "755"],
|
||||||
|
["misc/ncspot.desktop", "usr/share/applications/", "644"],
|
||||||
["README.md", "usr/share/doc/ncspot/README.md", "644"],
|
["README.md", "usr/share/doc/ncspot/README.md", "644"],
|
||||||
]
|
]
|
||||||
|
|||||||
10
misc/ncspot.desktop
Executable file
10
misc/ncspot.desktop
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
Type=Application
|
||||||
|
Name=ncspot
|
||||||
|
Comment=Cross-platform ncurses Spotify client written in Rust
|
||||||
|
TryExec=ncspot
|
||||||
|
Exec=ncspot
|
||||||
|
Icon=ncspot
|
||||||
|
Terminal=true
|
||||||
|
Categories=AudioVideo;Audio;Player;ConsoleOnly
|
||||||
|
Keywords=spotify;music;player
|
||||||
62
src/queue.rs
62
src/queue.rs
@@ -4,7 +4,7 @@ use std::sync::{Arc, RwLock};
|
|||||||
|
|
||||||
use log::{debug, error, info};
|
use log::{debug, error, info};
|
||||||
#[cfg(feature = "notify")]
|
#[cfg(feature = "notify")]
|
||||||
use notify_rust::Notification;
|
use notify_rust::{Hint, Notification, Urgency};
|
||||||
|
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use strum_macros::Display;
|
use strum_macros::Display;
|
||||||
@@ -433,47 +433,47 @@ impl Queue {
|
|||||||
#[cfg(feature = "notify")]
|
#[cfg(feature = "notify")]
|
||||||
pub fn send_notification(
|
pub fn send_notification(
|
||||||
track_name: &str,
|
track_name: &str,
|
||||||
_cover_url: Option<String>,
|
cover_url: Option<String>,
|
||||||
notification_id: Arc<AtomicU32>,
|
notification_id: Arc<AtomicU32>,
|
||||||
) {
|
) {
|
||||||
let current_notification_id = notification_id.load(std::sync::atomic::Ordering::Relaxed);
|
let current_notification_id = notification_id.load(std::sync::atomic::Ordering::Relaxed);
|
||||||
let res = if let Some(u) = _cover_url {
|
|
||||||
// download album cover image
|
|
||||||
let path = crate::utils::cache_path_for_url(u.to_string());
|
|
||||||
|
|
||||||
|
let mut n = Notification::new();
|
||||||
|
n.appname("ncspot")
|
||||||
|
.id(current_notification_id)
|
||||||
|
.summary(track_name);
|
||||||
|
|
||||||
|
// album cover image
|
||||||
|
if let Some(u) = cover_url {
|
||||||
|
let path = crate::utils::cache_path_for_url(u.to_string());
|
||||||
if !path.exists() {
|
if !path.exists() {
|
||||||
if let Err(e) = crate::utils::download(u, path.clone()) {
|
if let Err(e) = crate::utils::download(u, path.clone()) {
|
||||||
error!("Failed to download cover: {}", e);
|
error!("Failed to download cover: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
n.icon(path.to_str().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
Notification::new()
|
// XDG desktop entry hints
|
||||||
.appname("ncspot")
|
#[cfg(all(unix, not(target_os = "macos")))]
|
||||||
.id(current_notification_id)
|
n.urgency(Urgency::Low)
|
||||||
.summary(track_name)
|
.hint(Hint::Transient(true))
|
||||||
.icon(path.to_str().unwrap())
|
.hint(Hint::DesktopEntry("ncspot".into()));
|
||||||
.show()
|
|
||||||
} else {
|
|
||||||
Notification::new()
|
|
||||||
.appname("ncspot")
|
|
||||||
.id(current_notification_id)
|
|
||||||
.summary(track_name)
|
|
||||||
.show()
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Ok(n) = res {
|
match n.show() {
|
||||||
// only available for XDG
|
Ok(_handle) => {
|
||||||
#[cfg(all(unix, not(target_os = "macos")))]
|
// only available for XDG
|
||||||
{
|
#[cfg(all(unix, not(target_os = "macos")))]
|
||||||
let new_notification_id = n.id();
|
{
|
||||||
log::debug!(
|
let new_notification_id = _handle.id();
|
||||||
"new notification id: {}, previously: {}",
|
log::debug!(
|
||||||
new_notification_id,
|
"new notification id: {}, previously: {}",
|
||||||
current_notification_id
|
new_notification_id,
|
||||||
);
|
current_notification_id
|
||||||
notification_id.store(new_notification_id, std::sync::atomic::Ordering::Relaxed);
|
);
|
||||||
|
notification_id.store(new_notification_id, std::sync::atomic::Ordering::Relaxed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if let Err(e) = res {
|
Err(e) => error!("Failed to send notification cover: {}", e),
|
||||||
error!("Failed to send notification cover: {}", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user