From 819c31faa04b0e76885a3226cece7cd570b81d44 Mon Sep 17 00:00:00 2001 From: MrDulfin Date: Sat, 14 Dec 2024 19:17:46 -0500 Subject: [PATCH] Fixed Album art getting functionality for front end --- dmp-core/src/music_storage/library.rs | 8 +-- src-tauri/src/lib.rs | 2 +- src-tauri/src/wrappers.rs | 1 + src/App.tsx | 71 ++++++++++++++------------- 4 files changed, 42 insertions(+), 40 deletions(-) diff --git a/dmp-core/src/music_storage/library.rs b/dmp-core/src/music_storage/library.rs index de57956..299a698 100644 --- a/dmp-core/src/music_storage/library.rs +++ b/dmp-core/src/music_storage/library.rs @@ -476,14 +476,10 @@ impl Song { } pub fn album_art(&self, i: usize) -> Result, Box> { - match self.album_art[i] { + match self.album_art.get(i).unwrap() { AlbumArt::Embedded(j) => { let file = lofty::read_from_path(self.primary_uri()?.0.path())?; - if file.contains_tag_type(TagType::Id3v2) { - Ok(file.tag(TagType::Id3v2).unwrap().pictures()[j].data().to_vec()) - } else { - unimplemented!() - } + Ok(file.tag(file.primary_tag_type()).unwrap().pictures()[*j].data().to_vec()) }, AlbumArt::External(ref path) => { let mut buf = vec![]; diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 15a27e5..94f313a 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -182,7 +182,7 @@ async fn create_library( #[tauri::command] async fn lib_already_created(app: tauri::AppHandle, lib_rx: State<'_, LibRx>, handle_tx: State<'_, HandleTx>) -> Result<(), String> { println!("lib already created"); - lib_rx.inner().0.send(None); + lib_rx.inner().0.send(None).unwrap(); app.manage(handle_tx.inner().0.recv().unwrap()); Ok(()) } diff --git a/src-tauri/src/wrappers.rs b/src-tauri/src/wrappers.rs index d65b2f7..52751ed 100644 --- a/src-tauri/src/wrappers.rs +++ b/src-tauri/src/wrappers.rs @@ -51,6 +51,7 @@ pub async fn next(app: AppHandle, ctrl_handle: State<'_, ControllerHandle>, }; let _song = _Song::from(&song); art_rx.0.send(song.album_art(0).unwrap()).unwrap(); + println!("next"); app.emit("now_playing_change", _song).unwrap(); Ok(()) } diff --git a/src/App.tsx b/src/App.tsx index 9854b4f..e46abc0 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -4,26 +4,43 @@ import "./App.css"; import { Config } from "./types"; import { EventEmitter } from "@tauri-apps/plugin-shell"; import { listen } from "@tauri-apps/api/event"; +// import { fetch } from "@tauri-apps/plugin-http"; +import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow"; + +const appWindow = getCurrentWebviewWindow(); function App() { const library = useState(); - const [artwork, setArtwork] = useState(<>); - const [nowPlaying, setNowPlaying] = useState(); - listen("now_playing_change", (event) => { - console.log(event.payload); + const [nowPlaying, setNowPlaying] = useState( + } + /> + ); - setNowPlaying( ) - setArtwork( ) - }) + useEffect(() => { + const unlisten = appWindow.listen("now_playing_change", ({ event, payload }) => { + // console.log(event); + + setNowPlaying( + } + /> + ) + + }) + + return () => { unlisten.then((f) => f()) } + }, []); useEffect(() => { getConfig(); - invoke('set_volume', { volume: "1" }).then( () => {} ) }, []) return ( @@ -50,7 +67,7 @@ function getConfig(): any { if (config.libraries.libraries.length == 0) { newWindow() } else { - console.log("else"); + // console.log("else"); invoke('lib_already_created').then(() => {}) } }) @@ -80,23 +97,6 @@ interface MainViewProps { function MainView({ lib_ref }: MainViewProps) { const [library, setLibrary] = lib_ref; - // useEffect(() => { - // console.log(lib_ref); - // console.log(typeof lib_ref); - // if (typeof lib_ref.current !== "undefined") { - - // setLibrary(lib_ref.current.map((song) => { - // - // })) - // } - - // }, [lib_ref]) return (
@@ -187,11 +187,9 @@ interface NowPlayingProps { } function NowPlaying({ title, artist, album, artwork }: NowPlayingProps) { - console.log(convertFileSrc("abc")); - return (
- { artwork } + { artwork }

{ title }

{ artist }

{ album }

@@ -205,4 +203,11 @@ function Queue() { This is where the Queue be
) +} + +interface CurrentArtProps { + uuid: number, +} +function CurrentArt({uuid}: CurrentArtProps) { + return Now Playing Artwork } \ No newline at end of file