StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | use crate::platform::SystemTheme; |
| 2 | use winreg::enums::HKEY_CURRENT_USER; |
| 3 | use winreg::RegKey; |
| 4 | |
| 5 | const SYSTEM_THEME_SUBKEY_PATH: &str = |
| 6 | "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"; |
| 7 | const LIGHT_MODE_SUBKEY_NAME: &str = "AppsUseLightTheme"; |
| 8 | |
| 9 | /// Retrieves the system theme from the Windows Registry. |
| 10 | /// https://github.com/wez/wezterm/blob/b8f94c474ce48ac195b51c1aeacf41ae049b774e/window/src/os/windows/connection.rs#L42 |
| 11 | pub fn get_system_theme() -> Result<SystemTheme, std::io::Error> { |
| 12 | let theme_subkey = RegKey::predef(HKEY_CURRENT_USER).open_subkey(SYSTEM_THEME_SUBKEY_PATH)?; |
| 13 | let theme_value = theme_subkey.get_value::<u32, _>(LIGHT_MODE_SUBKEY_NAME)?; |
| 14 | match theme_value { |
| 15 | 1 => Ok(SystemTheme::Light), |
| 16 | 0 => Ok(SystemTheme::Dark), |
| 17 | _ => Err(std::io::Error::new( |
| 18 | std::io::ErrorKind::InvalidData, |
| 19 | format!("System theme value {theme_value:?} was invalid"), |
| 20 | )), |
| 21 | } |
| 22 | } |
| 23 |