Skip to content

Commit

Permalink
keep track globally of whether the user has network access #69
Browse files Browse the repository at this point in the history
  • Loading branch information
bsenyk committed Feb 3, 2016
1 parent 27319d6 commit 2bfecac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
15 changes: 14 additions & 1 deletion platforms/android/assets/www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// the 2nd parameter is an array of 'requires'
// 'starter.controllers' is found in controllers.js
angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter.services'])
.run(function($state, $window, LaunchService, $ionicPlatform, DBService) {
.run(function($state, $window, $rootScope, $cordovaNetwork, LaunchService, $ionicPlatform, DBService) {
$ionicPlatform.ready(function() {

// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
Expand All @@ -20,6 +20,19 @@ angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter
StatusBar.styleDefault();
}

$window.isOnline = $cordovaNetwork.isOnline();


// listen for Online event
$rootScope.$on('$cordovaNetwork:online', function(event, networkState){
$window.isOnline = true;
})

// listen for Offline event
$rootScope.$on('$cordovaNetwork:offline', function(event, networkState){
$window.isOnline = false;
})

$window.addEventListener('CustomURLFollow', function(e) {
if(LaunchService.checkUrl(e.detail.url)) {
$window.skipToUnit = LaunchService.get();
Expand Down
15 changes: 14 additions & 1 deletion www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// the 2nd parameter is an array of 'requires'
// 'starter.controllers' is found in controllers.js
angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter.services'])
.run(function($state, $window, LaunchService, $ionicPlatform, DBService) {
.run(function($state, $window, $rootScope, $cordovaNetwork, LaunchService, $ionicPlatform, DBService) {
$ionicPlatform.ready(function() {

// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
Expand All @@ -20,6 +20,19 @@ angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter
StatusBar.styleDefault();
}

$window.isOnline = $cordovaNetwork.isOnline();


// listen for Online event
$rootScope.$on('$cordovaNetwork:online', function(event, networkState){
$window.isOnline = true;
})

// listen for Offline event
$rootScope.$on('$cordovaNetwork:offline', function(event, networkState){
$window.isOnline = false;
})

$window.addEventListener('CustomURLFollow', function(e) {
if(LaunchService.checkUrl(e.detail.url)) {
$window.skipToUnit = LaunchService.get();
Expand Down

0 comments on commit 2bfecac

Please sign in to comment.