Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cordova-app-loader

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cordova-app-loader - npm Package Compare versions

Comparing version 0.5.2 to 0.6.0

dist/autoupdate.js

10

autoupdate.js

@@ -1,3 +0,1 @@

// Include the bootstrap script.
require('./bootstrap.js');
var CordovaAppLoader = require('./index');

@@ -16,9 +14,9 @@ var CordovaPromiseFS = require('cordova-promise-fs');

// Get SERVER_URL from script tag.
script = document.querySelector('script[manifest]');
script = document.querySelector('script[server]');
if(script){
serverUrl= script.getAttribute('server');
if(!serverUrl) {
throw new Error('Add a "server" attribute to the autoupdate.js script!');
}
}
if(!serverUrl) {
throw new Error('Add a "server" attribute to the autoupdate.js script!');
}

@@ -25,0 +23,0 @@ // Initialize filesystem and loader

4

bower.json
{
"name": "cordova-app-loadaer",
"main": "www/lib/CordovaAppLoader.js",
"version": "0.5.2",
"main": "dist/CordovaAppLoader.js",
"version": "0.6.0",
"homepage": "https://github.com/markmarijnissen/cordova-file-cache",

@@ -6,0 +6,0 @@ "authors": [

{
"name": "cordova-app-loader",
"version": "0.5.2",
"version": "0.6.0",
"description": "Cordova App Loader - remote update your cordova app",

@@ -9,5 +9,7 @@ "main": "index.js",

"cordova-app-loader": "webpack index.js www/lib/CordovaAppLoader.js --output-library CordovaAppLoader --output-library-target var",
"bootstrap": "uglifyjs -m --screw-ie8 bootstrap.js > www/bootstrap.js",
"bootstrap": "cp bootstrap.js www/bootstrap.js",
"autoupdate": "webpack autoupdate.js www/autoupdate.js",
"prepublish": "npm run autoupdate && npm run bootstrap && npm run cordova-promise-fs && npm run cordova-app-loader",
"prepublish": "npm run autoupdate && npm run bootstrap && npm run cordova-promise-fs && npm run cordova-app-loader && npm run copy-to-dist && npm run minify-dist",
"copy-to-dist":"cp www/lib/CordovaAppLoader.js dist/ && cp www/lib/CordovaPromiseFS.js dist/ && cp www/bootstrap.js dist/ && cp www/autoupdate.js dist/",
"minify-dist":" uglifyjs -c -m --screw-ie8 dist/bootstrap.js -o dist/bootstrap.min.js && uglifyjs -c -m --screw-ie8 dist/autoupdate.js -o dist/autoupdate.min.js && uglifyjs -c -m --screw-ie8 dist/CordovaPromiseFS.js -o dist/CordovaPromiseFS.min.js && uglifyjs -c -m --screw-ie8 dist/CordovaAppLoader.js -o dist/CordovaAppLoader.min.js",
"test": "echo \"Error: no test specified\" && exit 1"

@@ -25,4 +27,4 @@ },

"dependencies": {
"cordova-file-cache": "^0.5.0"
"cordova-file-cache": "^0.5.1"
}
}

@@ -52,8 +52,8 @@ cordova-app-loader

* bootstrap.js ([github](https://github.com/markmarijnissen/cordova-app-loader/), [file](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/bootstrap.js)): reads the manifest.json to start your app.
* cordova-app-loader ([github](https://github.com/markmarijnissen/cordova-app-loader/), [file]((https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/lib/CordovaAppLoader.js))): to check,download and update a **manifest.json**
* cordova-promise-fs ([github](https://github.com/markmarijnissen/cordova-promise-fs), [file](https://github.com/markmarijnissen/cordova-app-loader/blob/master/www/lib/CordovaPromiseFS.js)): to deal with the FileSystem
* Promise libary such as bluebird ([github](https://github.com/petkaantonov/bluebird), [file](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/lib/bluebird.js)) or promiscuous ([github](https://github.com/RubenVerborgh/promiscuous),[file](https://raw.githubusercontent.com/RubenVerborgh/promiscuous/master/promiscuous.js))
* **bootstrap.js** ([github](https://github.com/markmarijnissen/cordova-app-loader/), [file](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/bootstrap.js)): reads the manifest.json to start your app.
* **cordova-app-loader** ([github](https://github.com/markmarijnissen/cordova-app-loader/), [file](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/lib/CordovaAppLoader.js)): to check,download and update a **manifest.json**
* **cordova-promise-fs** ([github](https://github.com/markmarijnissen/cordova-promise-fs), [file](https://github.com/markmarijnissen/cordova-app-loader/blob/master/www/lib/CordovaPromiseFS.js)): to deal with the FileSystem
* a **Promise** libary such as bluebird ([github](https://github.com/petkaantonov/bluebird), [file](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/lib/bluebird.js)) or promiscuous ([github](https://github.com/RubenVerborgh/promiscuous),[file](https://raw.githubusercontent.com/RubenVerborgh/promiscuous/master/promiscuous.js))
CordovaAppLoader uses [cordova-file-cache](https://github.com/markmarijnissen/cordova-file-cache) to download and cache the files.
CordovaAppLoader includes [cordova-file-cache](https://github.com/markmarijnissen/cordova-file-cache) to download and cache the files.

@@ -68,3 +68,3 @@ ```bash

1. Write a **manifest.json** (see below)
2. The included **bootstrap.js** script will load your CSS and JS.
2. Include the **bootstrap.js** script to load your CSS and JS from the **manifest.json**
3. Use **CordovaAppLoader** to `check()`, `download()` and `apply()` updates:

@@ -103,15 +103,12 @@

If you don't need full control, you can use a drop-in solution: [autoupdate.js](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/autoupdate.js)
If you don't need full control, you can use a ready-made solution: [autoupdate.js](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/autoupdate.js)
[autoupdate.js](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/autoupdate.js) includes all four files ([bootstrap.js](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/bootstrap.js), [a Promise library](https://raw.githubusercontent.com/RubenVerborgh/promiscuous/master/promiscuous.js),[CordovaPromiseFS.js](https://github.com/markmarijnissen/cordova-app-loader/blob/master/www/lib/CordovaPromiseFS.js) and [CordovaAppLoader.js](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/lib/CordovaAppLoader.js)), initializes everything, and then implements very simple update logic:
[autoupdate.js](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/autoupdate.js) includes everything except the **bootloader.js** ([a Promise library](https://raw.githubusercontent.com/RubenVerborgh/promiscuous/master/promiscuous.js), [CordovaPromiseFS.js](https://github.com/markmarijnissen/cordova-app-loader/blob/master/www/lib/CordovaPromiseFS.js) and [CordovaAppLoader.js](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/lib/CordovaAppLoader.js)).
1. When you open or resume the app (or when you switch tabs in Chrome)
2. Check for updates
3. Download files in the background
3. Update automatically when download is ready.
Autoupdate initializes everything as described above, and automatically updates your app [when you open or resume it](https://github.com/markmarijnissen/cordova-app-loader/blob/master/autoupdate.js#L58).
Here is how to get started:
#### Steps
1. Download [index.html](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/autoupdate.html) to your `www` directory.
2. Download [autoupdate.js](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/autoupdate.js) to your `www` directory.
1. Download [index.html](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/autoupdate.html), [bootstrap.js](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/bootstrap.js) and [autoupdate.js](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/autoupdate.js) to your `www` directory.
2. Write a **manifest.json** (see below). Include `autoupdate.js` in it.
3. Make sure you set the correct options in `index.html`:

@@ -123,8 +120,9 @@ ```html

manifest="manifest.json"
src="autoupdate.js"></script>
src="bootstrap.js"></script>
```
4. Launch your app.
5. Upload a new **manifest.json** (+ files) to your server.
6. Reopen your app to download and apply the update.
4. Write `window.BOOTSTRAP_OK = true` in your code when your app succesfully launches.
5. Launch your app.
6. Upload a new **manifest.json** (+ files) to your server.
7. Reopen your app to download and apply the update.

@@ -136,15 +134,7 @@ This implementation is **not** recommended because:

## Usage
**Note:** You cannot update `bootstrap.js` - therefore `autoupdate.js` is a seperate file. (So you can update `autoupdate` itself).
### Overview
## Manifest.json
1. Write a **manifest.json**
2. Add **bootstrap.js** script to your **index.html**
3. Instantiate a `new CordovaAppLoader()`
4. `check()` for updates
5. `download()` new files
6. `update()` to apply update
### Step 1: Write a manifest.json
### Writing manifest.json
Describe which files to download and which files to load during bootstrap.

@@ -196,8 +186,8 @@

**Workflow tip:**
### Updating manifest.json
You can update your existing manifest like this:
```bash
node bin/update-manifest www www/manifest.json
node bin/update-manifest [root-directory] [manifest.json]
node node_modules/cordova-app-loader/bin/update-manifest www www/manifest.json
node node_modules/cordova-app-loader/bin/update-manifest [root-directory] [manifest.json]
```

@@ -207,4 +197,16 @@

### Step 2: Add [bootstrap.js](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/bootstrap.js) to your [index.html](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/index.html)
Or check out [this gruntfile](https://gist.github.com/lylepratt/d8bf84b3b7d6932e3549).
## Usage
### Overview
1. Add **bootstrap.js** script to your **index.html**
2. Instantiate a `new CordovaAppLoader()`
3. `check()` for updates
4. `download()` new files
5. `update()` to apply update
### Step 1: Add [bootstrap.js](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/bootstrap.js) to your [index.html](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/index.html)
Retrieves manifest.json and dynamically inserts JS/CSS to the current page.

@@ -218,13 +220,13 @@

If after `timeout` milliseconds `window.BOOTSTRAP_OK` is **not** true, the (corrupt?) manifest in localStorage is destroyed, and the page will reload. So make sure you set `window.BOOTSTRAP_OK = true` when your app has succesfully loaded!
Set `window.BOOTSTRAP_OK` to `true` when your app has succesfully launched.
**Tip:**
If your app is updated and `window.BOOTSTRAP_OK` is **not** true after `timeout` milliseconds, the corrupt manifest in localStorage is destroyed, and the page will reload. This will revert the app back to the original manifest.
Bundle a manifest.json with your app. This way, your app will also launch when not connected to the internet. When your app is updated, it will write a new manifest.json to localStorage. If this update is corrupt, it can safely revert to the bundled manifest.json
You should always bundle a manifest.json (+ files) in your app to make sure your app has a "factory default" to revert back to. (And to make sure your app works offline).
### Step 3: Intialize CordovaAppLoader
### Step 2: Intialize CordovaAppLoader
```javascript
// When using NPM, require these first.
// Otherwise these are available as global variables.
// When using bower or when you downloaded the files these are already available as global variables.
var CordovaPromiseFS = require('cordova-promise-fs');

@@ -249,3 +251,3 @@ var CordovaAppLoader = require('cordova-app-loader');

### Step 4: Check for updates
### Step 3: Check for updates

@@ -265,3 +267,3 @@ ```javascript

### Step 5: Download update
### Step 4: Download update

@@ -275,3 +277,3 @@ ```javascript

### Step 6: Apply update (reload page to bootstrap new files)
### Step 5: Apply update (reload page to bootstrap new files)

@@ -292,3 +294,3 @@ This writes the new manifest to localStorage and reloads the page to bootstrap the updated app.

I want CordovaAppLoader to be fast, responsive, reliable and safe. In order to do this, I've made the following decisions:
I want CordovaAppLoader to be fast, responsive, flexible, reliable and safe. In order to do this, I've made the following decisions:

@@ -354,2 +356,15 @@ ### Loading JS/CSS dynamically using bootstrap.js

### Four files for flexibility
Yes, you need to include four files - but this is to create flexibility.
* [bootstrap.js](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/bootstrap.js): This file cannot be updated, so it needs to be a minimal script/css loader.
* [A Promise library](https://raw.githubusercontent.com/RubenVerborgh/promiscuous/master/promiscuous.js): I don't want to enforce a particular Promise library.
* [CordovaPromiseFS.js](https://github.com/markmarijnissen/cordova-app-loader/blob/master/www/lib/CordovaPromiseFS.js): I want to reuse a single `CordovaPromiseFS` instance for the entire app.
* [CordovaAppLoader.js](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/lib/CordovaAppLoader.js): `download()` can slow down performance and `update()` can interrupt the user - you need to decide yourself you want to handle this.
If you don't care about this, you can use [autoupdate.js](https://raw.githubusercontent.com/markmarijnissen/cordova-app-loader/master/www/autoupdate.js) as describe in QuickStart above.
**TODO:** Include `CordovaPromiseFS.js` in the `CordovaAppLoader.js` build, just like the CordovaFileCache. I need to make sure CordovaPromiseFS and CordovaFileCache are globally available then.
### More to be considered?

@@ -359,5 +374,19 @@

## TODO
* Create a demo for **autoupdate.js**
* Include CordovaPromiseFS in the CordovaAppLoader build. Create a default instance if no CordovaPromiseFS instance is passed as option.
* Write automatic tests? (Is this possible?)
* Document and double-check all the urls and paths. (Especially: Do `serverUrl` and `Manifest.root` work together as expected?)
## Changelog
### 0.6.0 (19/11/2014)
* Created a `dist` folder to for all build files
* Fixed a few errors
* Updated readme
* Changed the autoupdate.js implementation (it doesn't include bootstrap.js anymore)
### 0.5.0 (15/11/2014)

@@ -364,0 +393,0 @@

@@ -47,7 +47,5 @@ /******/ (function(modules) { // webpackBootstrap

// Include the bootstrap script.
__webpack_require__(1);
var CordovaAppLoader = __webpack_require__(2);
var CordovaPromiseFS = __webpack_require__(3);
var Promise = __webpack_require__(4);
var CordovaAppLoader = __webpack_require__(1);
var CordovaPromiseFS = __webpack_require__(2);
var Promise = __webpack_require__(3);
window.setImmediate = window.setTimeout;

@@ -63,9 +61,9 @@

// Get SERVER_URL from script tag.
script = document.querySelector('script[manifest]');
script = document.querySelector('script[server]');
if(script){
serverUrl= script.getAttribute('server');
if(!serverUrl) {
throw new Error('Add a "server" attribute to the autoupdate.js script!');
}
}
if(!serverUrl) {
throw new Error('Add a "server" attribute to the autoupdate.js script!');
}

@@ -122,136 +120,3 @@ // Initialize filesystem and loader

(function(){
// Retrieved and slightly modified from: https://github.com/typicode/pegasus
// --------------------------------------------------------------------------
//
// a url (naming it a, beacause it will be reused to store callbacks)
// xhr placeholder to avoid using var, not to be used
window.pegasus = function pegasus(a, xhr) {
xhr = new XMLHttpRequest();
// Open url
xhr.open('GET', a);
// Reuse a to store callbacks
a = [];
// onSuccess handler
// onError handler
// cb placeholder to avoid using var, should not be used
xhr.onreadystatechange = xhr.then = function(onSuccess, onError, cb) {
// Test if onSuccess is a function or a load event
if (onSuccess.call) a = [onSuccess, onError];
// Test if request is complete
if (xhr.readyState == 4) {
// index will be:
// 0 if status is between 0 and 399
// 1 if status is over
cb = a[0|xhr.status / 400];
// Safari doesn't support xhr.responseType = 'json'
// so the response is parsed
if (cb) cb(xhr.status === 200 || xhr.status === 0?JSON.parse(xhr.responseText):xhr);
}
};
// Send
xhr.send();
// Return request
return xhr;
};
//------------------------------------------------------------------
// Step 2: After fetching manifest (localStorage or XHR), load it
function loadManifest(manifest,fromLocalStorage,timeout){
if(!manifest.load) {
console.error('Manifest has nothing to load (manifest.load is empty).',manifest);
return;
}
var el,
head = document.getElementsByTagName('head')[0],
scripts = manifest.load.concat();
// Load Next Script
function loadScript(){
var src = scripts.shift();
if(!src) return;
// Ensure the 'src' has no '/' (it's in the root already)
if(src[0] === '/') src = src.substr(1);
src = manifest.root + src;
// Load javascript
if(src.substr(-3) === ".js"){
el= document.createElement('script');
el.type= 'text/javascript';
el.src= src;
el.onload = loadScript;
// Load CSS
} else {
el= document.createElement('link');
el.rel = "stylesheet";
el.href = src;
el.type = "text/css";
setTimeout(loadScript,0);
}
head.appendChild(el);
}
//---------------------------------------------------
// Step 3: Ensure the 'root' end with a '/'
manifest.root = manifest.root || './';
if(manifest.root.length > 0 && manifest.root[manifest.root.length-1] !== '/')
manifest.root += '/';
// Step 4: Save manifest for next time
if(!fromLocalStorage)
localStorage.setItem('manifest',JSON.stringify(manifest));
// Step 5: Load Scripts
// If we're loading Cordova files, make sure Cordova is ready first!
if(manifest.root.substr(0,7) === 'cdvfile'){
document.addEventListener("deviceready", loadScript, false);
} else {
loadScript();
}
// Save to global scope
window.Manifest = manifest;
// Safety timeout. If BOOTSTRAP_OK is not defined,
// it will delete the 'localStorage' version and revert to factory settings.
if(fromLocalStorage){
setTimeout(function(){
if(!window.BOOTSTRAP_OK){
localStorage.removeItem('manifest');
location.reload();
}
},timeout);
}
}
//---------------------------------------------------------------------
window.Manifest = {};
// Step 1: Load manifest from localStorage
var manifest = JSON.parse(localStorage.getItem('manifest'));
// grab manifest.json location from <script manifest="..."></script>
var s = document.querySelector('script[manifest]');
// Not in localStorage? Fetch it!
if(!manifest){
var url = (s? s.getAttribute('manifest'): null) || 'manifest.json';
// get manifest.json, then loadManifest.
pegasus(url).then(loadManifest,function(xhr){
console.error('Could not download '+url+': '+xhr.status);
});
// Manifest was in localStorage. Load it immediatly.
} else {
loadManifest(manifest,true,s.getAttribute('timeout') || 10000);
}
})();
/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {
var CordovaFileCache = __webpack_require__(5);
var CordovaFileCache = __webpack_require__(4);
var Promise = null;

@@ -412,3 +277,3 @@

/***/ },
/* 3 */
/* 2 */
/***/ function(module, exports, __webpack_require__) {

@@ -867,3 +732,3 @@

/***/ },
/* 4 */
/* 3 */
/***/ function(module, exports, __webpack_require__) {

@@ -1001,6 +866,6 @@

/***/ },
/* 5 */
/* 4 */
/***/ function(module, exports, __webpack_require__) {
var hash = __webpack_require__(6);
var hash = __webpack_require__(5);
var Promise = null;

@@ -1260,3 +1125,3 @@ var isCordova = typeof cordova !== 'undefined';

/***/ },
/* 6 */
/* 5 */
/***/ function(module, exports, __webpack_require__) {

@@ -1263,0 +1128,0 @@

@@ -1,1 +0,128 @@

(function(){window.pegasus=function t(e,o){o=new XMLHttpRequest;o.open("GET",e);e=[];o.onreadystatechange=o.then=function(t,n,s){if(t.call)e=[t,n];if(o.readyState==4){s=e[0|o.status/400];if(s)s(o.status===200||o.status===0?JSON.parse(o.responseText):o)}};o.send();return o};function t(t,e,o){if(!t.load){console.error("Manifest has nothing to load (manifest.load is empty).",t);return}var n,s=document.getElementsByTagName("head")[0],a=t.load.concat();function r(){var e=a.shift();if(!e)return;if(e[0]==="/")e=e.substr(1);e=t.root+e;if(e.substr(-3)===".js"){n=document.createElement("script");n.type="text/javascript";n.src=e;n.onload=r}else{n=document.createElement("link");n.rel="stylesheet";n.href=e;n.type="text/css";setTimeout(r,0)}s.appendChild(n)}t.root=t.root||"./";if(t.root.length>0&&t.root[t.root.length-1]!=="/")t.root+="/";if(!e)localStorage.setItem("manifest",JSON.stringify(t));if(t.root.substr(0,7)==="cdvfile"){document.addEventListener("deviceready",r,false)}else{r()}window.Manifest=t;if(e){setTimeout(function(){if(!window.BOOTSTRAP_OK){localStorage.removeItem("manifest");location.reload()}},o)}}window.Manifest={};var e=JSON.parse(localStorage.getItem("manifest"));var o=document.querySelector("script[manifest]");if(!e){var n=(o?o.getAttribute("manifest"):null)||"manifest.json";pegasus(n).then(t,function(t){console.error("Could not download "+n+": "+t.status)})}else{t(e,true,o.getAttribute("timeout")||1e4)}})();
(function(){
// Retrieved and slightly modified from: https://github.com/typicode/pegasus
// --------------------------------------------------------------------------
//
// a url (naming it a, beacause it will be reused to store callbacks)
// xhr placeholder to avoid using var, not to be used
window.pegasus = function pegasus(a, xhr) {
xhr = new XMLHttpRequest();
// Open url
xhr.open('GET', a);
// Reuse a to store callbacks
a = [];
// onSuccess handler
// onError handler
// cb placeholder to avoid using var, should not be used
xhr.onreadystatechange = xhr.then = function(onSuccess, onError, cb) {
// Test if onSuccess is a function or a load event
if (onSuccess.call) a = [onSuccess, onError];
// Test if request is complete
if (xhr.readyState == 4) {
// index will be:
// 0 if status is between 0 and 399
// 1 if status is over
cb = a[0|xhr.status / 400];
// Safari doesn't support xhr.responseType = 'json'
// so the response is parsed
if (cb) cb(xhr.status === 200 || xhr.status === 0?JSON.parse(xhr.responseText):xhr);
}
};
// Send
xhr.send();
// Return request
return xhr;
};
//------------------------------------------------------------------
// Step 2: After fetching manifest (localStorage or XHR), load it
function loadManifest(manifest,fromLocalStorage,timeout){
if(!manifest.load) {
console.error('Manifest has nothing to load (manifest.load is empty).',manifest);
return;
}
var el,
head = document.getElementsByTagName('head')[0],
scripts = manifest.load.concat();
// Load Next Script
function loadScript(){
var src = scripts.shift();
if(!src) return;
// Ensure the 'src' has no '/' (it's in the root already)
if(src[0] === '/') src = src.substr(1);
src = manifest.root + src;
// Load javascript
if(src.substr(-3) === ".js"){
el= document.createElement('script');
el.type= 'text/javascript';
el.src= src;
el.onload = loadScript;
// Load CSS
} else {
el= document.createElement('link');
el.rel = "stylesheet";
el.href = src;
el.type = "text/css";
setTimeout(loadScript,0);
}
head.appendChild(el);
}
//---------------------------------------------------
// Step 3: Ensure the 'root' end with a '/'
manifest.root = manifest.root || './';
if(manifest.root.length > 0 && manifest.root[manifest.root.length-1] !== '/')
manifest.root += '/';
// Step 4: Save manifest for next time
if(!fromLocalStorage)
localStorage.setItem('manifest',JSON.stringify(manifest));
// Step 5: Load Scripts
// If we're loading Cordova files, make sure Cordova is ready first!
if(manifest.root.substr(0,7) === 'cdvfile'){
document.addEventListener("deviceready", loadScript, false);
} else {
loadScript();
}
// Save to global scope
window.Manifest = manifest;
// Safety timeout. If BOOTSTRAP_OK is not defined,
// it will delete the 'localStorage' version and revert to factory settings.
if(fromLocalStorage){
setTimeout(function(){
if(!window.BOOTSTRAP_OK){
localStorage.removeItem('manifest');
location.reload();
}
},timeout);
}
}
//---------------------------------------------------------------------
window.Manifest = {};
// Step 1: Load manifest from localStorage
var manifest = JSON.parse(localStorage.getItem('manifest'));
// grab manifest.json location from <script manifest="..."></script>
var s = document.querySelector('script[manifest]');
// Not in localStorage? Fetch it!
if(!manifest){
var url = (s? s.getAttribute('manifest'): null) || 'manifest.json';
// get manifest.json, then loadManifest.
pegasus(url).then(loadManifest,function(xhr){
console.error('Could not download '+url+': '+xhr.status);
});
// Manifest was in localStorage. Load it immediatly.
} else {
loadManifest(manifest,true,s.getAttribute('timeout') || 10000);
}
})();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc