Skip to content
This repository was archived by the owner on May 27, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 31 additions & 34 deletions ionic-deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ angular.module('ionic.service.deploy', ['ionic.service.core'])
// Watch every minute
.constant('WATCH_INTERVAL', 1 * 60 * 1000)

.factory('$ionicGetAppId', [
'$ionicCoreSettings',
'$ionicApp',
function ($ionicCoreSettings, $ionicApp) {
return function getAppId() {
if ($ionicCoreSettings.get('app_id')) {
return $ionicCoreSettings.get('app_id')
} else if ($ionicApp.getApp().app_id) {
return $ionicApp.getApp().app_id
} else {
throw new Error("No ionic app_id found! Please set it via $ionicAppProvider.identify()");
}
}
}])

/**
* @ngdoc service
* @name $ionicDeploy
Expand Down Expand Up @@ -68,17 +83,8 @@ angular.module('ionic.service.deploy', ['ionic.service.core'])
'$ionicCoreSettings',
'WATCH_INTERVAL',
'INITIAL_DELAY',
function($q, $timeout, $rootScope, $ionicApp, $ionicCoreSettings, WATCH_INTERVAL, INITIAL_DELAY) {

var get_ionic_app_id = function() {
if ($ionicCoreSettings.get('app_id')) {
return $ionicCoreSettings.get('app_id')
} else if ($ionicApp.getApp().app_id) {
return $ionicApp.getApp().app_id
} else {
return null;
}
};
'$ionicGetAppId',
function($q, $timeout, $rootScope, $ionicApp, $ionicCoreSettings, WATCH_INTERVAL, INITIAL_DELAY, $ionicGetAppId) {

return {

Expand Down Expand Up @@ -135,7 +141,7 @@ angular.module('ionic.service.deploy', ['ionic.service.core'])
var deferred = $q.defer();

if (typeof IonicDeploy != "undefined") {
IonicDeploy.check(get_ionic_app_id(), this.channel_tag, function(result) {
IonicDeploy.check($ionicGetAppId(), this.channel_tag, function(result) {
console.log("DEBUG DEPLOY: " + result);
if(result && result === "true") {
deferred.resolve(true);
Expand All @@ -160,7 +166,7 @@ angular.module('ionic.service.deploy', ['ionic.service.core'])
var deferred = $q.defer();

if (typeof IonicDeploy != "undefined") {
IonicDeploy.download(get_ionic_app_id(), function(result) {
IonicDeploy.download($ionicGetAppId(), function(result) {
if (result !== 'true' && result !== 'false') {
deferred.notify(result);
} else {
Expand All @@ -184,7 +190,7 @@ angular.module('ionic.service.deploy', ['ionic.service.core'])
var deferred = $q.defer();

if (typeof IonicDeploy != "undefined") {
IonicDeploy.extract(get_ionic_app_id(), function(result) {
IonicDeploy.extract($ionicGetAppId(), function(result) {
if (result !== 'done') {
deferred.notify(result);
} else {
Expand All @@ -205,7 +211,7 @@ angular.module('ionic.service.deploy', ['ionic.service.core'])
*/
load: function() {
if (typeof IonicDeploy != "undefined") {
IonicDeploy.redirect(get_ionic_app_id());
IonicDeploy.redirect($ionicGetAppId());
}
},

Expand All @@ -232,7 +238,7 @@ angular.module('ionic.service.deploy', ['ionic.service.core'])
var deferred = $q.defer();

if (typeof IonicDeploy != "undefined") {
IonicDeploy.info(get_ionic_app_id(), function(result) {
IonicDeploy.info($ionicGetAppId(), function(result) {
deferred.resolve(result);
}, function(err) {
deferred.reject(err);
Expand All @@ -254,28 +260,29 @@ angular.module('ionic.service.deploy', ['ionic.service.core'])
var deferred = $q.defer();

if (typeof IonicDeploy != "undefined") {
var appId = $ionicGetAppId()
// Check for updates
IonicDeploy.check(get_ionic_app_id(), this.channel_tag, function(result) {
IonicDeploy.check(appId, this.channel_tag, function(result) {
if (result === 'true') {
// There are updates, download them
var downloadProgress = 0;
IonicDeploy.download(get_ionic_app_id(), function(result) {
IonicDeploy.download(appId, function(result) {
if (result !== 'true' && result !== 'false') {
// Download is only half of the reported progress
downloadProgress = (result / 2);
deferred.notify(downloadProgress);
} else {
// Download complete, now extract
console.log("Download complete");
IonicDeploy.extract(get_ionic_app_id(), function(result) {
IonicDeploy.extract(appId, function(result) {
if (result !== 'done') {
// Extract is only half of the reported progress
var progress = downloadProgress + (result / 2);
deferred.notify(progress);
} else {
console.log("Extract complete");
// Extraction complete, now redirect
IonicDeploy.redirect(get_ionic_app_id());
IonicDeploy.redirect(appId);
}
}, function(error) {
// Error extracting updates
Expand All @@ -288,7 +295,7 @@ angular.module('ionic.service.deploy', ['ionic.service.core'])
});
} else {
// There are no updates, redirect
IonicDeploy.redirect(get_ionic_app_id());
IonicDeploy.redirect(appId);
}
}, function(error) {
// Error checking for updates
Expand All @@ -303,27 +310,17 @@ angular.module('ionic.service.deploy', ['ionic.service.core'])
}
}])

.run(['$ionicApp', '$ionicCoreSettings', function($ionicApp, $ionicCoreSettings) {
.run(['$ionicApp', '$ionicCoreSettings', '$ionicGetAppId', function($ionicApp, $ionicCoreSettings, $ionicGetAppId) {

document.addEventListener("deviceready", onDeviceReady, false);

var get_ionic_app_id = function() {
if ($ionicCoreSettings.get('app_id')) {
return $ionicCoreSettings.get('app_id')
} else if ($ionicApp.getApp().app_id) {
return $ionicApp.getApp().app_id
} else {
return null;
}
};

function onDeviceReady() {
console.log("Ionic Deploy: Init");
if (typeof IonicDeploy != "undefined") {
if (ionic.Platform.isAndroid()) {
IonicDeploy.init(get_ionic_app_id());
IonicDeploy.init($ionicGetAppId())
} else {
IonicDeploy.redirect(get_ionic_app_id());
IonicDeploy.redirect($ionicGetAppId())
}
}
};
Expand Down