cordova-app-loader
Remote update your Cordova App
Getting started
bower install cordova-app-loader cordova-promise-fs
npm install cordova-app-loader cordova-promise-fs
cordova platform add ios@3.7.0
cordova plugin add org.apache.cordova.file
cordova plugin add org.apache.cordova.file-transfer
IMPORTANT: For iOS, use Cordova 3.7.0 or higher (due to a bug that affects requestFileSystem).
Or just download and include CordovaPromiseFS.js and CordovaFileCache.js
Demo
git clone git@github.com:markmarijnissen/cordova-app-loader.git
cd cordova-app-loader
cordova platform add ios@3.7.0
cordova plugin add org.apache.cordova.file
cordova plugin add org.apache.cordova.file-transfer
cordova serve
cordova run ios
If you want to run on a real device, modify serverRoot
in www/test/test.js
to point to your local server!
Usage
Step 1: Write a manifest.json
{
"files":{
"lib/jquery.min.js": { "version": 0 },
"lib/bluebird.js": { "version": 0 },
"lib/CordovaPromiseFS.js": { "version": 0 },
"lib/CordovaAppLoader.js": { "version": 0 },
"test/template.html": {"version": 0},
"test/test.js": { "version": 0 },
"update2/index.js": { "version": 2 },
"update2/style2.css": { "version": 2 }
},
"load":[
"lib/jquery.min.js",
"lib/bluebird.js",
"lib/CordovaPromiseFS.js",
"lib/CordovaAppLoader.js",
"test/test.js",
"update2/index.js",
"update2/style2.css"
]
}
<script type="text/javascript" timeout="5000" manifest="update1/manifest.json" src="bootstrap.js"></script>
- The
manifest.json
is downloaded once. Second time it is retrieved from localStorage. - Javascript and CSS is inserted on the page.
- Your javascript codes calls
window.BOOTSTRAP_OK = true
to indicate bootstrap was a success. - If the manifest is updated and fails to bootstrap the app after
timeout
milliseconds, the manifest in localStorage is deleted and the app reloads the original manifest (and application).
Notes:
- The
manifest
attribute should point to a local manifest (i.e. bundled with the app) to guarantee the app can bootstrap even without internet connection. - Don't forget to set
BOOTSTRAP_OK
to true
!
Step 3: Use CordovaAppLoader to check
, download
and update
your app.
var fs = new CordovaPromiseFS({});
var loader = window.loader = new CordovaAppLoader({
fs: fs,
localRoot: 'app',
mode: 'mirror'
});
loader.check().then( ... )
loader.check('http://yourserver.com/manifest.json').then( ... )
loader.check({ files: { ... } }).then( ... )
loader.download(onprogress).then(function(manifest){},function(failedDownloadUrlArray){ ... });
loader.update()
Note: When downloading and updating, the new manifest is written to localStorage. The manifest.root
is set to the location of the downloaded files. (Default is ""
- i.e. it loads files relative to your index.html
)
Changelog
0.1.0 (07/11/2014)
Contribute
Convert CommonJS to a browser-version:
npm install webpack -g
npm run-script prepublish
Feel free to contribute to this project in any way. The easiest way to support this project is by giving it a star.
Contact
© 2014 - Mark Marijnissen