Skip to content

Commit

Permalink
Merge 4a98a0a into 3d35be5
Browse files Browse the repository at this point in the history
  • Loading branch information
mircoc authored Jul 12, 2017
2 parents 3d35be5 + 4a98a0a commit e392ed4
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 110 deletions.
114 changes: 81 additions & 33 deletions dist/bower/stargate.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
}(this, function () {
// Public interface
var stargatePackageVersion = "0.12.0";
var stargatePackageVersion = "0.13.5";
var stargatePublic = {};

var stargateModules = {};
Expand Down Expand Up @@ -2940,12 +2940,46 @@ function getAppIsDebug() {
return Promise.resolve({});
}

function getManifestWithCordovaFilePlugin() {
var url = window.cordova.file.applicationDirectory + "www/manifest.json";

return new Promise(function(resolve, reject){
window.resolveLocalFileSystemURL(url, resolve, reject);
})
.then(function(fileEntry) {

return new Promise(function(resolve, reject){
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onerror = reject;
reader.onabort = reject;

reader.onloadend = function() {
var textToParse = this.result;
resolve(textToParse);
};
reader.readAsText(file);
});
});
})
.then(function(fileContent) {
var jsonParsed = '';
try{
jsonParsed = window.JSON.parse(fileContent);
}
catch(e){
return Promise.reject(e);
}

return Promise.resolve(jsonParsed);
})
.catch(function(e) {
console.error("getManifestWithCordovaFilePlugin() error:"+e, e);
});
}

function getManifest() {

if (window.cordova.file) {
return stargateModules.file.readFileAsJSON(window.cordova.file.applicationDirectory + "www/manifest.json");
}

if (window.hostedwebapp) {
return new Promise(function(resolve,reject){
window.hostedwebapp.getManifest(
Expand All @@ -2959,6 +2993,10 @@ function getManifest() {
);
});
}

if (window.cordova.file) {
return getManifestWithCordovaFilePlugin();
}

err("getManifest() no available reading mechanism!");
return Promise.resolve({});
Expand Down Expand Up @@ -3251,7 +3289,13 @@ var onPluginReady = function (resolve) {

codepush.initialize();

push.initialize();
if (hasFeature('localpush')) {
push.initialize()
.catch(function(e) {
err("LocalPush initialization error: "+e, e);
});
}


var modulePromises = [];

Expand Down Expand Up @@ -3354,42 +3398,46 @@ var onDeviceReady = function (resolve, reject) {
// get connection information
initializeConnectionStatus();

// request all asyncronous initialization to complete
Promise.all([
// include here all needed asyncronous initializazion
cordova.getAppVersion.getVersionNumber(),
getManifest(),
cordova.getAppVersion.getPackageName(),
cordova.getAppVersion.getVersionCode(),
getAppIsDebug()
])
.then(function(results) {
// save async initialization result

appVersion = results[0];

var manifest = results[1];
var manifest = '';

if (typeof manifest !== 'object') {
manifest = JSON.parse(results[1]);
getManifest()
.then(function(resultManifest){
log("onDeviceReady() [1/4] got manifest");
if (typeof resultManifest !== 'object') {
resultManifest = JSON.parse(resultManifest);
}

appPackageName = results[2];
appBuild = results[3];

if (results[4] && ( typeof(results[4]) === 'object') ) {
if (results[4].debug) {
appIsDebug = true;
}
}

stargateConf = manifest.stargateConf;
// save stargateConf got from manifest.json
stargateConf = resultManifest.stargateConf;
manifest = resultManifest;

// execute next promise
return cordova.getAppVersion.getVersionNumber();
})
.then(function(resultAppVersionNumber) {
log("onDeviceReady() [2/4] got appVersionNumber");
appVersion = resultAppVersionNumber;

// execute next promise
return cordova.getAppVersion.getPackageName();
})
.then(function(resultAppPackageName){
log("onDeviceReady() [3/4] got appPackageName");
appPackageName = resultAppPackageName;

// execute next promise
return cordova.getAppVersion.getVersionCode();
})
.then(function(resultAppVersionCode){
log("onDeviceReady() [4/4] got appPackageName");
appBuild = resultAppVersionCode;

// multi country support ?
if (manifest.stargateConfCountries) {

getCountryPromise(manifest.stargateConfCountries)
.then(function(countryFromApi) {
log("onDeviceReady() [5/4] got user country");

// check if there is a configuration available
if (manifest.stargateConfCountries[countryFromApi]) {
Expand Down
8 changes: 4 additions & 4 deletions dist/bower/stargate.min.js

Large diffs are not rendered by default.

114 changes: 81 additions & 33 deletions dist/stargate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3935,7 +3935,7 @@
}
}(this, function () {
// Public interface
var stargatePackageVersion = "0.12.0";
var stargatePackageVersion = "0.13.5";
var stargatePublic = {};

var stargateModules = {};
Expand Down Expand Up @@ -6857,12 +6857,46 @@ function getAppIsDebug() {
return Promise.resolve({});
}

function getManifestWithCordovaFilePlugin() {
var url = window.cordova.file.applicationDirectory + "www/manifest.json";

return new Promise(function(resolve, reject){
window.resolveLocalFileSystemURL(url, resolve, reject);
})
.then(function(fileEntry) {

return new Promise(function(resolve, reject){
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onerror = reject;
reader.onabort = reject;

reader.onloadend = function() {
var textToParse = this.result;
resolve(textToParse);
};
reader.readAsText(file);
});
});
})
.then(function(fileContent) {
var jsonParsed = '';
try{
jsonParsed = window.JSON.parse(fileContent);
}
catch(e){
return Promise.reject(e);
}

return Promise.resolve(jsonParsed);
})
.catch(function(e) {
console.error("getManifestWithCordovaFilePlugin() error:"+e, e);
});
}

function getManifest() {

if (window.cordova.file) {
return stargateModules.file.readFileAsJSON(window.cordova.file.applicationDirectory + "www/manifest.json");
}

if (window.hostedwebapp) {
return new Promise(function(resolve,reject){
window.hostedwebapp.getManifest(
Expand All @@ -6876,6 +6910,10 @@ function getManifest() {
);
});
}

if (window.cordova.file) {
return getManifestWithCordovaFilePlugin();
}

err("getManifest() no available reading mechanism!");
return Promise.resolve({});
Expand Down Expand Up @@ -7168,7 +7206,13 @@ var onPluginReady = function (resolve) {

codepush.initialize();

push.initialize();
if (hasFeature('localpush')) {
push.initialize()
.catch(function(e) {
err("LocalPush initialization error: "+e, e);
});
}


var modulePromises = [];

Expand Down Expand Up @@ -7271,42 +7315,46 @@ var onDeviceReady = function (resolve, reject) {
// get connection information
initializeConnectionStatus();

// request all asyncronous initialization to complete
Promise.all([
// include here all needed asyncronous initializazion
cordova.getAppVersion.getVersionNumber(),
getManifest(),
cordova.getAppVersion.getPackageName(),
cordova.getAppVersion.getVersionCode(),
getAppIsDebug()
])
.then(function(results) {
// save async initialization result

appVersion = results[0];

var manifest = results[1];
var manifest = '';

if (typeof manifest !== 'object') {
manifest = JSON.parse(results[1]);
getManifest()
.then(function(resultManifest){
log("onDeviceReady() [1/4] got manifest");
if (typeof resultManifest !== 'object') {
resultManifest = JSON.parse(resultManifest);
}

appPackageName = results[2];
appBuild = results[3];

if (results[4] && ( typeof(results[4]) === 'object') ) {
if (results[4].debug) {
appIsDebug = true;
}
}

stargateConf = manifest.stargateConf;
// save stargateConf got from manifest.json
stargateConf = resultManifest.stargateConf;
manifest = resultManifest;

// execute next promise
return cordova.getAppVersion.getVersionNumber();
})
.then(function(resultAppVersionNumber) {
log("onDeviceReady() [2/4] got appVersionNumber");
appVersion = resultAppVersionNumber;

// execute next promise
return cordova.getAppVersion.getPackageName();
})
.then(function(resultAppPackageName){
log("onDeviceReady() [3/4] got appPackageName");
appPackageName = resultAppPackageName;

// execute next promise
return cordova.getAppVersion.getVersionCode();
})
.then(function(resultAppVersionCode){
log("onDeviceReady() [4/4] got appPackageName");
appBuild = resultAppVersionCode;

// multi country support ?
if (manifest.stargateConfCountries) {

getCountryPromise(manifest.stargateConfCountries)
.then(function(countryFromApi) {
log("onDeviceReady() [5/4] got user country");

// check if there is a configuration available
if (manifest.stargateConfCountries[countryFromApi]) {
Expand Down
10 changes: 5 additions & 5 deletions dist/stargate.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "stargatejs-apps",
"version": "0.12.0",
"version": "0.13.5",
"description": "StargateJS for HTML5 apps",
"main": "dist/stargate.js",
"scripts": {
"preversion": "npm test",
"preversion": "git checkout dist/ && npm test",
"upload": "scp -r dist/*.js super@192.168.124.3:/dadanet2/wl2/webstore_apps/js/webstore_apps/stargate/v4",
"postversion": "git push && git push --tags && npm publish",
"version": "gulp build && git add dist/",
Expand Down
Loading

0 comments on commit e392ed4

Please sign in to comment.