nativeTheme

    进程:主进程

    nativeTheme模块包括以下事件:

    当以下NativeTheme属性发生变化时会触发此事件: shouldUseDarkColors, shouldUseHighContrastColorsshouldUseInvertedColorScheme 。 你需要自己检查到底是哪个属性发生了变化。

    属性

    此属性的值为一个 Boolean 类型的值,代表着当前OS / Chromium是否正处于dark模式。或者应用程序是否正被建议使用dark模式的皮肤 如果你希望修改此属性的值,你应该使用下面的 themeSource属性

    一个类型为String的属性,此属性可能的值为:, light or dark. 它被用来覆盖、重写Chromium内部的相应的值

    Setting this property to system will remove the override and everything will be reset to the OS default. By default themeSource is system.

    • nativeTheme.shouldUseDarkColors will be true when accessed
    • Any UI Electron renders on Linux and Windows including context menus, devtools, etc. will use the dark UI.
    • Any UI the OS renders on macOS including menus, window frames, etc. will use the dark UI.
    • The prefers-color-scheme CSS query will match dark mode.
    • The updated event will be emitted

    Settings this property to light will have the following effects:

    • nativeTheme.shouldUseDarkColors will be when accessed
    • Any UI the OS renders on macOS including menus, window frames, etc. will use the light UI.
    • The CSS query will match light mode.
    • The updated event will be emitted

    The usage of this property should align with a classic “dark mode” state machine in your application where the user has three options.

    • Follow OS —> themeSource = 'system'
    • Dark Mode —> themeSource = 'dark'
    • Light Mode —> themeSource = 'light'

    Your application should then always use shouldUseDarkColors to determine what CSS to apply.

    A for if the OS / Chromium currently has an inverted color scheme or is being instructed to use an inverted color scheme.