mirror of
https://github.com/Dangoware/dango-music-player.git
synced 2025-04-19 01:52:53 -05:00
synchronized front end and backend to avoid race condition
This commit is contained in:
parent
a36c535e7f
commit
27cae8ec41
3 changed files with 14 additions and 15 deletions
|
@ -1,5 +1,4 @@
|
|||
use std::{fs::OpenOptions, io::Write};
|
||||
|
||||
use dmp_core::{
|
||||
music_controller::{
|
||||
connections::LastFMAuth,
|
||||
|
@ -92,4 +91,4 @@ pub async fn last_fm_init_auth(ctrl_handle: State<'_, ControllerHandle>) -> Resu
|
|||
LastFMAuth::Session(None),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -19,7 +19,7 @@ use dmp_core::{
|
|||
music_storage::library::{MusicLibrary, Song},
|
||||
};
|
||||
use parking_lot::RwLock;
|
||||
use tauri::{http::Response, AppHandle, Emitter, Manager};
|
||||
use tauri::{http::Response, AppHandle, Emitter, Listener, Manager};
|
||||
use uuid::Uuid;
|
||||
use wrappers::{_Song, stop};
|
||||
|
||||
|
@ -41,9 +41,7 @@ const LAST_FM_API_SECRET: &str = env!("LAST_FM_API_SECRET", "None");
|
|||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
let (app_rx, app_tx) = bounded::<AppHandle>(1);
|
||||
|
||||
|
||||
let (sync_rx, sync_tx) = bounded::<()>(1);
|
||||
|
||||
let app = tauri::Builder::default()
|
||||
.plugin(tauri_plugin_shell::init())
|
||||
|
@ -70,12 +68,10 @@ pub fn run() {
|
|||
get_config,
|
||||
save_config,
|
||||
close_window,
|
||||
start_controller,
|
||||
])
|
||||
.manage(tempfile::TempDir::new().unwrap())
|
||||
.setup(move |app| {
|
||||
app_rx.send(app.handle().clone()).unwrap();
|
||||
Ok(())
|
||||
})
|
||||
.manage(sync_rx)
|
||||
.register_asynchronous_uri_scheme_protocol("asset", move |ctx, req, res| {
|
||||
let query = req
|
||||
.clone()
|
||||
|
@ -117,8 +113,6 @@ pub fn run() {
|
|||
.build(tauri::generate_context!())
|
||||
.expect("error while building tauri application");
|
||||
|
||||
let _controller_thread = start_controller(app.handle().clone());
|
||||
|
||||
app.run(|_app_handle, event| match event {
|
||||
tauri::RunEvent::ExitRequested { .. } => {
|
||||
// api.prevent_exit();
|
||||
|
@ -128,7 +122,8 @@ pub fn run() {
|
|||
});
|
||||
}
|
||||
|
||||
fn start_controller(app: AppHandle) -> JoinHandle<()> {
|
||||
#[tauri::command]
|
||||
fn start_controller(app: AppHandle) -> Result<(), String> {
|
||||
spawn(move || {
|
||||
let mut config = init_get_config().unwrap();
|
||||
|
||||
|
@ -163,7 +158,7 @@ fn start_controller(app: AppHandle) -> JoinHandle<()> {
|
|||
} else {
|
||||
config.write_file().unwrap();
|
||||
}
|
||||
library.save(lib_path).unwrap();
|
||||
library.save(lib_path.to_path_buf()).unwrap();
|
||||
app.emit("library_loaded", ()).unwrap();
|
||||
|
||||
|
||||
|
@ -226,7 +221,8 @@ fn start_controller(app: AppHandle) -> JoinHandle<()> {
|
|||
.unwrap();
|
||||
|
||||
let _controller = futures::executor::block_on(Controller::start(input)).unwrap();
|
||||
})
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn init_get_config() -> Result<Config, String> {
|
||||
|
|
|
@ -71,6 +71,10 @@ function App() {
|
|||
return () => { unlisten.then((f) => f()) }
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const invoke_: any = invoke("start_controller").then(() => {});
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<main>
|
||||
<div className="container">
|
||||
|
|
Loading…
Reference in a new issue