Updated the create a library dialogue

This commit is contained in:
MrDulfin 2024-12-28 13:54:18 -05:00
parent 4ad55a3f9b
commit 280a17788b
2 changed files with 16 additions and 34 deletions

View file

@ -2,6 +2,7 @@ use std::{fs, path::PathBuf, str::FromStr, thread::spawn};
use crossbeam::channel::{unbounded, Receiver, Sender}; use crossbeam::channel::{unbounded, Receiver, Sender};
use dmp_core::{config::{Config, ConfigLibrary}, music_controller::controller::{Controller, ControllerHandle, LibraryResponse}, music_storage::library::MusicLibrary}; use dmp_core::{config::{Config, ConfigLibrary}, music_controller::controller::{Controller, ControllerHandle, LibraryResponse}, music_storage::library::MusicLibrary};
use rfd::FileHandle;
use tauri::{http::Response, Emitter, Manager, State, WebviewWindowBuilder, Wry}; use tauri::{http::Response, Emitter, Manager, State, WebviewWindowBuilder, Wry};
use uuid::Uuid; use uuid::Uuid;
@ -66,8 +67,7 @@ pub fn run() {
.plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![ .invoke_handler(tauri::generate_handler![
get_config, get_config,
new_library_window, create_new_library,
create_library,
get_library, get_library,
play, play,
pause, pause,
@ -126,11 +126,11 @@ pub fn run() {
app app
.run(|_app_handle, event| match event { .run(|_app_handle, event| match event {
tauri::RunEvent::ExitRequested { api, .. } => { tauri::RunEvent::ExitRequested { api, .. } => {
api.prevent_exit(); // api.prevent_exit();
panic!("does this kill the player?")
} }
_ => {} _ => {}
}); });
std::mem::drop(controller_thread)
} }
struct ConfigRx(Sender<Config>); struct ConfigRx(Sender<Config>);
@ -175,31 +175,19 @@ async fn get_config(state: State<'_, ConfigRx>) -> Result<Config, String> {
} }
#[tauri::command] #[tauri::command]
async fn new_library_window(app: tauri::AppHandle<Wry>) -> Result<(), String> { async fn create_new_library(
WebviewWindowBuilder::new(
&app,
"library_create",
tauri::WebviewUrl::App(PathBuf::from_str("/src/create_library_window/index.html").unwrap())
).title("Create a Library")
.focused(true)
.maximizable(false)
.build()
.unwrap();
Ok(())
}
#[tauri::command]
async fn create_library(
app: tauri::AppHandle<Wry>, app: tauri::AppHandle<Wry>,
lib_rx: State<'_, LibRx>, lib_rx: State<'_, LibRx>,
handle_tx: State<'_, HandleTx>, handle_tx: State<'_, HandleTx>,
window: tauri::Window<Wry>,
path: String
) -> Result<(), String> { ) -> Result<(), String> {
println!("{path}"); let dir = rfd::AsyncFileDialog::new()
let path = PathBuf::from(path.trim().trim_matches('"')); .set_title("Pick a library path")
.pick_folder()
.await
.unwrap();
let path = dir.path().canonicalize().unwrap();
println!("{}", path.display());
if !path.exists() { if !path.exists() {
panic!("Path {} does not exist!", path.display()) panic!("Path {} does not exist!", path.display())
@ -210,8 +198,6 @@ async fn create_library(
lib_rx.inner().0.send(Some(path)).unwrap(); lib_rx.inner().0.send(Some(path)).unwrap();
app.manage(handle_tx.inner().0.recv().unwrap()); app.manage(handle_tx.inner().0.recv().unwrap());
app.emit("library_loaded", ()).unwrap(); app.emit("library_loaded", ()).unwrap();
window.close().unwrap();
Ok(()) Ok(())
} }

View file

@ -262,7 +262,7 @@ function Song(props: SongProps) {
<div onClick={() => { <div onClick={() => {
invoke("play_now", { uuid: props.uuid, location: props.playerLocation }).then(() => {}) invoke("play_now", { uuid: props.uuid, location: props.playerLocation }).then(() => {})
}} className="song"> }} className="song">
<p className="artist">{ props.tags.AlbumArtist }</p> <p className="artist">{ props.tags.TrackArtist }</p>
<p className="title">{ props.tags.TrackTitle }</p> <p className="title">{ props.tags.TrackTitle }</p>
<p className="album">{ props.tags.AlbumTitle }</p> <p className="album">{ props.tags.AlbumTitle }</p>
<p className="duration"> <p className="duration">
@ -372,14 +372,10 @@ function getConfig(): any {
invoke('get_config').then( (_config) => { invoke('get_config').then( (_config) => {
let config = _config as Config; let config = _config as Config;
if (config.libraries.libraries.length == 0) { if (config.libraries.libraries.length == 0) {
newWindow() invoke('create_new_library').then(() => {})
} else { } else {
// console.log("else"); // console.log("else");
invoke('lib_already_created').then(() => {}) invoke('lib_already_created').then(() => {})
} }
}) })
} }
function newWindow() {
invoke('new_library_window').then(() => {})
}