cordova-app-loader
cordova-app-loader copied to clipboard
check() never resolves if cordova-plugin-file is missing
I am having trouble getting this to work and could use some advice on how to debug.
I've just knocked up a tiny simple app.js that does a check(), update(), download(), but it seems that check() never resolves on Android. Running directly in Chrome on desktop everything works as expected.
At the moment I'm just using the prebundled cordova-app-loader-complete.js. There's a call to
Promise.all([gotNewManifest, self.getBundledManifest(), self.cache.list()])
It seems that the self.cache.list() never resolves on Android.
What really confuses me is that nothing is showing up on the server log, even though the cordova app seems to be making successful XHR requests for manifest.json???
In case it helps, my app.js looks like this:
// Initialize a FileSystem
var fs = new CordovaPromiseFS({
Promise: Promise
});
// Initialize a CordovaAppLoader
var loader = new CordovaAppLoader({
fs: fs,
serverRoot: 'http://custard:7771/',
localRoot: 'app',
cacheBuster: true, // make sure we're not downloading cached files.
checkTimeout: 1000 // timeout for the "check" function - when you loose internet connection
});
document.body.innerHTML = '<div id="text"></div><div id="status"></div><button id="checkButton">Check</button><button id="updateButton">Update</button>';
document.getElementById('text').innerHTML = 'hello world 4';
setStatus('initial');
function setStatus(text) {
document.getElementById('status').innerHTML = text;
console.log('setStatus: ' + text);
}
function doCheck() {
setStatus('checking');
// download manifest from: serverRoot+'manifest.json'
loader.check().then(function(updateAvailable) {
if (updateAvailable) {
setStatus('update available');
} else {
setStatus('no update available');
}
}, function (err) {
setStatus('check failed');
console.log('Failed to check: ' + err);
});
}
function doUpdate() {
setStatus('updating');
function onProgress(progress) {
setStatus('progress: ' + progress);
}
loader.download(onProgress).then(function (mainfest) {
setStatus('download complete');
loader.update();
}, function (failedFiles) {
setStatus('failed to download: ' + failedFiles.join(', '));
});
}
document.getElementById('checkButton').addEventListener('click', doCheck);
document.getElementById('updateButton').addEventListener('click', doUpdate);
window.BOOTSTRAP_OK = true;
If anyone could give some tips on what to look for I would really appreciate it!
Thanks.
Ok this is fixed if I add the missing plugins:
cordova plugin add cordova-plugin-file
cordova plugin add cordova-plugin-file-transfer
However, that still doesn't explain why the promise was never resolved. I would have expected it to reject with an error instead of hanging forever. Is there something that can be done about this?
I would expect an error that the FileSystem is never resolved.
I'll see if I can add this to the code.