mirror of
				https://github.com/Dummi26/musicdb.git
				synced 2025-10-29 19:19:20 +01:00 
			
		
		
		
	-client now compiles with --no-default-features again + small bugfix for syncplayer
This commit is contained in:
		
							parent
							
								
									ec475aa1af
								
							
						
					
					
						commit
						a151aa8712
					
				| @ -8,6 +8,7 @@ use std::{ | |||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| use clap::{Parser, Subcommand}; | use clap::{Parser, Subcommand}; | ||||||
|  | #[cfg(feature = "speedy2d")] | ||||||
| use gui::GuiEvent; | use gui::GuiEvent; | ||||||
| use musicdb_lib::{ | use musicdb_lib::{ | ||||||
|     data::{ |     data::{ | ||||||
| @ -40,6 +41,7 @@ mod gui_settings; | |||||||
| mod gui_text; | mod gui_text; | ||||||
| #[cfg(feature = "speedy2d")] | #[cfg(feature = "speedy2d")] | ||||||
| mod gui_wrappers; | mod gui_wrappers; | ||||||
|  | #[cfg(feature = "speedy2d")] | ||||||
| mod textcfg; | mod textcfg; | ||||||
| 
 | 
 | ||||||
| #[derive(Parser, Debug)] | #[derive(Parser, Debug)] | ||||||
| @ -91,7 +93,7 @@ fn main() { | |||||||
|         thread::spawn(move || { |         thread::spawn(move || { | ||||||
|             let mut player = |             let mut player = | ||||||
|                 if matches!(mode, Mode::SyncplayerLocal { .. } | Mode::SyncplayerNetwork) { |                 if matches!(mode, Mode::SyncplayerLocal { .. } | Mode::SyncplayerNetwork) { | ||||||
|                     Some(Player::new().unwrap()) |                     Some(Player::new().unwrap().without_sending_commands()) | ||||||
|                 } else { |                 } else { | ||||||
|                     None |                     None | ||||||
|                 }; |                 }; | ||||||
|  | |||||||
| @ -24,6 +24,7 @@ pub struct Player { | |||||||
|     manager: Manager, |     manager: Manager, | ||||||
|     current_song_id: SongOpt, |     current_song_id: SongOpt, | ||||||
|     cached: HashSet<SongId>, |     cached: HashSet<SongId>, | ||||||
|  |     allow_sending_commands: bool, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub enum SongOpt { | pub enum SongOpt { | ||||||
| @ -42,8 +43,13 @@ impl Player { | |||||||
|             source: None, |             source: None, | ||||||
|             current_song_id: SongOpt::None, |             current_song_id: SongOpt::None, | ||||||
|             cached: HashSet::new(), |             cached: HashSet::new(), | ||||||
|  |             allow_sending_commands: true, | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
|  |     pub fn without_sending_commands(mut self) -> Self { | ||||||
|  |         self.allow_sending_commands = false; | ||||||
|  |         self | ||||||
|  |     } | ||||||
|     pub fn handle_command(&mut self, command: &Command) { |     pub fn handle_command(&mut self, command: &Command) { | ||||||
|         match command { |         match command { | ||||||
|             Command::Resume => self.resume(), |             Command::Resume => self.resume(), | ||||||
| @ -76,18 +82,25 @@ impl Player { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     pub fn update(&mut self, db: &mut Database) { |     pub fn update(&mut self, db: &mut Database) { | ||||||
|  |         macro_rules! apply_command { | ||||||
|  |             ($cmd:expr) => { | ||||||
|  |                 if self.allow_sending_commands { | ||||||
|  |                     db.apply_command($cmd); | ||||||
|  |                 } | ||||||
|  |             }; | ||||||
|  |         } | ||||||
|         if db.playing && self.source.is_none() { |         if db.playing && self.source.is_none() { | ||||||
|             if let Some(song) = db.queue.get_current_song() { |             if let Some(song) = db.queue.get_current_song() { | ||||||
|                 // db playing, but no source - initialize a source (via SongOpt::New)
 |                 // db playing, but no source - initialize a source (via SongOpt::New)
 | ||||||
|                 self.current_song_id = SongOpt::New(Some(*song)); |                 self.current_song_id = SongOpt::New(Some(*song)); | ||||||
|             } else { |             } else { | ||||||
|                 // db.playing, but no song in queue...
 |                 // db.playing, but no song in queue...
 | ||||||
|                 db.apply_command(Command::Stop); |                 apply_command!(Command::Stop); | ||||||
|             } |             } | ||||||
|         } else if let Some((_source, notif)) = &mut self.source { |         } else if let Some((_source, notif)) = &mut self.source { | ||||||
|             if let Ok(()) = notif.try_recv() { |             if let Ok(()) = notif.try_recv() { | ||||||
|                 // song has finished playing
 |                 // song has finished playing
 | ||||||
|                 db.apply_command(Command::NextSong); |                 apply_command!(Command::NextSong); | ||||||
|                 self.current_song_id = SongOpt::New(db.queue.get_current_song().cloned()); |                 self.current_song_id = SongOpt::New(db.queue.get_current_song().cloned()); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @ -136,7 +149,7 @@ impl Player { | |||||||
|                                 } |                                 } | ||||||
|                                 Err(e) => { |                                 Err(e) => { | ||||||
|                                     eprintln!("[player] Can't play, skipping! {e}"); |                                     eprintln!("[player] Can't play, skipping! {e}"); | ||||||
|                                     db.apply_command(Command::NextSong); |                                     apply_command!(Command::NextSong); | ||||||
|                                 } |                                 } | ||||||
|                             } |                             } | ||||||
|                         } else { |                         } else { | ||||||
| @ -145,7 +158,7 @@ impl Player { | |||||||
|                                 "NoSongData".to_owned(), |                                 "NoSongData".to_owned(), | ||||||
|                                 format!("Couldn't load song #{}\n({})", song.id, song.title), |                                 format!("Couldn't load song #{}\n({})", song.id, song.title), | ||||||
|                             )); |                             )); | ||||||
|                             db.apply_command(Command::NextSong); |                             apply_command!(Command::NextSong); | ||||||
|                         } |                         } | ||||||
|                     } else { |                     } else { | ||||||
|                         self.source = None; |                         self.source = None; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Mark
						Mark