Release
This commit is contained in:
+94
-79
@@ -187,50 +187,6 @@ impl App {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn play(&mut self) {
|
||||
let file = File::open(self.songs[self.list_state.selected().expect("None")].clone()).unwrap();
|
||||
let source = Decoder::new(BufReader::new(file)).unwrap();
|
||||
|
||||
if self.player.empty() {
|
||||
self.player.append(source);
|
||||
} else {
|
||||
self.player.stop();
|
||||
self.player.append(source);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
pub fn play(&mut self) {
|
||||
if !self.queue.is_empty() {
|
||||
for _i in 0..self.queue.len() {
|
||||
let file = File::open(
|
||||
self.library.songs[*self.queue.front().expect("None")]
|
||||
.path
|
||||
.clone(),
|
||||
)
|
||||
.unwrap();
|
||||
let source = Decoder::new(BufReader::new(file)).unwrap();
|
||||
self.queue.pop_front();
|
||||
self.player.append(source);
|
||||
}
|
||||
} else {
|
||||
let file = File::open(
|
||||
self.library.songs[self.artist_state.selected().expect("None")]
|
||||
.path
|
||||
.clone(),
|
||||
)
|
||||
.unwrap();
|
||||
let source = Decoder::new(BufReader::new(file)).unwrap();
|
||||
if self.player.empty() {
|
||||
self.player.append(source);
|
||||
} else {
|
||||
self.player.stop();
|
||||
self.player.append(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn play_song(&mut self, index: usize) {
|
||||
let song_indexes = self.current_selected_song();
|
||||
let song_index = song_indexes[index];
|
||||
@@ -256,52 +212,72 @@ impl App {
|
||||
song_indexes.to_owned()
|
||||
}
|
||||
|
||||
// pub fn play_pause(&mut self) {
|
||||
// if self.current_song().is_some() {
|
||||
// let song = &self.library.songs[self.current_song.unwrap()];
|
||||
// let duration = song.duration.unwrap_or(1.0) as i64;
|
||||
// let artist = &song.artist;
|
||||
// if let Some(client) = self.discord_client.as_mut() {
|
||||
// if !self.player.is_paused() {
|
||||
// self.player.pause();
|
||||
// self.paused_at = self.player.get_pos().as_secs() as i64;
|
||||
//
|
||||
// let asset = Assets::new();
|
||||
// let activity = activity::Activity::new()
|
||||
// .name("NCMPRS")
|
||||
// .details(song.title.clone())
|
||||
// .state("Paused")
|
||||
// .activity_type(activity::ActivityType::Listening)
|
||||
// .assets(asset.large_image("https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/navidrome.png"));
|
||||
// let _ = client.set_activity(activity);
|
||||
// } else if self.player.is_paused() {
|
||||
// self.player.play();
|
||||
// let now = SystemTime::now()
|
||||
// .duration_since(UNIX_EPOCH)
|
||||
// .unwrap()
|
||||
// .as_secs() as i64;
|
||||
// let timestamps = Timestamps::new()
|
||||
// .start(now - self.paused_at)
|
||||
// .end((now - self.paused_at) + duration);
|
||||
// let asset = Assets::new();
|
||||
//
|
||||
// let payload = activity::Activity::new()
|
||||
// .name("NCMPRS")
|
||||
// .details(song.title.clone())
|
||||
// .state(artist)
|
||||
// .activity_type(activity::ActivityType::Listening)
|
||||
// .timestamps(timestamps)
|
||||
// .assets(asset.large_image("https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/navidrome.png"));
|
||||
//
|
||||
// let _ = client.set_activity(payload);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn play_pause(&mut self) {
|
||||
if self.current_song().is_some() {
|
||||
let song = &self.library.songs[self.current_song.unwrap()];
|
||||
let song_idx = match self.current_song {
|
||||
Some(idx) => idx,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let song = &self.library.songs[song_idx];
|
||||
let duration = song.duration.unwrap_or(1.0) as i64;
|
||||
let artist = &song.artist;
|
||||
if let Some(client) = self.discord_client.as_mut() {
|
||||
let title = song.title.clone();
|
||||
let artist = song.artist.clone();
|
||||
|
||||
if !self.player.is_paused() {
|
||||
self.player.pause();
|
||||
self.paused_at = self.player.get_pos().as_secs() as i64;
|
||||
|
||||
let asset = Assets::new();
|
||||
let activity = activity::Activity::new()
|
||||
.name("NCMPRS")
|
||||
.details(song.title.clone())
|
||||
.state("Paused")
|
||||
.activity_type(activity::ActivityType::Listening)
|
||||
.assets(asset.large_image("https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/navidrome.png"));
|
||||
let _ = client.set_activity(activity);
|
||||
} else if self.player.is_paused() {
|
||||
self.update_discord_rpc(true, title, artist, duration);
|
||||
} else {
|
||||
self.player.play();
|
||||
let now = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs() as i64;
|
||||
let timestamps = Timestamps::new()
|
||||
.start(now - self.paused_at)
|
||||
.end((now - self.paused_at) + duration);
|
||||
let asset = Assets::new();
|
||||
|
||||
let payload = activity::Activity::new()
|
||||
.name("NCMPRS")
|
||||
.details(song.title.clone())
|
||||
.state(artist)
|
||||
.activity_type(activity::ActivityType::Listening)
|
||||
.timestamps(timestamps)
|
||||
.assets(asset.large_image("https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/navidrome.png"));
|
||||
|
||||
let _ = client.set_activity(payload);
|
||||
}
|
||||
}
|
||||
self.update_discord_rpc(false, title, artist, duration);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inc_volume(&mut self) {
|
||||
let vol = self.player.volume();
|
||||
//self.player.set_volume(self.player.volume() + 0.1);
|
||||
if vol >= 1.0 {
|
||||
self.player.set_volume(1.0);
|
||||
} else {
|
||||
@@ -398,6 +374,45 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
fn update_discord_rpc(
|
||||
&mut self,
|
||||
is_paused: bool,
|
||||
title: String,
|
||||
artist: String,
|
||||
duration: i64,
|
||||
) {
|
||||
let client = match self.discord_client.as_mut() {
|
||||
Some(c) => c,
|
||||
None => return,
|
||||
};
|
||||
|
||||
let mut activity = activity::Activity::new()
|
||||
.name("NCMPRS")
|
||||
.details(title)
|
||||
.activity_type(activity::ActivityType::Listening)
|
||||
.assets(Assets::new().large_image(
|
||||
"https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/navidrome.png",
|
||||
));
|
||||
|
||||
if is_paused {
|
||||
activity = activity.state("Paused");
|
||||
} else {
|
||||
let now = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs() as i64;
|
||||
let start_time = now - self.paused_at;
|
||||
|
||||
activity = activity.state(artist).timestamps(
|
||||
Timestamps::new()
|
||||
.start(start_time)
|
||||
.end(start_time + duration),
|
||||
);
|
||||
}
|
||||
|
||||
let _ = client.set_activity(activity);
|
||||
}
|
||||
|
||||
/// Handles the tick event of the terminal.
|
||||
///
|
||||
/// The tick event is where you can update the state of your application with any logic that
|
||||
|
||||
Reference in New Issue
Block a user