Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #383 from vIiRuS/master
Browse files Browse the repository at this point in the history
Add Update notification and killswitch option
  • Loading branch information
crookedneighbor committed Aug 15, 2015
2 parents 98afe53 + ee2329a commit d49d383
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
"cordovaPlatforms": [
"ios"
]
}
}
99 changes: 73 additions & 26 deletions scripts/controllers/rootCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
// Make user and settings available for everyone through root scope.
habitrpg.controller('RootCtrl',
['$scope', '$rootScope', '$location', '$ionicNavBarDelegate', 'User', '$state', '$stateParams', '$window', '$ionicPlatform', 'Groups', 'ApiUrl', '$http', 'API_URL',
'$ionicPopup',
function ($scope, $rootScope, $location, $ionicNavBarDelegate, User, $state, $stateParams, $window, $ionicPlatform, Groups, ApiUrl, $http, API_URL, $ionicPopup) {
'$ionicPopup', '$ionicModal',
function ($scope, $rootScope, $location, $ionicNavBarDelegate, User, $state, $stateParams, $window, $ionicPlatform, Groups, ApiUrl, $http, API_URL, $ionicPopup, $ionicModal) {

$rootScope.User = User;
$rootScope.user = User.user;
$rootScope.set = User.set;
$rootScope.settings = User.settings;
$rootScope.settings.auth.apiEndpoint = API_URL;

$rootScope.postData = function(endpoint, data){
return $http.post(ApiUrl.get()+endpoint, data);
};
Expand Down Expand Up @@ -84,31 +84,78 @@ habitrpg.controller('RootCtrl',
}


if($ionicPlatform.is('ios'))
{
var versionToCheck = ionic.Platform.version().toString();

var splittedVersion = versionToCheck.split('.');

if(splittedVersion[0] == '7' || splittedVersion[0] == '8' || splittedVersion[0] == '9')
{
var confirmPopup = $ionicPopup.confirm({
title: 'Update',
template: 'We’ve released an improved, updated app: Habitica! This old app is no longer supported. Click "Open Store" to download the new app now.',

okText: 'Open Store' // String (default: 'OK'). The text of the OK button.
});

confirmPopup.then(function(res) {
if(res) {
// open url
$rootScope.externalLink('itms://itunes.apple.com/us/app/habitica/id994882113');
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://habitica-assets.s3.amazonaws.com/mobileApp/endpoint/killswitch.json", true);
xhr.onload = function (e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var response = JSON.parse(xhr.responseText);
if ($ionicPlatform.is('ios')) {
var platformData = response.ios;
} else if ($ionicPlatform.is('android')) {
var platformData = response.android;
} else {
// Cancel
return;
}
});
if (platformData.killswitch) {
$ionicModal.fromTemplateUrl('views/app.modals.killswitch.html', {
scope: $scope,
}).then(function(modal) {
$scope.modal = modal
$scope.killswitchMessage = platformData.killswitchMessage
$scope.storeUrl = platformData.storeUrl
$scope.modal.show()
})
} else if (platformData.warning) {
var confirmPopup = $ionicPopup.confirm({
title: 'Warning',
template: platformData.warningMessage,

okText: 'Open Store' // String (default: 'OK'). The text of the OK button.
});

confirmPopup.then(function(res) {
if(res) {
// open url
$rootScope.externalLink(platformData.storeUrl);
} else {
// Cancel
}
});
} else if (platformData.newApp) {
if($ionicPlatform.is('ios')) {
var versionToCheck = ionic.Platform.version().toString();

var splittedVersion = versionToCheck.split('.');

if(splittedVersion[0] == '7' || splittedVersion[0] == '8' || splittedVersion[0] == '9') {
var confirmPopup = $ionicPopup.confirm({
title: 'Update',
template: 'We’ve released an improved, updated app: Habitica! This old app will no longer receive updates. Click "Open Store" to download the new app now.',

okText: 'Open Store' // String (default: 'OK'). The text of the OK button.
});

confirmPopup.then(function(res) {
if(res) {
// open url
$rootScope.externalLink(platformData.storeUrl);
} else {
// Cancel
}
});
}
} else if ($ionicPlatform.is('android')) {
}
}
} else {
console.error(xhr.statusText);
}
}
}

};
xhr.onerror = function (e) {
console.error(xhr.statusText);
};
xhr.send(null);
}
]);
9 changes: 9 additions & 0 deletions views/app.jade
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ script(id='views/app.html',type='text/ng-template')
output.queueLengthReporter {{queueLength()}}
script(id='views/app.modals.killswitch.html',type='text/ng-template')
.modal
ion-header-bar
h1.title Error
ion-content
.padding
{{killswitchMessage}}
.padding
a.button.button-block.button-stable(href=storeUrl) Go to App Store

0 comments on commit d49d383

Please sign in to comment.