优先选择电子中的颜色方案 [英] Override prefers-color-scheme in Electron
问题描述
我有一个Electron应用程序,该应用程序使用CSS prefers-color-scheme
来实现暗模式.在Windows和Mac上可以正常使用,但在Linux上则不能(大概是因为Chromium无法查询桌面主题).
I have an Electron app that uses CSS prefers-color-scheme
to implement dark mode. This works fine on Windows and Mac, but not on Linux (presumably because Chromium doesn't have a way of querying the desktop theme).
我想提供一个选项,以替代Chromium自动为 prefers-color-scheme
找到的值.是否可以使用Electron API做到这一点?
I would like to provide an option to override the value that Chromium automatically finds for prefers-color-scheme
. Is there a way to do this using the Electron API?
推荐答案
有一个API!您可以 nativeTheme.themeSource
到系统
,浅
或暗
.
There is an API! You can nativeTheme.themeSource
to system
, light
or dark
.
例如,在我的 background.ts
中,添加以下代码:
For example, in my background.ts
, add this code:
import { /* existing stuff */, nativeTheme } from "electron";
nativeTheme.themeSource = 'light';
这篇关于优先选择电子中的颜色方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!