Skip to content

Commit

Permalink
Rename ChannelPayload struct to ChannelMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
catuhana committed Nov 29, 2023
1 parent 4f6fbb2 commit 41d4b1f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/channel_listener.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use rive_http::Client as RiveClient;
use tokio::sync::mpsc::UnboundedReceiver;

use crate::{config::StatusOptions, platforms::Track, rive::ClientExt, ChannelPayload};
use crate::{config::StatusOptions, platforms::Track, rive::ClientExt, ChannelMessage};

pub async fn listen(
mut rx: UnboundedReceiver<ChannelPayload>,
mut rx: UnboundedReceiver<ChannelMessage>,
rive_client: RiveClient,
status: StatusOptions,
) {
Expand All @@ -13,7 +13,7 @@ pub async fn listen(
let mut previous_track: Option<Track> = None;
while let Some(payload) = rx.recv().await {
match payload {
ChannelPayload::Track(track) => {
ChannelMessage::Track(track) => {
if previous_track == track {
continue;
};
Expand All @@ -33,7 +33,7 @@ pub async fn listen(
rive_client.set_status(status).await;
previous_track = track;
}
ChannelPayload::Exit(reset_status) => {
ChannelMessage::Exit(reset_status) => {
tracing::info!("stopping lure");

if reset_status {
Expand Down
6 changes: 3 additions & 3 deletions src/exit_handler.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use tokio::{signal, sync::mpsc::UnboundedSender};

use crate::ChannelPayload;
use crate::ChannelMessage;

pub fn handle(tx: UnboundedSender<ChannelPayload>) {
pub fn handle(tx: UnboundedSender<ChannelMessage>) {
tracing::debug!("spawning exit signal handler");

tokio::spawn(async move {
Expand All @@ -24,7 +24,7 @@ pub fn handle(tx: UnboundedSender<ChannelPayload>) {
#[cfg(windows)]
ctrl_c.await.expect("CTRL-C handler could not be created");

tx.send(ChannelPayload::Exit(true))
tx.send(ChannelMessage::Exit(true))
.expect("CTRL-C handler could not be created");
});

Expand Down
12 changes: 6 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use clap::Parser;
use confique::Config;
use rive_models::authentication::Authentication;
use tokio::sync;
use tokio::sync::mpsc;
use tracing_subscriber::EnvFilter;

mod channel_listener;
mod cli;
Expand All @@ -21,7 +22,7 @@ use crate::platforms::{Platform, Track};
use crate::rive::ClientExt;

#[derive(Clone, Debug)]
pub enum ChannelPayload {
pub enum ChannelMessage {
Track(Option<Track>),
Exit(bool),
}
Expand All @@ -30,8 +31,7 @@ pub enum ChannelPayload {
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("lure=info")),
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("lure=info")),
)
.init();

Expand All @@ -48,7 +48,7 @@ async fn main() -> anyhow::Result<()> {
}))
.load()?;

let (tx, rx) = sync::mpsc::unbounded_channel::<ChannelPayload>();
let (tx, rx) = mpsc::unbounded_channel::<ChannelMessage>();

exit_handler::handle(tx.clone());

Expand Down Expand Up @@ -106,7 +106,7 @@ async fn main() -> anyhow::Result<()> {
let rive_client =
rive_http::Client::new(Authentication::SessionToken(options.session_token));
if rive_client.ping().await.is_err() {
tx.send(ChannelPayload::Exit(false))?;
tx.send(ChannelMessage::Exit(false))?;
}

channel_listener::listen(rx, rive_client, options.status).await;
Expand Down
8 changes: 4 additions & 4 deletions src/platforms/lastfm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tokio::{sync::mpsc::UnboundedSender, time};
use super::{Platform, Track};

use crate::models::lastfm;
use crate::ChannelPayload;
use crate::ChannelMessage;

#[derive(Default)]
pub struct LastFM {
Expand All @@ -26,7 +26,7 @@ pub trait LastFMPlatform: Platform {

async fn event_loop(
self,
tx: UnboundedSender<ChannelPayload>,
tx: UnboundedSender<ChannelMessage>,
check_interval: u64,
) -> anyhow::Result<()>;
}
Expand All @@ -37,7 +37,7 @@ impl LastFMPlatform for LastFM {

async fn event_loop(
self,
tx: UnboundedSender<ChannelPayload>,
tx: UnboundedSender<ChannelMessage>,
check_interval: u64,
) -> anyhow::Result<()> {
let mut interval = time::interval(Duration::from_secs(check_interval));
Expand All @@ -46,7 +46,7 @@ impl LastFMPlatform for LastFM {

let track = self.get_current_track().await;
match track {
Ok(track) => tx.send(ChannelPayload::Track(track))?,
Ok(track) => tx.send(ChannelMessage::Track(track))?,
Err(err) => tracing::error!("Last.fm API error: {err}"),
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/platforms/listenbrainz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tokio::{sync::mpsc::UnboundedSender, time};
use super::{Platform, Track};

use crate::models::listenbrainz;
use crate::ChannelPayload;
use crate::ChannelMessage;

#[derive(Default)]
pub struct ListenBrainz {
Expand All @@ -20,7 +20,7 @@ pub struct ListenBrainz {
impl ListenBrainz {
pub async fn event_loop(
self,
tx: UnboundedSender<ChannelPayload>,
tx: UnboundedSender<ChannelMessage>,
check_interval: u64,
) -> anyhow::Result<()> {
let mut interval = time::interval(Duration::from_secs(check_interval));
Expand All @@ -29,7 +29,7 @@ impl ListenBrainz {

let track = self.get_current_track().await;
match track {
Ok(track) => tx.send(ChannelPayload::Track(track))?,
Ok(track) => tx.send(ChannelMessage::Track(track))?,
Err(err) => tracing::error!("ListenBrainz API error: {err}"),
}
}
Expand Down

0 comments on commit 41d4b1f

Please sign in to comment.