Skip to main content

Accessibility可达性

Accessibility concerns in Electron applications are similar to those of websites because they're both ultimately HTML.Electron应用程序中的可访问性问题类似于网站,因为它们最终都是HTML。

Manually enabling accessibility features手动启用辅助功能

Electron applications will automatically enable accessibility features in the presence of assistive technology (e.g. JAWS on Windows or VoiceOver on macOS). Electron应用程序将自动启用辅助技术(如Windows上的JAWS或macOS上的VoiceOver)的辅助功能。See Chrome's accessibility documentation for more details.有关更多详细信息,请参阅Chrome的可访问性文档

You can also manually toggle these features either within your Electron application or by setting flags in third-party native software.您还可以在Electron应用程序中或通过在第三方本机软件中设置标志手动切换这些功能。

Using Electron's API使用Electron的API

By using the app.setAccessibilitySupportEnabled(enabled) API, you can manually expose Chrome's accessibility tree to users in the application preferences. 通过使用app.setAccessibilitySupportEnabled(enabled)API,您可以在应用程序首选项中手动向用户公开Chrome的可访问性树。Note that the user's system assistive utilities have priority over this setting and will override it.请注意,用户的系统辅助实用程序优先于此设置,并将覆盖此设置。

Within third-party software第三方软件内

macOS

On macOS, third-party assistive technology can toggle accessibility features inside Electron applications by setting the AXManualAccessibility attribute programmatically:在macOS上,第三方辅助技术可以通过编程方式设置AXManualAccessibility属性来切换Electron应用程序中的辅助功能:

CFStringRef kAXManualAccessibility = CFSTR("AXManualAccessibility");

+ (void)enableAccessibility:(BOOL)enable inElectronApplication:(NSRunningApplication *)app
{
AXUIElementRef appRef = AXUIElementCreateApplication(app.processIdentifier);
if (appRef == nil)
return;

CFBooleanRef value = enable ? kCFBooleanTrue : kCFBooleanFalse;
AXUIElementSetAttributeValue(appRef, kAXManualAccessibility, value);
CFRelease(appRef);
}