src/app/config/main.rs

58 lines · 1315 bytes

 1use std::collections::HashMap;
 2
 3use crate::traits::ConfigItem;
 4use serde::{Deserialize, Serialize};
 5
 6fn max_watch_history_default() -> usize {
 7    50
 8}
 9
10fn server_url_default() -> String {
11    String::from("https://invidious.flokinet.to")
12}
13
14fn env_default() -> HashMap<String, String> {
15    let mut out = HashMap::default();
16
17    out.insert(
18        String::from("download_location"),
19        String::from("~/Downloads/%(title)s.%(ext)s"),
20    );
21
22    out
23}
24
25fn display_thumbnails_default() -> bool {
26    true
27}
28
29#[derive(Clone, Serialize, Deserialize)]
30pub struct MainConfig {
31    #[serde(default = "max_watch_history_default")]
32    pub max_watch_history: usize,
33
34    #[serde(default = "server_url_default")]
35    pub server_url: String,
36
37    #[serde(default = "display_thumbnails_default")]
38    pub display_thumbnails: bool,
39
40    #[serde(default = "env_default")]
41    pub env: HashMap<String, String>,
42}
43
44impl Default for MainConfig {
45    fn default() -> Self {
46        Self {
47            max_watch_history: max_watch_history_default(),
48            server_url: server_url_default(),
49            display_thumbnails: display_thumbnails_default(),
50            env: env_default(),
51        }
52    }
53}
54
55impl ConfigItem<'_> for MainConfig {
56    type Struct = MainConfig;
57    const FILE_NAME: &'static str = "main.yml";
58}