termusiclib/config/server_overlay.rs
1use std::path::{Path, PathBuf};
2
3use super::v2::server::ScanDepth;
4
5/// The Server Settings to use, with possible overwrite (like from CLI)
6#[derive(Debug, Clone, PartialEq, Default)]
7#[allow(clippy::module_name_repetitions)]
8pub struct ServerOverlay {
9 /// The saved Server-Settings
10 pub settings: super::v2::server::ServerSettings,
11
12 /// Overwrite what music directory should be opened first
13 ///
14 /// This music dir will not be saved to the config
15 // Note that this is basically unused in the server currently, but used in the TUI
16 // but it is here because the Server has all the music-dirs and in the future it should handle the roots
17 pub music_dir_overwrite: Option<PathBuf>,
18 /// Overwrite disabling the discord status setting
19 pub disable_discord_status: bool,
20 /// Overwrite the Library scan depth
21 pub library_scan_depth: Option<ScanDepth>,
22}
23
24impl ServerOverlay {
25 /// Get the Library scan depth, either the overwrite if present, otherwise the config itself
26 #[must_use]
27 pub fn get_library_scan_depth(&self) -> ScanDepth {
28 if let Some(v) = self.library_scan_depth {
29 v
30 } else {
31 self.settings.player.library_scan_depth
32 }
33 }
34
35 /// Get whether to enable the discord status
36 #[must_use]
37 pub fn get_discord_status_enable(&self) -> bool {
38 if self.disable_discord_status {
39 false
40 } else {
41 self.settings.player.set_discord_status
42 }
43 }
44
45 /// Get the first music dir to use, either the overwrite if present, otherwise the config's first music music (if any)
46 pub fn get_first_music_dir(&self) -> Option<&Path> {
47 if let Some(ref overwrite) = self.music_dir_overwrite {
48 Some(overwrite)
49 } else {
50 self.settings
51 .player
52 .music_dirs
53 .first()
54 .map(PathBuf::as_path)
55 }
56 }
57}