From b976ace7becc38649f1b7a8833fa9a19e802c81d Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 9 Apr 2014 16:15:38 +0000 Subject: [PATCH] --- js/libs/gal/gal.filesystem.js | 8 ++--- js/libs/gal/gal.js | 55 ++++++++++------------------------- 2 files changed, 19 insertions(+), 44 deletions(-) diff --git a/js/libs/gal/gal.filesystem.js b/js/libs/gal/gal.filesystem.js index 9dbf36d4..c708d4ce 100644 --- a/js/libs/gal/gal.filesystem.js +++ b/js/libs/gal/gal.filesystem.js @@ -1,6 +1,6 @@ /* * Copyright 2011 Google Inc. All Rights Reserved. - + * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -205,12 +205,11 @@ var file = basename_(key); dir.getFile(file, {create: true}, function(fileEntry) { var fileTransfer = new FileTransfer(); - fileTransfer.download(url, fileEntry.fullPath, function(entry) { + fileTransfer.download(url, fileEntry.toURL(), function(entry) { lookupTable[key] = entry.toURL(); entry.setMetadata(function(entry) { - callback(); }, failCallback, {'com.apple.MobileBackup': 1}); - + callback(); }, failCallback); }, failCallback); }); @@ -265,6 +264,7 @@ callback(); }, onError); }); + } if (!gal) { diff --git a/js/libs/gal/gal.js b/js/libs/gal/gal.js index 4eed7ed6..2f965ac2 100644 --- a/js/libs/gal/gal.js +++ b/js/libs/gal/gal.js @@ -1,6 +1,6 @@ /* * Copyright 2011 Google Inc. All Rights Reserved. - + * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -37,9 +37,6 @@ // Array of bundle names in the order that they appear in the manifest. this.bundleOrder = []; // Table of callbacks, per bundle. - this.loadingBundles = {}; - this.loadedBundles = {}; - this.loaded = {}; this.progress = {}; this.error = {}; @@ -60,11 +57,7 @@ * Downloads assets contained in the named bundle. * @param {string} bundleName name of single bundle to download. */ - GAL.prototype.download = function(bundleName, callback, timeout) { - if (timeout == undefined) { - timeout = 0; - } - + GAL.prototype.download = function(bundleName, callback) { var bundle = this.bundles[bundleName]; if (callback == undefined) { callback = function() { @@ -74,7 +67,7 @@ if (!bundle) { // Attempting to download invalid bundle. - throw "Invalid bundle specified"; + throw "Invalid bundle specified :: " + bundleName; } var that = this; @@ -83,15 +76,13 @@ this.check(bundleName, function(result) { if (result.success) { // Already downloaded. Success! - that.loadedBundles[bundleName] = true; - that.loadingBundles[bundleName] = false; fireCallback_(that.loaded, bundleName, { success: true, cached: true, bundleName: bundleName }); - callback(); + } else { if (!that.online()) { // Otherwise, since we're offline, error out. @@ -101,26 +92,20 @@ callback(); } else { // Setup a loop via callback chaining. - that.loadedBundles[bundleName] = false; - that.loadingBundles[bundleName] = true; (function loop(index) { // If we've finished loading all of the assets in the bundle. if (index == bundle.length) { - that.loadedBundles[bundleName] = true; - that.loadingBundles[bundleName] = false; fireCallback_(that.loaded, bundleName, { bundleName: bundleName, success: true }); - setTimeout(function() { - callback(); - }, timeout); + callback(); return; } var key = bundle[index]; // Get the full url to the asset. - var url = that.manifest.assetRoot + key; + var url = encodeURI(that.manifest.assetRoot + key); // Fetch full url and store it locally. that.adapter.saveAsset(key, url, function() { fireCallback_(that.progress, bundleName, { @@ -170,24 +155,15 @@ addCallback_(this.error, opt_bundleName, callback); }; - GAL.prototype.downloadAndCall = function(bundleName, callback, timeoutIfNotLoaded) { + GAL.prototype.downloadAndCall = function(bundleName, callback) { var $this = this; - - if ($this.loadedBundles[bundleName]) { - callback(); - } else if ($this.loadingBundles[bundleName]) { - $this.onLoaded(bundleName, function() { + this.check(bundleName, function(info) { + if (info.success) { callback(); - }); - } else { - this.check(bundleName, function(info) { - if (info.success) { - callback(); - } else { - $this.download(bundleName, callback, timeoutIfNotLoaded); - } - }); - } + } else { + $this.download(bundleName, callback); + } + }); }; /** @@ -299,8 +275,6 @@ // Set this.bundles object and this.bundleOrder array for (var i = 0, bundle; bundle = manifest.bundles[i]; ++i) { this.bundles[bundle.name] = bundle.contents; - this.loadedBundles[bundle.name] = false; - this.loadingBundles[bundle.name] = false; this.bundleOrder.push(bundle.name); } } @@ -317,7 +291,7 @@ this.initAdapter_.call(context, function() { setManifest_.call(context, manifest); // Optionally, start auto-download. - if (manifest.autoDownload && context.online()) { + if (manifest.autoDownload) { downloadAll_.call(context); } callback(); @@ -377,6 +351,7 @@ var that = this; // Start by downloading the first bundle, then download subsequent ones. (function loop(bundleIndex) { + console.log(bundleIndex); if (bundleIndex == that.bundleOrder.length) { // We're done downloading stuff! return; -- 2.39.5