Catch javascript errors when cvox.ChromeVox.tts.stop is unavailable

refactor activateOrDeactivateChromeVox into a separate method.
This commit is contained in:
Michael Jordan 2014-02-10 21:36:35 -05:00
parent ea97c1faa1
commit b0016ab0df

View File

@ -81,16 +81,7 @@ MobileAccessibility.onHasSubscribersChange = function() {
*/
MobileAccessibility.prototype.isScreenReaderRunning = function(callback) {
exec(function(bool) {
if (device.platform==="Android") {
if (typeof cvox === "undefined") {
if (bool) {
console.warn('A screen reader is running but ChromeVox has failed to initialize.');
}
} else {
// activate or deactivate ChromeVox based on whether or not or not the screen reader is running.
cvox.ChromeVox.host.activateOrDeactivateChromeVox(bool);
}
}
mobileAccessibility.activateOrDeactivateChromeVox(bool);
callback(Boolean(bool));
}, null, "MobileAccessibility", "isScreenReaderRunning", []);
};
@ -99,6 +90,21 @@ MobileAccessibility.prototype.isTalkBackRunning = MobileAccessibility.prototype.
MobileAccessibility.prototype.isChromeVoxActive = function () {
return typeof cvox !== "undefined" && cvox.ChromeVox.host.ttsLoaded() && cvox.Api.isChromeVoxActive();
};
MobileAccessibility.prototype.activateOrDeactivateChromeVox = function(bool) {
if (device.platform !== "Android") return;
if (typeof cvox === "undefined") {
if (bool) {
console.warn('A screen reader is running but ChromeVox has failed to initialize.');
}
} else {
// activate or deactivate ChromeVox based on whether or not or not the screen reader is running.
try {
cvox.ChromeVox.host.activateOrDeactivateChromeVox(bool);
} catch (err) {
console.error(err);
}
}
};
/**
* Asynchronous call to native MobileAccessibility to determine if closed captioning is enabled.
@ -195,16 +201,7 @@ MobileAccessibility.prototype.stop = function() {
*/
MobileAccessibility.prototype._status = function(info) {
if (info) {
if (device.platform === "Android") {
if (typeof cvox === "undefined") {
if (info.isScreenReaderRunning) {
console.warn('A screen reader is running but ChromeVox has failed to initialize.');
}
} else {
// activate or deactivate ChromeVox based on whether or not or not the screen reader is running.
cvox.ChromeVox.host.activateOrDeactivateChromeVox(info.isScreenReaderRunning);
}
}
mobileAccessibility.activateOrDeactivateChromeVox(info.isScreenReaderRunning);
if (mobileAccessibility._isScreenReaderRunning !== info.isScreenReaderRunning) {
cordova.fireWindowEvent("screenreaderstatuschanged", info);
mobileAccessibility._isScreenReaderRunning = info.isScreenReaderRunning;