diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index a68edce..5b6bdd5 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -2,6 +2,7 @@ use std::{fs, path::PathBuf, str::FromStr, thread::spawn}; use crossbeam::channel::{unbounded, Receiver, Sender}; 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 uuid::Uuid; @@ -66,8 +67,7 @@ pub fn run() { .plugin(tauri_plugin_shell::init()) .invoke_handler(tauri::generate_handler![ get_config, - new_library_window, - create_library, + create_new_library, get_library, play, pause, @@ -126,11 +126,11 @@ pub fn run() { app .run(|_app_handle, event| match event { tauri::RunEvent::ExitRequested { api, .. } => { - api.prevent_exit(); + // api.prevent_exit(); + panic!("does this kill the player?") } _ => {} }); - std::mem::drop(controller_thread) } struct ConfigRx(Sender); @@ -175,31 +175,19 @@ async fn get_config(state: State<'_, ConfigRx>) -> Result { } #[tauri::command] -async fn new_library_window(app: tauri::AppHandle) -> Result<(), String> { - 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( +async fn create_new_library( app: tauri::AppHandle, lib_rx: State<'_, LibRx>, handle_tx: State<'_, HandleTx>, - window: tauri::Window, - path: String ) -> Result<(), String> { - println!("{path}"); - let path = PathBuf::from(path.trim().trim_matches('"')); + let dir = rfd::AsyncFileDialog::new() + .set_title("Pick a library path") + .pick_folder() + .await + .unwrap(); + + let path = dir.path().canonicalize().unwrap(); + println!("{}", path.display()); if !path.exists() { panic!("Path {} does not exist!", path.display()) @@ -210,8 +198,6 @@ async fn create_library( lib_rx.inner().0.send(Some(path)).unwrap(); app.manage(handle_tx.inner().0.recv().unwrap()); app.emit("library_loaded", ()).unwrap(); - - window.close().unwrap(); Ok(()) } diff --git a/src/App.tsx b/src/App.tsx index 0af6157..e0fa644 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -262,7 +262,7 @@ function Song(props: SongProps) {
{ invoke("play_now", { uuid: props.uuid, location: props.playerLocation }).then(() => {}) }} className="song"> -

{ props.tags.AlbumArtist }

+

{ props.tags.TrackArtist }

{ props.tags.TrackTitle }

{ props.tags.AlbumTitle }

@@ -372,14 +372,10 @@ function getConfig(): any { invoke('get_config').then( (_config) => { let config = _config as Config; if (config.libraries.libraries.length == 0) { - newWindow() + invoke('create_new_library').then(() => {}) } else { // console.log("else"); invoke('lib_already_created').then(() => {}) } }) -} - -function newWindow() { - invoke('new_library_window').then(() => {}) -} +} \ No newline at end of file