diff --git a/dmp-core/src/config/mod.rs b/dmp-core/src/config/mod.rs index 7e1f8b7..8a12053 100644 --- a/dmp-core/src/config/mod.rs +++ b/dmp-core/src/config/mod.rs @@ -29,11 +29,11 @@ impl Default for ConfigLibrary { } impl ConfigLibrary { - pub fn new(path: PathBuf, name: String, scan_folders: Option>) -> Self { + pub fn new(path: PathBuf, name: String, scan_folders: Option>, uuid: Option) -> Self { ConfigLibrary { name, path, - uuid: Uuid::new_v4(), + uuid: uuid.unwrap_or(Uuid::new_v4()), scan_folders, } } @@ -197,6 +197,7 @@ pub mod tests { PathBuf::from("test-config/library"), String::from("library"), None, + None ); let mut config = Config { path: PathBuf::from("test-config/config_test.json"), diff --git a/dmp-core/src/music_controller/controller.rs b/dmp-core/src/music_controller/controller.rs index 3a7e56f..88baf35 100644 --- a/dmp-core/src/music_controller/controller.rs +++ b/dmp-core/src/music_controller/controller.rs @@ -312,21 +312,8 @@ impl Controller { if let Ok(mail) = _mail { match mail { PlayerCommand::Play => { - if first { - queue_mail.send(QueueCommand::NowPlaying).await.unwrap(); - let QueueResponse::Item(item) = queue_mail.recv().await.unwrap() else { unimplemented!() }; - let QueueItemType::Single(song) = item.item else { unimplemented!("This is temporary, handle queueItemTypes at some point") }; - - let prism_uri = prismriver::utils::path_to_uri(&song.song.primary_uri().unwrap().0.as_path().unwrap()).unwrap(); - player.write().unwrap().load_new(&prism_uri).unwrap(); - player.write().unwrap().play(); - - player_mail.send(PlayerResponse::NowPlaying(song.song)).await.unwrap(); - first = false - } else { - player.write().unwrap().play(); - player_mail.send(PlayerResponse::Empty).await.unwrap(); - } + player.write().unwrap().play(); + player_mail.send(PlayerResponse::Empty).await.unwrap(); } PlayerCommand::Pause => { player.write().unwrap().pause(); @@ -350,6 +337,7 @@ impl Controller { }; let prism_uri = prismriver::utils::path_to_uri(&uri.as_path().unwrap()).unwrap(); + println!("Playing song at path: {:?}", prism_uri); player.write().unwrap().load_new(&prism_uri).unwrap(); player.write().unwrap().play(); diff --git a/dmp-core/src/music_storage/db_reader/itunes/reader.rs b/dmp-core/src/music_storage/db_reader/itunes/reader.rs index d70496e..1941ec5 100644 --- a/dmp-core/src/music_storage/db_reader/itunes/reader.rs +++ b/dmp-core/src/music_storage/db_reader/itunes/reader.rs @@ -351,6 +351,7 @@ mod tests { PathBuf::from("test-config/library2"), String::from("library2"), None, + None ); config.libraries.libraries.push(config_lib.clone()); diff --git a/dmp-core/src/music_storage/utils.rs b/dmp-core/src/music_storage/utils.rs index a91299d..b9e1d69 100644 --- a/dmp-core/src/music_storage/utils.rs +++ b/dmp-core/src/music_storage/utils.rs @@ -2,7 +2,7 @@ use ciborium::{from_reader, into_writer}; use deunicode::deunicode_with_tofu; use file_format::{FileFormat, Kind}; use std::error::Error; -use std::fs::{self, File}; +use std::fs::{self, File, OpenOptions}; use std::io::{BufReader, BufWriter}; use std::path::{Path, PathBuf}; use walkdir::WalkDir; @@ -53,7 +53,7 @@ pub(super) fn read_file serde::Deserialize<'de>>( path: PathBuf, ) -> Result> { // Create a new snap reader over the file - let file_reader = BufReader::new(File::open(path)?); + let file_reader = BufReader::new(OpenOptions::new().read(true).open(path)?); //let mut d = snap::read::FrameDecoder::new(file_reader); // Decode the library from the serialized data into the vec diff --git a/kushi-queue/src/lib.rs b/kushi-queue/src/lib.rs index 5d5b1ef..0562540 100644 --- a/kushi-queue/src/lib.rs +++ b/kushi-queue/src/lib.rs @@ -196,7 +196,7 @@ impl< let empty = self.items.is_empty(); if !empty { - self.items.get_mut(i).expect("There should be an item at index {i}").state == QueueState::NoState; + self.items.get_mut(i).expect("There should be an item at index {i}").state = QueueState::NoState; } let len = items.len(); diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 5147b00..faadca1 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -22,22 +22,26 @@ pub fn run() { let controller_thread = spawn(move || { let mut config = { tx.recv().unwrap() } ; let scan_path = { lib_tx.recv().unwrap() }; - let save_path = dbg!(config.libraries.library_folder.join("library.dlib")); + let _temp_config = ConfigLibrary::default(); + let _lib = config.libraries.get_default().unwrap_or(&_temp_config); + + let save_path = if _lib.path == PathBuf::default() { + scan_path.as_ref().unwrap().clone().canonicalize().unwrap().join("library.dlib") + } else { + _lib.path.clone() + }; + println!("save_path: {}\nscan_path:{scan_path:?}", save_path.display()); let mut library = MusicLibrary::init( save_path.clone(), - if let Ok(lib) = config.libraries.get_default() { - lib.uuid - } else { - Uuid::new_v4() - } + _lib.uuid ).unwrap(); let scan_path = scan_path.unwrap_or_else(|| config.libraries.get_default().unwrap().scan_folders.as_ref().unwrap()[0].clone()); if config.libraries.get_default().is_err() { library.scan_folder(&scan_path).unwrap(); - config.push_library( ConfigLibrary::new(save_path.clone(), String::from("Library"), Some(vec![scan_path.clone()]))); + config.push_library( ConfigLibrary::new(save_path.clone(), String::from("Library"), Some(vec![scan_path.clone()]), Some(library.uuid))); } if library.library.is_empty() { println!("library is empty"); @@ -132,7 +136,6 @@ struct HandleTx(Receiver); async fn get_config(state: State<'_, ConfigRx>) -> Result { if let Some(dir) = directories::ProjectDirs::from("", "Dangoware", "dmp") { let path = dir.config_dir(); - // dbg!(&path); fs::create_dir_all(path).or_else(|err| { if err.kind() == std::io::ErrorKind::AlreadyExists { Ok(()) @@ -141,8 +144,6 @@ async fn get_config(state: State<'_, ConfigRx>) -> Result { } }).unwrap(); - // dbg!(&dir); - let config = if let Ok(mut c) = Config::read_file(PathBuf::from(path).join("config")) { if c.state_path == PathBuf::default() { c.state_path = PathBuf::from(path).join("state"); diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index ae2c4d3..caddea4 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,6 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "Dango Music Player", - "mainBinaryName": "DMP", "version": "0.0.1", "identifier": "com.dango-music-player.app", "build": { diff --git a/src/App.tsx b/src/App.tsx index aac11da..ef847b3 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,9 +1,9 @@ -import { useEffect, useRef, useState } from "react"; +import { useEffect, useState } from "react"; import { convertFileSrc, invoke } from "@tauri-apps/api/core"; import "./App.css"; import { Config } from "./types"; -import { EventEmitter } from "@tauri-apps/plugin-shell"; -import { listen } from "@tauri-apps/api/event"; +// 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"; @@ -26,7 +26,7 @@ function App() { ); useEffect(() => { - const unlisten = appWindow.listen("now_playing_change", ({ event, payload }) => { + const unlisten = appWindow.listen("now_playing_change", ({ payload, }) => { // console.log(event); setNowPlaying(
{ nowPlaying } - +
@@ -201,8 +201,6 @@ function MainView({ lib_ref, viewName }: MainViewProps) { useEffect(() => { const unlisten = appWindow.listen("library_loaded", (_) => { console.log("library_loaded"); - invoke('get_playlists').then(() => {}) - invoke('get_library').then((lib) => { setLibrary([...(lib as any[]).map((song) => { @@ -219,6 +217,8 @@ function MainView({ lib_ref, viewName }: MainViewProps) { ) })]) }) + + invoke('get_playlists').then(() => {}) }) return () => { unlisten.then((f) => f()) } }, []); @@ -313,9 +313,8 @@ function NowPlaying({ title, artist, album, artwork }: NowPlayingProps) { interface QueueProps { songs: JSX.Element[], - setSongs: React.Dispatch> } -function Queue({ songs, setSongs }: QueueProps) { +function Queue({ songs }: QueueProps) { return (
{ songs } diff --git a/src/main.tsx b/src/main.tsx index 37ea778..09a651b 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,4 +1,4 @@ -import React, { StrictMode } from "react"; +import { StrictMode } from "react"; import ReactDOM from "react-dom/client"; import App from "./App";