Seregon/StratoSDK

StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.

Rust/27.3 KB/No license
crates/strato-ui-renderer/src/windowing/winit/windows/registry.rs
1use crate::platform::SystemTheme;
2use winreg::enums::HKEY_CURRENT_USER;
3use winreg::RegKey;
4 
5const SYSTEM_THEME_SUBKEY_PATH: &str =
6 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
7const 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
11pub 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