cosmic_theme/model/
mode.rs

1use cosmic_config::{Config, ConfigGet, CosmicConfigEntry};
2
3/// ID for the ThemeMode config
4pub const THEME_MODE_ID: &str = "com.system76.CosmicTheme.Mode";
5
6/// The config for cosmic theme dark / light settings
7#[derive(
8    Debug, Clone, Copy, PartialEq, Eq, cosmic_config::cosmic_config_derive::CosmicConfigEntry,
9)]
10#[version = 1]
11pub struct ThemeMode {
12    /// The theme dark mode setting.
13    pub is_dark: bool,
14    /// The theme auto-switch dark and light mode setting.
15    pub auto_switch: bool,
16}
17
18impl Default for ThemeMode {
19    #[inline]
20    fn default() -> Self {
21        Self {
22            is_dark: true,
23            auto_switch: false,
24        }
25    }
26}
27
28impl ThemeMode {
29    #[inline]
30    /// Check if the theme is currently using dark mode
31    pub fn is_dark(config: &Config) -> Result<bool, cosmic_config::Error> {
32        config.get::<bool>("is_dark")
33    }
34
35    #[inline]
36    /// The current version of the theme mode config.
37    pub const fn version() -> u64 {
38        Self::VERSION
39    }
40
41    #[inline]
42    /// Get the config for the theme mode
43    pub fn config() -> Result<Config, cosmic_config::Error> {
44        Config::new(THEME_MODE_ID, Self::VERSION)
45    }
46}