settings/display/
display_configuration.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2021 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

//! This file contains a number of enums and structs that are used as an
//! internal representation of the configuration data found in
//! `/config/data/display_configuration.json`.

use std::rc::Rc;
use std::sync::Mutex;

use serde::{Deserialize, Serialize};

use crate::config::default_settings::DefaultSetting;
use crate::inspect::config_logger::InspectConfigLogger;

/// Possible theme modes that can be found in
/// `/config/data/display_configuration.json`.
#[derive(PartialEq, Debug, Clone, Copy, Serialize, Deserialize)]
pub enum ConfigurationThemeMode {
    Auto,
}

/// Possible theme types that can be found in
/// `/config/data/display_configuration.json`.
#[derive(PartialEq, Debug, Clone, Copy, Serialize, Deserialize)]
pub enum ConfigurationThemeType {
    Light,
}

/// Internal representation of the display configuration stored in
/// `/config/data/display_configuration.json`.
#[derive(PartialEq, Debug, Clone, Deserialize)]
pub struct DisplayConfiguration {
    pub theme: ThemeConfiguration,
}

/// Internal representation of the theme portion of the configuration stored in
/// `/config/data/display_configuration.json`.
#[derive(PartialEq, Debug, Clone, Deserialize)]
pub struct ThemeConfiguration {
    pub theme_mode: Vec<ConfigurationThemeMode>,
    pub theme_type: ConfigurationThemeType,
}

pub fn build_display_default_settings(
    config_logger: Rc<Mutex<InspectConfigLogger>>,
) -> DefaultSetting<DisplayConfiguration, &'static str> {
    DefaultSetting::new(None, "/config/data/display_configuration.json", config_logger)
}

#[cfg(test)]
mod test {
    use super::*;
    use fuchsia_inspect::component;

    #[fuchsia::test(allow_stalls = false)]
    async fn test_display_configuration() {
        let config_logger =
            Rc::new(Mutex::new(InspectConfigLogger::new(component::inspector().root())));
        let default_value = build_display_default_settings(config_logger)
            .load_default_value()
            .expect("Invalid display configuration")
            .expect("Unable to parse configuration");

        assert_eq!(default_value.theme.theme_mode, vec![ConfigurationThemeMode::Auto]);
        assert_eq!(default_value.theme.theme_type, ConfigurationThemeType::Light);
    }
}