Try to load from assets in case we don't have manifest on FS

Has problems with scripts load ordering
This commit is contained in:
Slava Kim
2014-08-14 21:01:31 -07:00
parent 5fbe4aea66
commit 09cd163a2b
4 changed files with 32 additions and 44 deletions

View File

@@ -41,7 +41,6 @@ var onNewVersion = function (handle) {
// save the manifest
uri = encodeURI(urlPrefix + '/manifest.json');
ft.download(uri, localPathPrefix + '/manifest.json', function () {
console.log('done');
Package.reload.Reload._reload();
});
}

View File

@@ -50,7 +50,8 @@ Boilerplate.prototype._generateBoilerplateFromManifestAndSource =
css: [],
js: [],
head: '',
body: ''
body: '',
meteorManifest: JSON.stringify(manifest)
};
// allow the caller to extend the default base data

View File

@@ -5,41 +5,25 @@
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi">
<meta name="msapplication-tap-highlight" content="no">
{{#each css}}
{{#if inline}}
<style type="text/css"> {{{ scriptContent }}} </style>
{{else}}
<link rel="stylesheet" href="{{url}}">
{{/if}}
{{/each}}
<script type='text/javascript'>
__meteor_runtime_config__ = {{meteorRuntimeConfig}};
if (/Android/i.test(navigator.userAgent)) {
// When Android app is emulated, it cannot connect to localhost,
// instead it should connect to 10.0.2.2
__meteor_runtime_config__.ROOT_URL = (__meteor_runtime_config__.ROOT_URL || '').replace(/localhost/i, '10.0.2.2');
__meteor_runtime_config__.DDP_DEFAULT_CONNECTION_URL = (__meteor_runtime_config__.DDP_DEFAULT_CONNECTION_URL || '').replace(/localhost/i, '10.0.2.2');
}
__meteor_manifest__ = {{meteorManifest}};
</script>
<script type="text/javascript" src="cordova.js"></script>
{{#if includeCordova}}
<script type="text/javascript" src="meteor_cordova_loader.js"></script>
{{/if}}
{{#each js}}
{{#if inline}}
<script type="text/javascript"> {{{ scriptContent }}} </script>
{{else}}
<script type="text/javascript" src="{{url}}"></script>
{{/if}}
{{/each}}
<script type="text/javascript" src="meteor_cordova_loader.js"></script>
{{{head}}}
</head>
<body style="display: none">
<body>
{{{body}}}
</body>
</html>

View File

@@ -39,6 +39,7 @@
var COUNTER = 0;
var loadScript = function (url) {
console.log('loadscript ' + url)
var scriptTag = document.createElement('script');
scriptTag.type = "text/javascript";
scriptTag.src = url;
@@ -52,12 +53,26 @@
};
var loadStyle = function (url) {
var scriptTag = document.createElement('link');
scriptTag.rel = "stylesheet";
scriptTag.type = "text/css";
scriptTag.href = url;
scriptTag.type = "text/javascript";
document.getElementsByTagName('head')[0].appendChild(scriptTag);
var styleTag = document.createElement('link');
styleTag.rel = "stylesheet";
styleTag.type = "text/css";
styleTag.href = url;
document.getElementsByTagName('head')[0].appendChild(styleTag);
};
var loadAssetsFromManifest = function (manifest, urlPrefix) {
each(manifest, function (item) {
if (item.type === 'js') {
COUNTER++;
}
});
each(manifest, function (item) {
if (item.type === 'js')
loadScript(urlPrefix + item.url.substring(1));
else if (item.type === 'css')
loadStyle(urlPrefix + item.url.substring(1));
});
};
document.addEventListener("deviceready", function () {
@@ -66,26 +81,15 @@
function (err, res) {
if (! err) {
var manifest = JSON.parse(res).manifest;
each(manifest, function (item) {
if (item.type==='js')
COUNTER++;
});
each(manifest, function (item) {
if (item.type === 'js')
loadScript(localPathPrefix + item.url);
else if (item.type === 'css')
loadStyle(localPathPrefix + item.url);
});
loadAssetsFromManifest(manifest, localPathPrefix + '/');
} else {
// We don't have any new versions, default to the bundled assets.
console.log(err.message);
console.log('Couldn\'t load from the manifest, falling back to the bundled assets.');
}
loadScript('document.dispatchEvent(evt);', true);
document.getElementsByTagName('body')[0].removeAttribute('style'); // XXX remove this?
loadAssetsFromManifest(__meteor_manifest__, '');
}
});
}, false);
})();