覆盖 Electron 中的 prefers-color-scheme

huangapple go评论64阅读模式
英文:

Override prefers-color-scheme in Electron

问题

我有一个使用CSS的Electron应用程序,它使用prefers-color-scheme来实现深色模式。在Windows和Mac上运行良好,但在Linux上不行(可能是因为Chromium没有一种查询桌面主题的方式)。

我想提供一个选项来覆盖Chromium自动查找的prefers-color-scheme值。是否可以使用Electron API来实现这一点?

英文:

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).

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?

答案1

得分: 1

有一个API!你可以使用nativeTheme.themeSource设置为systemlightdark

例如,在我的background.ts文件中,添加以下代码:

import { /* 现有内容 */, nativeTheme } from "electron";

nativeTheme.themeSource = 'light';
英文:

There is an API! You can nativeTheme.themeSource to system, light or dark.

For example, in my background.ts, add this code:

import { /* existing stuff */, nativeTheme } from "electron";

nativeTheme.themeSource = 'light';

huangapple
  • 本文由 发表于 2020年1月6日 17:47:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/59609852.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定