Skip to main content

system_is_dark

Function system_is_dark 

Source
pub fn system_is_dark() -> bool
Expand description

Detect whether the system is using a dark color scheme.

Uses synchronous, platform-specific checks so the result is available immediately at window creation time (before any async portal response).

§Caching

The result is cached after the first call using OnceLock and never refreshed. If the user toggles dark mode while the app is running, this function will return stale data. Use detect_is_dark() instead for a fresh reading suitable for polling or change tracking.

For live dark-mode tracking, subscribe to OS appearance-change events (D-Bus SettingChanged on Linux, NSAppearance KVO on macOS, UISettings.ColorValuesChanged on Windows) and call SystemTheme::from_system() to get a fresh SystemTheme with updated resolved variants.

§Platform Behavior

  • Linux: Queries gsettings for color-scheme via subprocess; falls back to KDE kdeglobals background luminance (with kde feature).
  • macOS: Reads AppleInterfaceStyle via NSUserDefaults (with macos feature) or defaults subprocess (without).
  • Windows: Checks foreground color luminance from UISettings via BT.601 coefficients (requires windows feature).
  • Other platforms / missing features: Returns false (light).