Skip to main content

from_system

Function from_system 

Source
pub fn from_system() -> Result<(Theme, ResolvedThemeVariant, bool)>
Expand description

Detect the OS theme and convert it to a gpui-component Theme in one call.

Combines SystemTheme::from_system() with to_theme() using the system-detected name and dark-mode preference.

Returns both the gpui Theme and the ResolvedThemeVariant so callers can access per-widget metrics that the flat ThemeColor cannot represent.

Ownership note (Issue 19/31): this function takes ownership of the SystemTheme’s active variant. The non-active variant (light when dark is active, or vice versa) is dropped. If you need both variants, use SystemTheme::from_system() directly and call to_theme() on each.

Performance note: SystemTheme::from_system() resolves both light and dark variants before this function picks one. If you only need one variant and want to avoid the cost of resolving both, use SystemTheme::from_system() directly and resolve only the variant you need.

§Errors

Returns an error if the platform theme cannot be read (e.g., unsupported platform, missing desktop environment).

§Examples

let (theme, resolved, is_dark) = native_theme_gpui::from_system()?;