Skip to main content

config/
views.rs

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 musicbrainz_token: String,
63    pub lastfm_api_key: String,
64    pub lastfm_api_secret: String,
65    pub lastfm_session_key: String,
66    pub librefm_api_key: String,
67    pub librefm_api_secret: String,
68    pub librefm_session_key: String,
69    pub prefer_local_lyrics: bool,
70    pub enable_musixmatch_lyrics: bool,
71    pub radio_registries: Vec<RegistryEntry>,
72}
73
74impl MusicServer {
75    pub fn auth(&self) -> ServerAuth {
76        if self.service == MusicService::YtMusic || self.service == MusicService::SoundCloud {
77            ServerAuth::Browser {
78                browser: self.yt_browser,
79                token: self.access_token.clone(),
80                user_id: self.user_id.clone(),
81                anonymous: self.yt_anonymous,
82            }
83        } else {
84            ServerAuth::Token {
85                token: self.access_token.clone(),
86                user_id: self.user_id.clone(),
87            }
88        }
89    }
90}
91
92impl AppConfig {
93    pub fn playback(&self) -> PlaybackConfig {
94        PlaybackConfig {
95            volume: self.volume,
96            volume_scroll_step: self.volume_scroll_step,
97            crossfade_seconds: self.crossfade_seconds,
98            back_behavior: self.back_behavior,
99            channel_mode: self.channel_mode,
100            equalizer: self.equalizer.clone(),
101        }
102    }
103
104    pub fn ui(&self) -> UiConfig {
105        UiConfig {
106            theme: self.theme.clone(),
107            language: self.language.clone(),
108            reduce_animations: self.reduce_animations,
109            titlebar_mode: self.titlebar_mode,
110            player_bar_position: self.player_bar_position,
111            ui_style: self.ui_style,
112            hero_height: self.hero_height,
113            home_sections: self.home_sections.clone(),
114            listen_now_style: self.listen_now_style,
115            show_source_toggle: self.show_source_toggle,
116            sidebar_order: self.sidebar_order.clone(),
117        }
118    }
119
120    pub fn library(&self) -> LibraryConfig {
121        LibraryConfig {
122            music_directory: self.music_directory.clone(),
123            sort_order: self.sort_order.clone(),
124            artist_view_order: self.artist_view_order.clone(),
125            artist_photo_source: self.artist_photo_source,
126            auto_fetch_covers: self.auto_fetch_covers,
127            cover_fetch_strategy: self.cover_fetch_strategy,
128        }
129    }
130
131    pub fn integrations(&self) -> IntegrationConfig {
132        IntegrationConfig {
133            discord_presence: self.discord_presence,
134            discord_presence_paused: self.discord_presence_paused,
135            musicbrainz_token: self.musicbrainz_token.clone(),
136            lastfm_api_key: self.lastfm_api_key.clone(),
137            lastfm_api_secret: self.lastfm_api_secret.clone(),
138            lastfm_session_key: self.lastfm_session_key.clone(),
139            librefm_api_key: self.librefm_api_key.clone(),
140            librefm_api_secret: self.librefm_api_secret.clone(),
141            librefm_session_key: self.librefm_session_key.clone(),
142            prefer_local_lyrics: self.prefer_local_lyrics,
143            enable_musixmatch_lyrics: self.enable_musixmatch_lyrics,
144            radio_registries: self.radio_registries.clone(),
145        }
146    }
147}