mod macos;
mod mixr;
use std::sync::mpsc::Receiver;
use std::time::Duration;
const POLL_INTERVAL: Duration = Duration::from_secs(3);
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct NowPlaying {
pub source: String,
pub playing: bool,
pub track: String,
pub detail: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Source {
Mixr,
Macos,
Auto,
}
pub fn poll(source: Source) -> Option<NowPlaying> {
match source {
Source::Mixr => mixr::poll(),
Source::Macos => macos::poll(),
Source::Auto => {
let m = mixr::poll();
if m.as_ref().is_some_and(|n| n.playing) {
return m;
}
let mac = macos::poll();
if mac.as_ref().is_some_and(|n| n.playing) {
return mac;
}
m.or(mac)
}
}
}
pub fn spawn_poller(source: Source) -> Receiver<Option<NowPlaying>> {
let (tx, rx) = std::sync::mpsc::channel();
std::thread::spawn(move || {
loop {
if tx.send(poll(source)).is_err() {
break; }
std::thread::sleep(POLL_INTERVAL);
}
});
rx
}