1use std::path::PathBuf;
2
3use crate::{
4 AppConfig, ArtistPhotoSource, ArtistViewOrder, BackBehavior, Browser, ChannelMode,
5 EqualizerSettings, FetchStrategy, HomeSection, ListenNowStyle, MusicServer, MusicService,
6 PlayerBarPosition, RegistryEntry, SortOrder, TitlebarMode, UiStyle,
7};
8
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub enum ServerAuth {
11 Token {
12 token: Option<String>,
13 user_id: Option<String>,
14 },
15 Browser {
16 browser: Option<Browser>,
17 token: Option<String>,
18 user_id: Option<String>,
19 anonymous: bool,
20 },
21}
22
23#[derive(Debug, Clone, PartialEq)]
24pub struct PlaybackConfig {
25 pub volume: f32,
26 pub volume_scroll_step: f32,
27 pub crossfade_seconds: u8,
28 pub back_behavior: BackBehavior,
29 pub channel_mode: ChannelMode,
30 pub equalizer: EqualizerSettings,
31}
32
33#[derive(Debug, Clone, PartialEq)]
34pub struct UiConfig {
35 pub theme: String,
36 pub language: String,
37 pub reduce_animations: bool,
38 pub titlebar_mode: TitlebarMode,
39 pub player_bar_position: PlayerBarPosition,
40 pub ui_style: UiStyle,
41 pub hero_height: u32,
42 pub home_sections: Vec<HomeSection>,
43 pub listen_now_style: ListenNowStyle,
44 pub show_source_toggle: bool,
45 pub sidebar_order: Vec<String>,
46}
47
48#[derive(Debug, Clone, PartialEq)]
49pub struct LibraryConfig {
50 pub music_directory: Vec<PathBuf>,
51 pub sort_order: SortOrder,
52 pub artist_view_order: ArtistViewOrder,
53 pub artist_photo_source: ArtistPhotoSource,
54 pub auto_fetch_covers: bool,
55 pub cover_fetch_strategy: FetchStrategy,
56}
57
58#[derive(Debug, Clone, PartialEq)]
59pub struct IntegrationConfig {
60 pub discord_presence: Option<bool>,
61 pub discord_presence_paused: Option<bool>,
62 pub discord_presence_source: Option<bool>,
63 pub musicbrainz_token: String,
64 pub lastfm_api_key: String,
65 pub lastfm_api_secret: String,
66 pub lastfm_session_key: String,
67 pub librefm_api_key: String,
68 pub librefm_api_secret: String,
69 pub librefm_session_key: String,
70 pub prefer_local_lyrics: bool,
71 pub enable_musixmatch_lyrics: bool,
72 pub radio_registries: Vec<RegistryEntry>,
73}
74
75impl MusicServer {
76 pub fn auth(&self) -> ServerAuth {
77 if self.service == MusicService::YtMusic || self.service == MusicService::SoundCloud {
78 ServerAuth::Browser {
79 browser: self.yt_browser,
80 token: self.access_token.clone(),
81 user_id: self.user_id.clone(),
82 anonymous: self.yt_anonymous,
83 }
84 } else {
85 ServerAuth::Token {
86 token: self.access_token.clone(),
87 user_id: self.user_id.clone(),
88 }
89 }
90 }
91}
92
93impl AppConfig {
94 pub fn playback(&self) -> PlaybackConfig {
95 PlaybackConfig {
96 volume: self.volume,
97 volume_scroll_step: self.volume_scroll_step,
98 crossfade_seconds: self.crossfade_seconds,
99 back_behavior: self.back_behavior,
100 channel_mode: self.channel_mode,
101 equalizer: self.equalizer.clone(),
102 }
103 }
104
105 pub fn ui(&self) -> UiConfig {
106 UiConfig {
107 theme: self.theme.clone(),
108 language: self.language.clone(),
109 reduce_animations: self.reduce_animations,
110 titlebar_mode: self.titlebar_mode,
111 player_bar_position: self.player_bar_position,
112 ui_style: self.ui_style,
113 hero_height: self.hero_height,
114 home_sections: self.home_sections.clone(),
115 listen_now_style: self.listen_now_style,
116 show_source_toggle: self.show_source_toggle,
117 sidebar_order: self.sidebar_order.clone(),
118 }
119 }
120
121 pub fn library(&self) -> LibraryConfig {
122 LibraryConfig {
123 music_directory: self.music_directory.clone(),
124 sort_order: self.sort_order.clone(),
125 artist_view_order: self.artist_view_order.clone(),
126 artist_photo_source: self.artist_photo_source,
127 auto_fetch_covers: self.auto_fetch_covers,
128 cover_fetch_strategy: self.cover_fetch_strategy,
129 }
130 }
131
132 pub fn integrations(&self) -> IntegrationConfig {
133 IntegrationConfig {
134 discord_presence: self.discord_presence,
135 discord_presence_paused: self.discord_presence_paused,
136 discord_presence_source: self.discord_presence_source,
137 musicbrainz_token: self.musicbrainz_token.clone(),
138 lastfm_api_key: self.lastfm_api_key.clone(),
139 lastfm_api_secret: self.lastfm_api_secret.clone(),
140 lastfm_session_key: self.lastfm_session_key.clone(),
141 librefm_api_key: self.librefm_api_key.clone(),
142 librefm_api_secret: self.librefm_api_secret.clone(),
143 librefm_session_key: self.librefm_session_key.clone(),
144 prefer_local_lyrics: self.prefer_local_lyrics,
145 enable_musixmatch_lyrics: self.enable_musixmatch_lyrics,
146 radio_registries: self.radio_registries.clone(),
147 }
148 }
149}