Windows10周年纪念更新引入了一种深色模式,在这种模式下,大多数支持的应用程序会将其调色板更改为深色。我想使用Node.js或Electron来确定是否启用了该设置,这样我就可以适当地选择默认情况下启动应用程序的主题。做这件事最好的方法是什么?
发布于 2019-08-03 18:40:54
从electron 6.0.0 (and chromium 76)
媒体查询开始,可以使用prefers color scheme
来检测暗/亮模式,如下所示:
@media screen and (prefers-color-scheme: light), screen and (prefers-color-scheme: no-preference) {
/*light theme*/
body{
color: black;
background-color: white;
}
}
@media screen and (prefers-color-scheme: dark) {
/*dark theme*/
body {
color: white;
background-color: black;
}
}
您还可以通过编程检查暗模式,如下所示:
if (window.matchMedia('(prefers-color-scheme:dark)').matches) {
console.log('dark');
}
else {
console.log('light or no-preference');
}
演示:codepen
发布于 2018-04-22 02:39:35
我能想到的一种选择是读取以下注册表项:HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\AppsUseLightTheme
https://stackoverflow.com/questions/45112719
复制相似问题