Basic notification behaviour
This commit is contained in:
parent
5b434e3621
commit
69028816e8
2 changed files with 74 additions and 85 deletions
|
@ -19,7 +19,7 @@
|
||||||
naersk-lib = pkgs.callPackage naersk { };
|
naersk-lib = pkgs.callPackage naersk { };
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
defaultPackage = naersk-lib.buildPackage rec {
|
packages.default = naersk-lib.buildPackage rec {
|
||||||
src = ./.;
|
src = ./.;
|
||||||
nativeBuildInputs = with pkgs; [
|
nativeBuildInputs = with pkgs; [
|
||||||
libnotify
|
libnotify
|
||||||
|
|
145
src/main.rs
145
src/main.rs
|
@ -1,12 +1,10 @@
|
||||||
extern crate libnotify;
|
extern crate libnotify;
|
||||||
extern crate mpd;
|
extern crate mpd;
|
||||||
|
|
||||||
use std::time::Duration;
|
|
||||||
use std::{io, usize};
|
|
||||||
|
|
||||||
use mpd::{Client, Query, Song, Term};
|
|
||||||
|
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
use libnotify::Notification;
|
||||||
|
use mpd::{Client, Query, Song, Term};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(author, version, about, long_about = "Banaan")]
|
#[command(author, version, about, long_about = "Banaan")]
|
||||||
|
@ -49,10 +47,10 @@ enum Commands {
|
||||||
///Only return the first n results
|
///Only return the first n results
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
max: Option<u32>,
|
max: Option<u32>,
|
||||||
#[arg(short, long)]
|
// #[arg(short, long)]
|
||||||
append: bool,
|
// append: bool,
|
||||||
#[arg(short, long)]
|
// #[arg(short, long)]
|
||||||
insert: Option<u32>,
|
// insert: Option<u32>,
|
||||||
},
|
},
|
||||||
/// Query database differently
|
/// Query database differently
|
||||||
Find {
|
Find {
|
||||||
|
@ -62,16 +60,21 @@ enum Commands {
|
||||||
///Only return the first n results
|
///Only return the first n results
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
max: Option<u32>,
|
max: Option<u32>,
|
||||||
|
#[arg(short, long)]
|
||||||
|
append: bool,
|
||||||
},
|
},
|
||||||
/// List items in the current queueueu
|
/// List items in the current queueueu
|
||||||
List {},
|
List {},
|
||||||
Add {
|
// Add {
|
||||||
#[arg(short, long)]
|
// #[arg(short, long)]
|
||||||
position: Option<u32>,
|
// position: Option<u32>,
|
||||||
},
|
// },
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
libnotify::init("noise").unwrap();
|
||||||
|
|
||||||
|
let n = libnotify::Notification::new("Noise", None, None);
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
let host = match cli.host {
|
let host = match cli.host {
|
||||||
|
@ -101,45 +104,41 @@ fn main() {
|
||||||
Commands::Stop {} => conn.stop().unwrap(),
|
Commands::Stop {} => conn.stop().unwrap(),
|
||||||
|
|
||||||
Commands::Toggle {} => {
|
Commands::Toggle {} => {
|
||||||
println!(
|
|
||||||
"{}",
|
|
||||||
match conn.status().unwrap().state {
|
|
||||||
mpd::State::Pause => "Resuming track...",
|
|
||||||
mpd::State::Play => "Pausing track...",
|
|
||||||
mpd::State::Stop => "Track stopped",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
conn.toggle_pause().unwrap();
|
conn.toggle_pause().unwrap();
|
||||||
let status = get_status(conn, cli.verbose);
|
let status = get_status(conn, cli.verbose, n);
|
||||||
println!("{status}");
|
println!("{status}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::Next {} => conn.next().unwrap(),
|
Commands::Next {} => {
|
||||||
|
conn.next().unwrap();
|
||||||
|
let status = get_status(conn, cli.verbose, n);
|
||||||
|
println!("{status}");
|
||||||
|
}
|
||||||
|
|
||||||
Commands::Prev {} => conn.prev().unwrap(),
|
Commands::Prev {} => {
|
||||||
|
conn.prev().unwrap();
|
||||||
|
let status = get_status(conn, cli.verbose, n);
|
||||||
|
println!("{status}");
|
||||||
|
}
|
||||||
|
|
||||||
Commands::List {} => print_songs(conn.queue().unwrap()),
|
Commands::List {} => print_songs(conn.queue().unwrap()),
|
||||||
// Commands::List {} => {
|
|
||||||
// conn.insert(first_song, usize::try_from(1).unwrap());
|
|
||||||
// println!("{:?}", conn.queue().unwrap().first());
|
|
||||||
// }
|
|
||||||
Commands::Update {} => {
|
Commands::Update {} => {
|
||||||
let thing = conn.update().unwrap();
|
let thing = conn.update().unwrap();
|
||||||
println!("{thing}")
|
println!("{thing}")
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::Current {} => {
|
Commands::Current {} => {
|
||||||
let status = get_status(conn, cli.verbose);
|
let status = get_status(conn, cli.verbose, n);
|
||||||
println!("{status}");
|
println!("{status}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::Search {
|
Commands::Search {
|
||||||
query,
|
query,
|
||||||
max,
|
max,
|
||||||
append,
|
// append,
|
||||||
insert,
|
// insert,
|
||||||
} => {
|
} => {
|
||||||
let mut result: Vec<String> = vec![];
|
|
||||||
let mut songs: Vec<Song> = vec![];
|
let mut songs: Vec<Song> = vec![];
|
||||||
let query = query.join(" ");
|
let query = query.join(" ");
|
||||||
// I want to return all results by default
|
// I want to return all results by default
|
||||||
|
@ -151,29 +150,26 @@ fn main() {
|
||||||
conn.stats().unwrap().songs
|
conn.stats().unwrap().songs
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if *append {
|
// let queue_length = conn.status().unwrap().queue_len;
|
||||||
let queue_length = conn.status().unwrap().queue_len;
|
// conn.search(&Query::new().and(Term::Any, query), window)
|
||||||
let _song = conn
|
// .unwrap()
|
||||||
.search(&Query::new().and(Term::Any, query), window)
|
// .iter()
|
||||||
.unwrap()
|
// .for_each(|x| songs.push(x.clone()));
|
||||||
.iter()
|
|
||||||
.map(|x| songs.push(x.clone()));
|
// songs.iter().rev().for_each(|x| {
|
||||||
conn.insert(
|
// conn.insert(x, usize::try_from(queue_length).unwrap())
|
||||||
songs.first().unwrap(),
|
// .unwrap();
|
||||||
usize::try_from(queue_length).unwrap(),
|
// });
|
||||||
)
|
//conn.insert(, usize::try_from(queue_length).unwrap())
|
||||||
.unwrap();
|
|
||||||
} else {
|
|
||||||
conn.search(&Query::new().and(Term::Any, query), window)
|
conn.search(&Query::new().and(Term::Any, query), window)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.for_each(|x| result.push(x.file.clone()));
|
.for_each(|x| songs.push(x.clone()));
|
||||||
result.iter().for_each(|x| println!("{x}"))
|
songs.iter().for_each(|x| println!("{}", x.file))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::Find { query, max } => {
|
Commands::Find { query, max, append } => {
|
||||||
let mut result: Vec<String> = vec![];
|
let mut songs: Vec<Song> = vec![];
|
||||||
let query = query.join(" ");
|
let query = query.join(" ");
|
||||||
let window = (
|
let window = (
|
||||||
0,
|
0,
|
||||||
|
@ -183,11 +179,15 @@ fn main() {
|
||||||
conn.stats().unwrap().songs
|
conn.stats().unwrap().songs
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
if *append {
|
||||||
|
conn.findadd(&Query::new().and(Term::Any, query)).unwrap();
|
||||||
|
} else {
|
||||||
conn.find(&Query::new().and(Term::Any, query), window)
|
conn.find(&Query::new().and(Term::Any, query), window)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.for_each(|x| result.push(x.file.clone()));
|
.for_each(|x| songs.push(x.clone()));
|
||||||
result.iter().for_each(|x| println!("{x}"))
|
songs.iter().for_each(|x| println!("{}", x.file))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::Crossfade { seconds } => {
|
Commands::Crossfade { seconds } => {
|
||||||
|
@ -200,37 +200,18 @@ fn main() {
|
||||||
println!("Crossfade disabled")
|
println!("Crossfade disabled")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} // Commands::Add { position } => {
|
||||||
|
// // insert_or_append(conn, *position);
|
||||||
Commands::Add { position } => {
|
// println!("{:?}", position);
|
||||||
// insert_or_append(conn, *position);
|
// }
|
||||||
println!("{:?}", position);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let status = get_status(conn, cli.verbose);
|
let status = get_status(conn, cli.verbose, n);
|
||||||
println!("{}", status);
|
println!("{}", &status);
|
||||||
// println!("{:?}", conn.status().unwrap());
|
|
||||||
|
|
||||||
libnotify::init("noise").unwrap();
|
|
||||||
let n = libnotify::Notification::new("Noise", None, None);
|
|
||||||
n.show().unwrap();
|
|
||||||
|
|
||||||
libnotify::uninit();
|
libnotify::uninit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stdin_reader() -> String {
|
|
||||||
"fiets".to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
// fn insert_or_append(mut client: Client, position: Option<u32>) {
|
|
||||||
// if let Some(pos) = position {
|
|
||||||
// client.insert(usize::try_from(1).unwrap(), usize::try_from(pos).unwrap());
|
|
||||||
// // let position = usize::try_from(position.unwrap()).unwrap();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
fn print_songs(songs: Vec<Song>) -> () {
|
fn print_songs(songs: Vec<Song>) -> () {
|
||||||
songs
|
songs
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -246,7 +227,7 @@ fn bts(b: bool) -> &'static str {
|
||||||
b.then(|| "on").unwrap_or("off")
|
b.then(|| "on").unwrap_or("off")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_status(mut client: Client, verbose: bool) -> String {
|
fn get_status(mut client: Client, verbose: bool, notify: Notification) -> String {
|
||||||
let status = client.status().unwrap();
|
let status = client.status().unwrap();
|
||||||
|
|
||||||
let repeat = bts(status.repeat);
|
let repeat = bts(status.repeat);
|
||||||
|
@ -269,6 +250,8 @@ fn get_status(mut client: Client, verbose: bool) -> String {
|
||||||
output.push("No song playing".to_string())
|
output.push("No song playing".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
send_notification(output.first().unwrap().clone(), notify);
|
||||||
|
|
||||||
if verbose {
|
if verbose {
|
||||||
output.push(format!(
|
output.push(format!(
|
||||||
"volume: {vol:<6} repeat: {repeat:<6} random: {rnd:<6} single: {single:<6} consume: {consume:<6}",
|
"volume: {vol:<6} repeat: {repeat:<6} random: {rnd:<6} single: {single:<6} consume: {consume:<6}",
|
||||||
|
@ -294,6 +277,12 @@ fn get_status(mut client: Client, verbose: bool) -> String {
|
||||||
output.join("\n")
|
output.join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn send_notification(body: String, notify: Notification) -> String {
|
||||||
|
let _ = notify.update("Noise", body.as_str(), None);
|
||||||
|
notify.show().unwrap();
|
||||||
|
body
|
||||||
|
}
|
||||||
|
|
||||||
fn to_mins_string(dur: Duration) -> String {
|
fn to_mins_string(dur: Duration) -> String {
|
||||||
let seconds = dur.as_secs();
|
let seconds = dur.as_secs();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue