add more modes to client and change server cli

server can now source its database and files from
another server, but it will have its own
queue and appears as separate to clients.

the client now has gui-syncplayer-{local,network}
modes which show the gui and also play the songs.
using a syncplayer-network mode now automatically
enables the cache manager, which should make
waiting for songs to load less frequent.
This commit is contained in:
Mark
2024-05-28 13:20:43 +02:00
parent 7d6d6d295b
commit 61110f5f4a
14 changed files with 405 additions and 139 deletions

View File

@@ -163,7 +163,7 @@ impl CacheManager {
Err(true) => {
break;
}
Ok(()) => {
Ok(true) => {
eprintln!(
"[{}] CacheManager :: Start caching bytes for song '{}'.",
"INFO".cyan(),
@@ -172,6 +172,7 @@ impl CacheManager {
sleep_short = true;
break;
}
Ok(false) => (),
}
}
}

View File

@@ -89,15 +89,16 @@ impl CachedData {
}
/// If no data is cached yet and no caching thread is running, starts a thread to cache the data.
pub fn cache_data_start_thread(&self, db: &Database, song: &Song) -> bool {
self.cache_data_start_thread_or_say_already_running(db, song)
.is_ok()
self.cache_data_start_thread_or_say_already_running(db, song) == Ok(true)
}
/// Ok(true) => thread started,
/// Ok(false) => data was already loaded
pub fn cache_data_start_thread_or_say_already_running(
&self,
db: &Database,
song: &Song,
) -> Result<(), bool> {
self.get_data_or_start_thread_and_say_already_running(db, |_| (), || (), song)
) -> Result<bool, bool> {
self.get_data_or_start_thread_and_say_already_running(db, |_| false, || true, song)
}
/// gets the data if available, or, if no thread is running, starts a thread to get the data.
/// if a thread is running, was started, or recently encountered an error, `None` is returned, otherwise `Some(data)`.
@@ -128,7 +129,7 @@ impl CachedData {
) -> Result<T, bool> {
let mut cd = self.0.lock().unwrap();
match cd.0.as_mut() {
Err(Some(i)) if i.elapsed().as_secs_f32() > 60.0 => return Err(false),
Err(Some(i)) if i.elapsed().as_secs_f32() < 60.0 => return Err(false),
Err(_) => (),
Ok(Err(t)) => {
if t.is_finished() {