Last active
August 31, 2016 14:55
-
-
Save angel-vladov/422f0f7244c6704375ecac7ec7338eb7 to your computer and use it in GitHub Desktop.
Cordova hook that disables Crosswalk SSL error checks. Otherwise HTTPS doesn't work with Android 5.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
// Disables crosswalk release time SSL errors check | |
// v1.0 | |
// Install mkdirp before using this hook. Run npm install mkdirp --save | |
// Place this file in hooks/after-prepare | |
// Confirmed working with Crosswalk 1.7.2 | |
var fs = require('fs'); | |
var path = require('path'); | |
var mkdirp = require('mkdirp'); | |
var rootdir = process.argv[2]; | |
var crosswalkResourceClient = 'src/org/crosswalk/engine/XWalkCordovaResourceClient.java'; | |
function applyJavaChanges(codePath) { | |
var javaCode = fs.readFileSync(codePath, 'utf8'); | |
javaCode = javaCode.replace(new RegExp('callback.onReceiveValue\\(false\\)', 'g'), 'callback.onReceiveValue(true)'); | |
fs.writeFileSync(codePath, javaCode, 'utf8'); | |
process.stdout.write('Crosswalk onReceivedSslError disabled\n'); | |
} | |
function updateCrosswalkResourceClient() { | |
var codePath = path.join('platforms/android', crosswalkResourceClient); | |
if (fs.existsSync(codePath)) { | |
applyJavaChanges(codePath); | |
} else { | |
throw 'Crosswalk implementation changed. Modify "' + path.basename(process.env.CORDOVA_HOOK) + '".'; | |
} | |
} | |
if (rootdir) { | |
var platforms = (process.env.CORDOVA_PLATFORMS ? process.env.CORDOVA_PLATFORMS.split(',') : []); | |
for(var x = 0; x < platforms.length; x++) { | |
try { | |
var platform = platforms[x].trim().toLowerCase(); | |
if (platform == 'android') { | |
updateCrosswalkResourceClient(); | |
} | |
} | |
catch (e) { | |
process.stdout.write(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment