From 2130af1e4a5459b69f22b527da1dd168d44e6fae Mon Sep 17 00:00:00 2001 From: G2-Games Date: Sun, 29 Dec 2024 23:15:01 -0600 Subject: [PATCH] Added stop, various small tweaks --- dmp-core/src/music_controller/controller.rs | 6 +++ .../src/music_controller/controller_handle.rs | 8 ++++ src-tauri/src/lib.rs | 39 +++---------------- src-tauri/src/wrappers.rs | 12 +++++- src/App.css | 20 +++++++++- src/App.tsx | 11 +++--- 6 files changed, 53 insertions(+), 43 deletions(-) diff --git a/dmp-core/src/music_controller/controller.rs b/dmp-core/src/music_controller/controller.rs index c19081c..203a48c 100644 --- a/dmp-core/src/music_controller/controller.rs +++ b/dmp-core/src/music_controller/controller.rs @@ -84,6 +84,7 @@ pub enum PlayerCommand { PrevSong, Pause, Play, + Stop, Seek(i64), Enqueue(usize), SetVolume(f32), @@ -351,6 +352,11 @@ impl Controller { player_mail.send(PlayerResponse::Empty(Ok(()))).await.unwrap(); } + PlayerCommand::Stop => { + player.write().unwrap().stop(); + player_mail.send(PlayerResponse::Empty(Ok(()))).await.unwrap(); + } + PlayerCommand::Seek(time) => { let res = player.write().unwrap().seek_to(TimeDelta::milliseconds(time)); player_mail.send(PlayerResponse::Empty(res.map_err(|e| e.into()))).await.unwrap(); diff --git a/dmp-core/src/music_controller/controller_handle.rs b/dmp-core/src/music_controller/controller_handle.rs index 1b9a0f0..b60cb11 100644 --- a/dmp-core/src/music_controller/controller_handle.rs +++ b/dmp-core/src/music_controller/controller_handle.rs @@ -106,6 +106,14 @@ impl ControllerHandle { res } + pub async fn stop(&self) -> Result<(), PlayerError> { + self.player_mail.send(PlayerCommand::Stop).await.unwrap(); + let PlayerResponse::Empty(res) = self.player_mail.recv().await.unwrap() else { + unreachable!() + }; + res + } + pub async fn seek(&self, time: i64) -> Result<(), PlayerError> { self.player_mail.send(PlayerCommand::Seek(time)).await.unwrap(); let PlayerResponse::Empty(res) = self.player_mail.recv().await.unwrap() else { diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index d535c83..7478ef3 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -6,11 +6,11 @@ use crossbeam::channel::{bounded, unbounded, Receiver, Sender}; use discord_presence::{models::{Activity, ActivityButton, ActivityTimestamps, ActivityType}, Event}; use dmp_core::{config::{Config, ConfigLibrary}, music_controller::controller::{Controller, ControllerHandle, LibraryResponse, PlaybackInfo}, music_storage::library::{MusicLibrary, Song}}; use futures::channel::oneshot; -use parking_lot::lock_api::{RawRwLock, RwLock}; +use parking_lot::RwLock; use rfd::FileHandle; use tauri::{http::Response, Emitter, Manager, State, WebviewWindowBuilder, Wry}; use uuid::Uuid; -use wrappers::_Song; +use wrappers::{_Song, stop}; use crate::wrappers::{get_library, play, pause, prev, set_volume, get_song, next, get_queue, import_playlist, get_playlist, get_playlists, remove_from_queue, seek}; use commands::{add_song_to_queue, play_now, display_album_art}; @@ -97,6 +97,7 @@ pub fn run() { get_library, play, pause, + stop, set_volume, next, prev, @@ -123,7 +124,7 @@ pub fn run() { .name("PlaybackInfo handler".to_string()) .spawn(move || { let mut _info = Arc::new(RwLock::new(PlaybackInfo::default())); - let mut _now_playing: Arc>> = Arc::new(RwLock::new(None)); + let mut _now_playing = Arc::new(RwLock::new(None)); scope(|s| { let info = _info.clone(); @@ -153,36 +154,6 @@ pub fn run() { let info = _info.clone(); let now_playing = _now_playing.clone(); - s.spawn(|| { - let info = info; - let now_playing = now_playing; - let mut rpc_client = discord_presence::Client::new(std::env!("DISCORD_SECRET").parse::().unwrap()); - rpc_client.start(); - rpc_client.block_until_event(Event::Connected).unwrap(); - rpc_client.set_activity(|_| { - Activity { - state: Some("Idle".to_string()), - _type: Some(ActivityType::Listening), - buttons: vec![ActivityButton { - label: Some("Try the Player!(beta)".to_string()), - url: Some("https://github.com/Dangoware/dango-music-player".to_string()) - }], - ..Default::default() - } - }).unwrap(); - - while true { - rpc_client.set_activity(|mut a| { - if let Some(song) = now_playing.read().clone() { - - a.timestamps = info.read().duration.map(|dur| ActivityTimestamps::new().end(dur.num_milliseconds() as u64) ); - a.details = Some(format!("{} 🍡 {}" song.tags. )) - } - a - }); - } - }); - }); }).unwrap(); @@ -228,7 +199,7 @@ pub fn run() { .run(|_app_handle, event| match event { tauri::RunEvent::ExitRequested { api, .. } => { // api.prevent_exit(); - panic!("does this kill the player?") + //panic!("does this kill the player?") } _ => {} }); diff --git a/src-tauri/src/wrappers.rs b/src-tauri/src/wrappers.rs index ab877f4..ad648d6 100644 --- a/src-tauri/src/wrappers.rs +++ b/src-tauri/src/wrappers.rs @@ -2,7 +2,7 @@ use std::{collections::BTreeMap, path::PathBuf}; use chrono::{DateTime, Utc, serde::ts_milliseconds_option}; use crossbeam::channel::Sender; -use dmp_core::{music_controller::controller::{ControllerHandle, LibraryCommand, LibraryResponse, PlayerLocation, PlayerResponse, QueueCommand, QueueResponse}, music_storage::library::{Song, Tag, URI}}; +use dmp_core::{music_controller::controller::{ControllerHandle, PlayerLocation}, music_storage::library::{Song, Tag, URI}}; use itertools::Itertools; use kushi::QueueItemType; use serde::Serialize; @@ -31,7 +31,17 @@ pub async fn pause(app: AppHandle, ctrl_handle: State<'_, ControllerHandle> } Err(e) => Err(e.to_string()) } +} +#[tauri::command] +pub async fn stop(app: AppHandle, ctrl_handle: State<'_, ControllerHandle>) -> Result<(), String> { + match ctrl_handle.stop().await { + Ok(()) => { + app.emit("stop", ()).unwrap(); + Ok(()) + } + Err(e) => Err(e.to_string()) + } } #[tauri::command] diff --git a/src/App.css b/src/App.css index 09b8865..864c96c 100644 --- a/src/App.css +++ b/src/App.css @@ -52,6 +52,7 @@ main { /* Change to resize width */ width: 350px; + min-width: 350px; } .bottom { @@ -137,6 +138,9 @@ main { .bottomRight { display: flex; justify-content: space-around; + align-items: center; + color: var(--highlightTextColor); + margin-top: 14px; } button { @@ -146,14 +150,25 @@ main { width: 50px; height: 100%; margin-right: 15px; - color: #FFF; + color: var(--mediumTextColor); + cursor: pointer; } } +.playBar button:hover { + color: var(--highlightTextColor); +} + #seekBar { width: 100%; } +#timeDisplay { + font-family: monospace; + font-size: 14px; + margin: 0 20px; +} + .nowPlaying { font-size: 14pt; width: 100%; @@ -243,4 +258,5 @@ main { .unselectable { -webkit-user-select: none; user-select: none; -} \ No newline at end of file + cursor: default; +} diff --git a/src/App.tsx b/src/App.tsx index 4e2ec53..a6a405f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -304,8 +304,7 @@ function PlayBar({ playing, setPlaying }: PlayBarProps) { setPosition(_pos); setDuration(_dur); - let progress = (Math.floor((_pos/_dur)*100)); - console.log(progress + '%'); + let progress = ((_pos/_dur) * 100); setSeekBarSize(progress) }) return () => { unlisten.then((f) => f()) } @@ -341,10 +340,10 @@ function PlayBar({ playing, setPlaying }: PlayBarProps) { invoke('set_volume', { volume: volume.target.value }).then(() => {}) }} />

- { Math.round(+position / 60) }: - { (+position % 60).toString().padStart(2, "0") } / - { Math.round(+duration / 60) }: - { (+duration % 60).toString().padStart(2, "0") } + { Math.round(+position / 60).toString().padStart(2, "0") }: + { (+position % 60).toString().padStart(2, "0") }/ + { Math.round(+duration / 60).toString().padStart(2, "0") }: + { (+duration % 60).toString().padStart(2, "0") }