mirror of
https://gitee.com/shuto-github/phonegap-mobile-accessibility.git
synced 2026-04-19 00:01:32 +08:00
Inject AndroidVox locally when there is no network connection.
The WebView typically injects AndroidVox from a Google server when it launches a page with TalkBack enabled, however, in the unlikely event that the app launches without a network connection and AndroidVox has not been cached from an previous connected session, AndroidVox will not start and the app will be inaccessible. We try to mitigate this by injecting AndroidVox from a local path.
This commit is contained in:
@@ -22,7 +22,9 @@
|
||||
var argscheck = require('cordova/argscheck'),
|
||||
utils = require('cordova/utils'),
|
||||
exec = require('cordova/exec'),
|
||||
device = require('org.apache.cordova.device.device');
|
||||
device = require('org.apache.cordova.device.device'),
|
||||
network = require('org.apache.cordova.network-information.network'),
|
||||
connection = require('org.apache.cordova.network-information.Connection');
|
||||
|
||||
var MobileAccessibility = function() {
|
||||
this._isScreenReaderRunning = false;
|
||||
@@ -95,6 +97,9 @@ MobileAccessibility.prototype.activateOrDeactivateChromeVox = function(bool) {
|
||||
if (typeof cvox === "undefined") {
|
||||
if (bool) {
|
||||
console.warn('A screen reader is running but ChromeVox has failed to initialize.');
|
||||
if (navigator.connection.type === Connection.UNKNOWN || navigator.connection.type === Connection.NONE) {
|
||||
mobileAccessibility.injectLocalAndroidVoxScript();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// activate or deactivate ChromeVox based on whether or not or not the screen reader is running.
|
||||
@@ -106,6 +111,31 @@ MobileAccessibility.prototype.activateOrDeactivateChromeVox = function(bool) {
|
||||
}
|
||||
};
|
||||
|
||||
MobileAccessibility.prototype.scriptInjected = false;
|
||||
MobileAccessibility.prototype.injectLocalAndroidVoxScript = function() {
|
||||
var versionsplit = device.version.split('.');
|
||||
if (device.platform !== "Android" ||
|
||||
!(versionsplit[0] > 4 || (versionsplit[0] == 4 && versionsplit[1] >= 1)) ||
|
||||
typeof cvox !== "undefined" || mobileAccessibility.scriptInjected) return;
|
||||
var script = document.createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.async = true;
|
||||
script.onload = function(){
|
||||
// console.log(this.src + ' has loaded');
|
||||
if (mobileAccessibility.isChromeVoxActive()) {
|
||||
cordova.fireWindowEvent("screenreaderstatuschanged", {
|
||||
isScreenReaderRunning: true
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
script.src = (versionsplit[0] > 4 || versionsplit[1] > 3)
|
||||
? "plugins/com.phonegap.plugin.mobile-accessibility/android/chromeandroidvox.js"
|
||||
: "plugins/com.phonegap.plugin.mobile-accessibility/android/AndroidVox_v1.js";
|
||||
document.getElementsByTagName('head')[0].appendChild(script);
|
||||
mobileAccessibility.scriptInjected = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Asynchronous call to native MobileAccessibility to determine if closed captioning is enabled.
|
||||
* @param {function} callback A callback method to receive the asynchronous result from the native MobileAccessibility.
|
||||
|
||||
Reference in New Issue
Block a user