跳到主内容

辅助功能

为程序制作辅助功能是很重要的。在这里,我们很高兴地向你们介绍DevtronSpectron。这两个新功能有机会使开发者们让他们的应用程序更加可用。


Electron 应用中有关辅助功能的开发和网站是相似的,因为两者最终使用的都是HTML. 然而, 对于Electron应用, 你不能使用在线的辅助功能审查者, 因为你的应用没有一个URL可以提供给审查者.

这些功能将会提供一些审查工具给你的Electron 应用。 您可以选择使用 Spectron 将审查添加到你的测试环境中,或在开发者工具(DevTools)中使用Devtron。 详见各工具的文档.

Spectron#

In the testing framework Spectron, you can now audit each window and <webview> tag in your application. 例如:

app.client.auditAccessibility().then(function (audit) {  if (audit.failed) {    console.error(audit.message)  }})

你可以从这里Spectron文档阅读到更多有关于这个功能的信息。

Devtron#

In Devtron, there is an accessibility tab which will allow you to audit a page in your app, sort and filter the results.

devtron 截图

这两种工具都使用了Google 为 Chrome 所构建的 辅助功能开发工具 库。 您可以在 repository's wiki 上了解到更加详细的辅助功能审核规则。

如果你知道其他适用于Electron的辅助功能开发工具, 请通过pull request添加到本文档中.

Manually enabling accessibility features#

当辅助技术存在时,Electron 应用程序将自动启用辅助功能(例如 Windows 上的 JAWS 或 macOS 上的 VoiceOver)。 有关详细信息, 请参阅 Chrome 的 辅助功能文档

You can also manually toggle these features either within your Electron application or by setting flags in third-party native software.

使用 Electron 的 API#

通过使用 app.setAccessibilitySupportEnabled(enabled) API,您可以在应用程序首选项中的手动向用户暴露Chrome的访问树。 请注意,用户的系统辅助工具优先于此设置并将覆盖它。

在第三方软件内#

macOS#

On macOS, third-party assistive technology can toggle accessibility features inside Electron applications by setting the AXManualAccessibility attribute programmatically:

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);}