mirror of
https://github.com/Dangoware/dango-music-player.git
synced 2025-04-19 10:02: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 std::{fs::OpenOptions, io::Write};
|
||||||
|
|
||||||
use dmp_core::{
|
use dmp_core::{
|
||||||
music_controller::{
|
music_controller::{
|
||||||
connections::LastFMAuth,
|
connections::LastFMAuth,
|
||||||
|
|
|
@ -19,7 +19,7 @@ use dmp_core::{
|
||||||
music_storage::library::{MusicLibrary, Song},
|
music_storage::library::{MusicLibrary, Song},
|
||||||
};
|
};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use tauri::{http::Response, AppHandle, Emitter, Manager};
|
use tauri::{http::Response, AppHandle, Emitter, Listener, Manager};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use wrappers::{_Song, stop};
|
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)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
let (app_rx, app_tx) = bounded::<AppHandle>(1);
|
let (sync_rx, sync_tx) = bounded::<()>(1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let app = tauri::Builder::default()
|
let app = tauri::Builder::default()
|
||||||
.plugin(tauri_plugin_shell::init())
|
.plugin(tauri_plugin_shell::init())
|
||||||
|
@ -70,12 +68,10 @@ pub fn run() {
|
||||||
get_config,
|
get_config,
|
||||||
save_config,
|
save_config,
|
||||||
close_window,
|
close_window,
|
||||||
|
start_controller,
|
||||||
])
|
])
|
||||||
.manage(tempfile::TempDir::new().unwrap())
|
.manage(tempfile::TempDir::new().unwrap())
|
||||||
.setup(move |app| {
|
.manage(sync_rx)
|
||||||
app_rx.send(app.handle().clone()).unwrap();
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
.register_asynchronous_uri_scheme_protocol("asset", move |ctx, req, res| {
|
.register_asynchronous_uri_scheme_protocol("asset", move |ctx, req, res| {
|
||||||
let query = req
|
let query = req
|
||||||
.clone()
|
.clone()
|
||||||
|
@ -117,8 +113,6 @@ pub fn run() {
|
||||||
.build(tauri::generate_context!())
|
.build(tauri::generate_context!())
|
||||||
.expect("error while building tauri application");
|
.expect("error while building tauri application");
|
||||||
|
|
||||||
let _controller_thread = start_controller(app.handle().clone());
|
|
||||||
|
|
||||||
app.run(|_app_handle, event| match event {
|
app.run(|_app_handle, event| match event {
|
||||||
tauri::RunEvent::ExitRequested { .. } => {
|
tauri::RunEvent::ExitRequested { .. } => {
|
||||||
// api.prevent_exit();
|
// 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 || {
|
spawn(move || {
|
||||||
let mut config = init_get_config().unwrap();
|
let mut config = init_get_config().unwrap();
|
||||||
|
|
||||||
|
@ -163,7 +158,7 @@ fn start_controller(app: AppHandle) -> JoinHandle<()> {
|
||||||
} else {
|
} else {
|
||||||
config.write_file().unwrap();
|
config.write_file().unwrap();
|
||||||
}
|
}
|
||||||
library.save(lib_path).unwrap();
|
library.save(lib_path.to_path_buf()).unwrap();
|
||||||
app.emit("library_loaded", ()).unwrap();
|
app.emit("library_loaded", ()).unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
@ -226,7 +221,8 @@ fn start_controller(app: AppHandle) -> JoinHandle<()> {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let _controller = futures::executor::block_on(Controller::start(input)).unwrap();
|
let _controller = futures::executor::block_on(Controller::start(input)).unwrap();
|
||||||
})
|
});
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_get_config() -> Result<Config, String> {
|
fn init_get_config() -> Result<Config, String> {
|
||||||
|
|
|
@ -71,6 +71,10 @@ function App() {
|
||||||
return () => { unlisten.then((f) => f()) }
|
return () => { unlisten.then((f) => f()) }
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const invoke_: any = invoke("start_controller").then(() => {});
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main>
|
<main>
|
||||||
<div className="container">
|
<div className="container">
|
||||||
|
|
Loading…
Reference in a new issue