系统表现 | systemPreferences
获取系统首选项。
过程:Main
const {systemPreferences} = require('electron')
console.log(systemPreferences.isDarkMode())活动
systemPreferences对象发出以下事件:
事件:'重音颜色改变' Windows
返回:
event事件newColor字符串 - 用户指定为其系统口音颜色的新RGBA颜色。
Event: ‘color-changed’ Windows
返回:
eventEvent
事件:'倒置颜色方案改变' Windows
返回:
event事件invertedColorScheme布尔值 -true如果正在使用反转色彩方案(例如高对比度主题),则使用false其他方法。
方法
systemPreferences.isDarkMode() macOS
返回Boolean- 系统是否处于黑暗模式。
systemPreferences.isSwipeTrackingFromScrollEventsEnabled() macOS
返回Boolean- 页面间滑动设置是否打开。
systemPreferences.postNotification(event, userInfo) macOS
event串userInfo目的
上传event为MacOS的原生通知。该userInfo对象包含随通知一起发送的用户信息词典。
systemPreferences.postLocalNotification(event, userInfo) macOS
eventStringuserInfoObject
发布event为MacOS的原生通知。该userInfo对象包含随通知一起发送的用户信息词典。
systemPreferences.subscribeNotification(event, callback) macOS
eventStringcallbackFunctioneventStringuserInfoObject
订阅macOS的本地通知,callback将callback(event, userInfo)在相应event情况发生时调用。该userInfo对象包含随通知一起发送的用户信息词典。
id订户的返回,其可用于退订event。
在这个API所订阅的引擎之下NSDistributedNotificationCenter,示例值event是:
AppleInterfaceThemeChangedNotificationAppleAquaColorVariantChangedAppleColorPreferencesChangedNotificationAppleShowScrollBarsSettingChanged
systemPreferences.unsubscribeNotification(id) macOS
idInteger
删除订阅者id。
systemPreferences.subscribeLocalNotification(event, callback) macOS
eventStringcallbackFunctioneventStringuserInfoObject
与subscribeNotification相同,但NSNotificationCenter用于本地默认值。这对于诸如NSUserDefaultsDidChangeNotification
systemPreferences.unsubscribeLocalNotification(id) macOS
idInteger
与unsubscribeNotification相同,但将用户从中删除NSNotificationCenter。
systemPreferences.getUserDefault(key, type) macOS
keyStringtypeString - Can bestring,boolean,integer,float,double,url,array,dictionary
返回any- key系统首选项中的值。
此API NSUserDefaults在macOS上使用。一些流行key和types是:
AppleInterfaceStyle:stringAppleAquaColorVariant:integerAppleHighlightColor:stringAppleShowScrollBars:stringNSNavRecentPlaces:arrayNSPreferredWebServices:dictionaryNSUserDictionaryReplacementItems:array
systemPreferences.setUserDefault(key, type, value) macOS
keyStringtypeString - SeegetUserDefaultvalueString
设置key系统偏好设置的值。
请注意,type应该匹配实际类型value。如果不存在,则抛出异常。
此API NSUserDefaults在macOS上使用。一些流行key和types是:
ApplePressAndHoldEnabled:boolean
systemPreferences.isAeroGlassEnabled() Windows
返回Boolean- true如果启用DWM组合(Aero Glass),false否则返回。
使用它来确定是否应创建透明窗口的示例(禁用DWM组合时,透明窗口无法正常工作):
const {BrowserWindow, systemPreferences} = require('electron')
let browserOptions = {width: 1000, height: 800}
// Make the window transparent only if the platform supports it.
if (process.platform !== 'win32' || systemPreferences.isAeroGlassEnabled()) {
browserOptions.transparent = true
browserOptions.frame = false
}
// Create the window.
let win = new BrowserWindow(browserOptions)
// Navigate.
if (browserOptions.transparent) {
win.loadURL(`file://${__dirname}/index.html`)
} else {
// No transparency, so we load a fallback that uses basic styles.
win.loadURL(`file://${__dirname}/fallback.html`)
}systemPreferences.getAccentColor() Windows
返回String- RGBA十六进制格式中的用户当前系统宽带口音颜色首选项。
const color = systemPreferences.getAccentColor() // `"aabbccdd"`
const red = color.substr(0, 2) // "aa"
const green = color.substr(2, 2) // "bb"
const blue = color.substr(4, 2) // "cc"
const alpha = color.substr(6, 2) // "dd"systemPreferences.getColor(color) Windows
color字符串 - 以下值之一:3d-dark-shadow- 三维显示元素的阴影。3d-face- 三维显示元素和对话框背景的面部颜色。3d-highlight- 突出显示三维显示元素的颜色。3d-light- 三维显示元素的浅色。3d-shadow- 三维显示元素的阴影颜色。active-border- 活动窗口边框。active-caption- 活动窗口标题栏。如果启用了渐变效果,则指定活动窗口标题栏的颜色渐变中的左侧颜色。active-caption-gradient- 活动窗口标题栏的颜色渐变中的右侧颜色。app-workspace- 多文档界面(MDI)应用程序的背景颜色。button-text- 按钮上的文字。caption-text- 标题,大小框和滚动条箭头框中的文本。desktop- 桌面背景颜色。disabled-text- 灰色(禁用)文本。highlight- 在控件中选择的项目。highlight-text- 在控件中选择的项目文本。hotlight- 超链接或热追踪项目的颜色。inactive-border- 非活动窗口边框。inactive-caption- 非活动窗口标题。如果启用了渐变效果,则指定非活动窗口标题栏的颜色渐变中的左侧颜色。inactive-caption-gradient- 非活动窗口标题栏的颜色渐变中的右侧颜色。inactive-caption-text- 不活动标题中的文字颜色。info-background- 工具提示控件的背景颜色。info-text- 工具提示控件的文本颜色。menu- 菜单背景。menu-highlight- 当菜单显示为平面菜单时用于突出显示菜单项的颜色。menubar- 当菜单显示为扁平菜单时菜单栏的背景颜色。menu-text- 菜单中的文字。scrollbar- 滚动条灰色区域。window- 窗口背景。window-frame- 窗框。window-text- 窗口中的文本。
返回String- RGB十六进制形式(#ABCDEF)的系统颜色设置。有关更多详细信息,请参阅Windows文档(https://msdn.microsoft.com/en-us/library/windows/desktop/ms724371(v = vs.85%29.aspx)。
systemPreferences.isInvertedColorScheme() Windows
返回Boolean- true如果反转的颜色方案(如高对比度主题)处于活动状态,false则返回。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

