mirror of
https://github.com/Dangoware/dango-music-player.git
synced 2025-04-19 10:02:53 -05:00
Updated save path for library
This commit is contained in:
parent
6b3ac348ac
commit
f88d50c720
9 changed files with 30 additions and 41 deletions
|
@ -29,11 +29,11 @@ impl Default for ConfigLibrary {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConfigLibrary {
|
impl ConfigLibrary {
|
||||||
pub fn new(path: PathBuf, name: String, scan_folders: Option<Vec<PathBuf>>) -> Self {
|
pub fn new(path: PathBuf, name: String, scan_folders: Option<Vec<PathBuf>>, uuid: Option<Uuid>) -> Self {
|
||||||
ConfigLibrary {
|
ConfigLibrary {
|
||||||
name,
|
name,
|
||||||
path,
|
path,
|
||||||
uuid: Uuid::new_v4(),
|
uuid: uuid.unwrap_or(Uuid::new_v4()),
|
||||||
scan_folders,
|
scan_folders,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,6 +197,7 @@ pub mod tests {
|
||||||
PathBuf::from("test-config/library"),
|
PathBuf::from("test-config/library"),
|
||||||
String::from("library"),
|
String::from("library"),
|
||||||
None,
|
None,
|
||||||
|
None
|
||||||
);
|
);
|
||||||
let mut config = Config {
|
let mut config = Config {
|
||||||
path: PathBuf::from("test-config/config_test.json"),
|
path: PathBuf::from("test-config/config_test.json"),
|
||||||
|
|
|
@ -312,22 +312,9 @@ impl Controller {
|
||||||
if let Ok(mail) = _mail {
|
if let Ok(mail) = _mail {
|
||||||
match mail {
|
match mail {
|
||||||
PlayerCommand::Play => {
|
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.write().unwrap().play();
|
||||||
player_mail.send(PlayerResponse::Empty).await.unwrap();
|
player_mail.send(PlayerResponse::Empty).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
PlayerCommand::Pause => {
|
PlayerCommand::Pause => {
|
||||||
player.write().unwrap().pause();
|
player.write().unwrap().pause();
|
||||||
player_mail.send(PlayerResponse::Empty).await.unwrap();
|
player_mail.send(PlayerResponse::Empty).await.unwrap();
|
||||||
|
@ -350,6 +337,7 @@ impl Controller {
|
||||||
};
|
};
|
||||||
|
|
||||||
let prism_uri = prismriver::utils::path_to_uri(&uri.as_path().unwrap()).unwrap();
|
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().load_new(&prism_uri).unwrap();
|
||||||
player.write().unwrap().play();
|
player.write().unwrap().play();
|
||||||
|
|
||||||
|
|
|
@ -351,6 +351,7 @@ mod tests {
|
||||||
PathBuf::from("test-config/library2"),
|
PathBuf::from("test-config/library2"),
|
||||||
String::from("library2"),
|
String::from("library2"),
|
||||||
None,
|
None,
|
||||||
|
None
|
||||||
);
|
);
|
||||||
config.libraries.libraries.push(config_lib.clone());
|
config.libraries.libraries.push(config_lib.clone());
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use ciborium::{from_reader, into_writer};
|
||||||
use deunicode::deunicode_with_tofu;
|
use deunicode::deunicode_with_tofu;
|
||||||
use file_format::{FileFormat, Kind};
|
use file_format::{FileFormat, Kind};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File, OpenOptions};
|
||||||
use std::io::{BufReader, BufWriter};
|
use std::io::{BufReader, BufWriter};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
@ -53,7 +53,7 @@ pub(super) fn read_file<T: for<'de> serde::Deserialize<'de>>(
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
) -> Result<T, Box<dyn Error>> {
|
) -> Result<T, Box<dyn Error>> {
|
||||||
// Create a new snap reader over the file
|
// 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);
|
//let mut d = snap::read::FrameDecoder::new(file_reader);
|
||||||
|
|
||||||
// Decode the library from the serialized data into the vec
|
// Decode the library from the serialized data into the vec
|
||||||
|
|
|
@ -196,7 +196,7 @@ impl<
|
||||||
|
|
||||||
let empty = self.items.is_empty();
|
let empty = self.items.is_empty();
|
||||||
if !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();
|
let len = items.len();
|
||||||
|
|
|
@ -22,22 +22,26 @@ pub fn run() {
|
||||||
let controller_thread = spawn(move || {
|
let controller_thread = spawn(move || {
|
||||||
let mut config = { tx.recv().unwrap() } ;
|
let mut config = { tx.recv().unwrap() } ;
|
||||||
let scan_path = { lib_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(
|
let mut library = MusicLibrary::init(
|
||||||
save_path.clone(),
|
save_path.clone(),
|
||||||
if let Ok(lib) = config.libraries.get_default() {
|
_lib.uuid
|
||||||
lib.uuid
|
|
||||||
} else {
|
|
||||||
Uuid::new_v4()
|
|
||||||
}
|
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
let scan_path = scan_path.unwrap_or_else(|| config.libraries.get_default().unwrap().scan_folders.as_ref().unwrap()[0].clone());
|
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() {
|
if config.libraries.get_default().is_err() {
|
||||||
library.scan_folder(&scan_path).unwrap();
|
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() {
|
if library.library.is_empty() {
|
||||||
println!("library is empty");
|
println!("library is empty");
|
||||||
|
@ -132,7 +136,6 @@ struct HandleTx(Receiver<ControllerHandle>);
|
||||||
async fn get_config(state: State<'_, ConfigRx>) -> Result<Config, String> {
|
async fn get_config(state: State<'_, ConfigRx>) -> Result<Config, String> {
|
||||||
if let Some(dir) = directories::ProjectDirs::from("", "Dangoware", "dmp") {
|
if let Some(dir) = directories::ProjectDirs::from("", "Dangoware", "dmp") {
|
||||||
let path = dir.config_dir();
|
let path = dir.config_dir();
|
||||||
// dbg!(&path);
|
|
||||||
fs::create_dir_all(path).or_else(|err| {
|
fs::create_dir_all(path).or_else(|err| {
|
||||||
if err.kind() == std::io::ErrorKind::AlreadyExists {
|
if err.kind() == std::io::ErrorKind::AlreadyExists {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -141,8 +144,6 @@ async fn get_config(state: State<'_, ConfigRx>) -> Result<Config, String> {
|
||||||
}
|
}
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
|
||||||
// dbg!(&dir);
|
|
||||||
|
|
||||||
let config = if let Ok(mut c) = Config::read_file(PathBuf::from(path).join("config")) {
|
let config = if let Ok(mut c) = Config::read_file(PathBuf::from(path).join("config")) {
|
||||||
if c.state_path == PathBuf::default() {
|
if c.state_path == PathBuf::default() {
|
||||||
c.state_path = PathBuf::from(path).join("state");
|
c.state_path = PathBuf::from(path).join("state");
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "Dango Music Player",
|
"productName": "Dango Music Player",
|
||||||
"mainBinaryName": "DMP",
|
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"identifier": "com.dango-music-player.app",
|
"identifier": "com.dango-music-player.app",
|
||||||
"build": {
|
"build": {
|
||||||
|
|
17
src/App.tsx
17
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 { convertFileSrc, invoke } from "@tauri-apps/api/core";
|
||||||
import "./App.css";
|
import "./App.css";
|
||||||
import { Config } from "./types";
|
import { Config } from "./types";
|
||||||
import { EventEmitter } from "@tauri-apps/plugin-shell";
|
// import { EventEmitter } from "@tauri-apps/plugin-shell";
|
||||||
import { listen } from "@tauri-apps/api/event";
|
// import { listen } from "@tauri-apps/api/event";
|
||||||
// import { fetch } from "@tauri-apps/plugin-http";
|
// import { fetch } from "@tauri-apps/plugin-http";
|
||||||
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ function App() {
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const unlisten = appWindow.listen<any>("now_playing_change", ({ event, payload }) => {
|
const unlisten = appWindow.listen<any>("now_playing_change", ({ payload, }) => {
|
||||||
// console.log(event);
|
// console.log(event);
|
||||||
setNowPlaying(
|
setNowPlaying(
|
||||||
<NowPlaying
|
<NowPlaying
|
||||||
|
@ -80,7 +80,7 @@ function App() {
|
||||||
</div>
|
</div>
|
||||||
<div className="rightSide">
|
<div className="rightSide">
|
||||||
{ nowPlaying }
|
{ nowPlaying }
|
||||||
<Queue songs={ queue } setSongs={ setQueue } />
|
<Queue songs={ queue } />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
|
@ -201,8 +201,6 @@ function MainView({ lib_ref, viewName }: MainViewProps) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const unlisten = appWindow.listen<any>("library_loaded", (_) => {
|
const unlisten = appWindow.listen<any>("library_loaded", (_) => {
|
||||||
console.log("library_loaded");
|
console.log("library_loaded");
|
||||||
invoke('get_playlists').then(() => {})
|
|
||||||
|
|
||||||
invoke('get_library').then((lib) => {
|
invoke('get_library').then((lib) => {
|
||||||
setLibrary([...(lib as any[]).map((song) => {
|
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()) }
|
return () => { unlisten.then((f) => f()) }
|
||||||
}, []);
|
}, []);
|
||||||
|
@ -313,9 +313,8 @@ function NowPlaying({ title, artist, album, artwork }: NowPlayingProps) {
|
||||||
|
|
||||||
interface QueueProps {
|
interface QueueProps {
|
||||||
songs: JSX.Element[],
|
songs: JSX.Element[],
|
||||||
setSongs: React.Dispatch<React.SetStateAction<JSX.Element[]>>
|
|
||||||
}
|
}
|
||||||
function Queue({ songs, setSongs }: QueueProps) {
|
function Queue({ songs }: QueueProps) {
|
||||||
return (
|
return (
|
||||||
<section className="Queue">
|
<section className="Queue">
|
||||||
{ songs }
|
{ songs }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { StrictMode } from "react";
|
import { StrictMode } from "react";
|
||||||
import ReactDOM from "react-dom/client";
|
import ReactDOM from "react-dom/client";
|
||||||
import App from "./App";
|
import App from "./App";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue