Yup! I’ll paste my app.js and controller below. (thanks!)
Here’s my app.js:
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'App' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('App', [
'ionic',
'ionic.cloud',
'starter.directives',
'starter.photopickable',
'ngCordova',
'ngAnimate',
'timer',
'pubnub.angular.service',
'angularPayments',
'uiGmapgoogle-maps',
'angular.google.distance',
'vsGoogleAutocomplete',
])
.config(['uiGmapGoogleMapApiProvider', function(uiGmapGoogleMapApiProvider) {
uiGmapGoogleMapApiProvider.configure({
key: '******',
v: '3.23', //defaults to latest 3.X anyhow
libraries: 'weather,geometry,places'
});
}])
.config(function($ionicCloudProvider) {
$ionicCloudProvider.init({
"core": {
"app_id": "****"
}
});
})
.run(['$ionicPlatform',
'$sqliteService',
'$injector',
function($ionicPlatform, $sqliteService, $injector ) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
//Load the Pre-populated database, debug = true
//$sqliteService.preloadDataBase(true);
// Load the Stripe Module
var Environment = $injector.get('Environment');
Stripe.setPublishableKey(Environment.stripe_pk);
});
}
])
.run(['$ionicPlatform',
'$ionicPopup',
function($ionicPlatform, $ionicPopup) {
// Disable BACK button on home
$ionicPlatform.registerBackButtonAction(function(event) {
if (true) { // your check here
$ionicPopup.confirm({
title: 'System warning',
template: 'are you sure you want to exit?'
}).then(function(res) {
if (res) {
ionic.Platform.exitApp();
}
});
}
}, 100);
}
])
// Moved deploy code to appStartController
//.run(['$ionicPopup','$ionicDeploy', '$log', function( $ionicPopup, $ionicDeploy, $log ) {
// $ionicDeploy.check().then( function( updateAvailable ) {
// var originalSnapshots = [];
// var originalInfo;
// alert( 'run...1' );
//
// $ionicDeploy.getSnapshots().then(function(snapshots) {
// // snapshots will be an array of snapshot uuids
// alert( 'run...inside snapshots' );
// originalSnapshots = snapshots;
// $log.log( 'RUN deploy: snapshots',snapshots );
// });
//
// alert( 'run...before info' );
//
// $ionicDeploy.info().then(function( info ) {
// alert( 'run...after info deploy' );
// $log.log( 'RUN info:', info );
// });
//
// alert( 'run...update available', updateAvailable );
//
// if (updateAvailable) {
// $ionicDeploy.download().then(function() {
// $ionicDeploy.extract().then(function() {
// $ionicDeploy.unwatch();
// //$ionicDeploy.getMetadata().then(function(metadata) {});
//
// $ionicPopup.show({
// title: 'Update available',
// subTitle: 'An update was just downloaded. Would you like to restart your app to use the latest features?',
// buttons: [
// { text: 'Not now' },
// {
// text: 'Restart',
// onTap: function(e) {
// $ionicDeploy.load();
// }
// }
// ]
// });
// });
// });
// }
// });
// }
//])
.config(['$httpProvider', function($httpProvider) {
return $httpProvider.interceptors.push("AuthInterceptor");
}])
// .config(['$compileProvider', function($compileProvider) {
// $compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|file|tel|coui):/);
// }])
.config(['$stateProvider',
'$urlRouterProvider',
'$ionicConfigProvider',
'$compileProvider',
function($stateProvider, $urlRouterProvider, $ionicConfigProvider, $compileProvider) {
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|blob|content|ms-appx|x-wmapp0):|data:image\/|img\//);
//$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|file|ftp|mailto|tel|ghttps?|ms-appx|x-wmapp0):/);
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|http|maps|geo|sms|tel|mailto|app|file|ghttps?|ms-appx|x-wmapp0):/);
$ionicConfigProvider.scrolling.jsScrolling(ionic.Platform.isIOS());
$stateProvider
// app loading
.state('app-start', {
url: "/app-start",
templateUrl: "templates/app-start.html",
controller: 'AppStartCtrl'
})
// login screen
.state('auth', {
url: "/auth",
templateUrl: "templates/auth.html",
controller: 'AuthCtrl'
})
// forgot password screen
.state('forgot-password', {
url: '/forgot-password',
templateUrl: 'templates/auth_forgot-password.html',
controller: 'AuthCtrl'
})
// register screen
.state('register', {
url: '/register',
templateUrl: 'templates/auth_register.html',
controller: 'AuthCtrl'
})
//Hauul State
.state('hauul', {
url: '/hauul',
abstract: true,
controller: 'ionSideMenuCtrl',
templateUrl: 'templates/hauul/menu.html'
})
// .state('hauul.home-old', {
// //cache: false,
// url: '/home',
// templateUrl: 'templates/hauul/home.html',
// controller: 'HomeCtrl'
// })
.state('hauul.home', {
//cache: false,
url: '/home',
templateUrl: 'templates/hauul/main-map.html',
controller: 'MainMapCtrl'
})
// Search for a place/ NEW dropoff Location
.state('hauul.places', {
url: '/places',
templateUrl: 'templates/hauul/places.html',
controller: 'PlacesCtrl'
})
// update dropoff location
.state('hauul.places-update-dropoff', {
url: '/places-update-dropoff/:previous_state',
templateUrl: 'templates/hauul/places.html',
controller: 'UpdateDropoffCtrl'
})
.state('hauul.places-modal', {
url: '/places-modal',
templateUrl: 'templates/hauul/modals/places-modal.html',
controller: 'PlacesModalCtrl'
})
// 2017-05-29: Universal Location Picker
.state('hauul.location-picker', {
url: '/location-picker/:role',
templateUrl: 'templates/hauul/location-picker.html',
controller: 'LocationPickerCtrl'
})
// Update uses same view template, but new controller, that sends update to rails, instead of just storing it locally.
.state('hauul.location-picker-update', {
url: '/location-picker-update/:role',
templateUrl: 'templates/hauul/location-picker-update.html',
controller: 'LocationPickerUpdateCtrl'
})
// Choose booking photos
.state('hauul.attach_photo', {
url: '/attach-photo',
templateUrl: 'templates/hauul/attach-photo.html',
controller: 'AttachPhotoCtrl'
})
// Add Booking Info
.state('hauul.add_description', {
url: '/add-description',
templateUrl: 'templates/hauul/add-description.html',
controller: 'AddDescriptionCtrl'
})
// Choose payment method
.state('hauul.payment_method', {
url: '/payment-method',
templateUrl: 'templates/hauul/payment-method.html',
controller: 'PaymentMethodCtrl'
})
// Add Payment method
.state('hauul.payment_method_add', {
url: '/payment_method_add',
templateUrl: 'templates/hauul/payment-method-add.html',
controller: 'PaymentMethodAddCtrl'
})
// Find a driver
.state('hauul.finding', {
url: '/finding',
templateUrl: 'templates/hauul/finding.html',
controller: 'FindingCtrl'
})
// Show driver profile
.state('hauul.driver', {
url: '/driver',
templateUrl: 'templates/hauul/driver.html',
controller: 'DriverCtrl'
})
// Tracking driver position
.state('hauul.tracking', {
url: '/tracking',
templateUrl: 'templates/hauul/tracking.html',
controller: 'TrackingCtrl'
})
// Show history
.state('hauul.history', {
url: '/history&page=:page',
templateUrl: 'templates/hauul/history-list.html',
controller: 'HistoryListCtrl'
})
.state('hauul.history_trip_id', {
url: '/history/page=:page/trip_id=:trip_id',
templateUrl: 'templates/hauul/history.html',
controller: 'HistoryCtrl'
})
// Show notifications
.state('hauul.notification', {
url: '/notification',
templateUrl: 'templates/hauul/notification.html',
controller: 'NotificationCtrl'
})
// Support form
.state('hauul.support', {
url: '/support',
templateUrl: 'templates/hauul/support.html',
controller: 'SupportCtrl'
})
// Profile page
.state('hauul.profile', {
url: '/profile',
templateUrl: 'templates/hauul/profile.html',
controller: 'ProfileCtrl'
})
// Legal page
.state('hauul.legal', {
url: '/legal',
templateUrl: 'templates/hauul/legal.html',
controller: 'LegalCtrl'
})
// template app states:
.state('app', {
url: '/app',
abstract: true,
controller: 'AppController',
templateUrl: 'templates/menu.html'
})
.state('app.gallery', {
url: "/gallery",
cache: false,
views: {
viewContent: {
templateUrl: "templates/gallery.html",
controller: 'GalleryController'
}
}
})
.state('app.item', {
url: "/item/{title}",
params: {
color: null,
icon: null
},
cache: false,
views: {
viewContent: {
templateUrl: "templates/item.html",
controller: 'ItemController'
}
}
});
$urlRouterProvider.otherwise(function($injector, $location) {
var $state = $injector.get("$state");
$state.go("app-start");
});
}
]);
And here’s the controller:
(function() {
var AppStartCtrl = function ($scope, $log, $state, $ionicHistory, $ionicPopup, $ionicDeploy ) {
$log.log( "AppStartCtrl: Initialized..." );
$ionicDeploy.check().then(function (snapshotAvailable) {
if (snapshotAvailable) {
// When snapshotAvailable is true, you can apply the snapshot
$ionicDeploy.download().then(function () {
console.log( "deploy extracting..." );
return $ionicDeploy.extract();
}).then(function () {
console.log( "deploy.load()..." );
$ionicPopup.show({
title: 'Update available',
subTitle: 'An update was just downloaded. New features will be available when you restart the app.',
buttons: [
{ text: 'Not now' },
{
text: 'Restart',
onTap: function(e) {
$ionicDeploy.load();
}
}
]
});
//$ionicDeploy.load();
});
} else {
// No updates found, delete old snapshots now
$ionicDeploy.info().then(function (info) {
$ionicDeploy.getSnapshots().then(function (snapshots) {
// snapshots will be an array of snapshot uuids
angular.forEach(snapshots, function (value, key) {
if (value !== undefined && value !== info.deploy_uuid) {
console.log("Deleting snapshot", value);
$ionicDeploy.deleteSnapshot(value);
}
});
// You app logic starts here, in my case it's just loading the "login" state
});
});
}
});
};
AppStartCtrl.$inject = ['$scope', '$log', '$state', '$ionicHistory', '$ionicPopup','$ionicDeploy' ];
angular.module('App')
.controller( 'AppStartCtrl', AppStartCtrl);
}());