From b2c25c351e17ffdca9d26e1b8396c911db14db20 Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Fri, 9 Sep 2016 16:59:37 -0400 Subject: #321 - add ability to automatically switch based on network connection Former-commit-id: bad04bbef6839c949aad05fb34eee61c64947070 --- www/js/DataModel.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'www/js/DataModel.js') diff --git a/www/js/DataModel.js b/www/js/DataModel.js index 11451916..ee69b09c 100644 --- a/www/js/DataModel.js +++ b/www/js/DataModel.js @@ -2,7 +2,7 @@ /* jslint browser: true*/ -/* global cordova,StatusBar,angular,console, URI, moment, localforage, CryptoJS */ +/* global cordova,StatusBar,angular,console, URI, moment, localforage, CryptoJS, Connection */ // This is my central data respository and common functions // that many other controllers use @@ -109,6 +109,7 @@ angular.module('zmApp.controllers') 'cycleMonitors': false, 'cycleMonitorsInterval':10, // 10sec 'enableLowBandwidth':false, + 'autoSwitchBandwidth':false, @@ -691,12 +692,28 @@ angular.module('zmApp.controllers') } + if (typeof loginData.enableLowBandwidth == 'undefined') { + loginData.enableLowBandwidth = false; } - $rootScope.runMode = loginData.enableLowBandwith? "low": "normal"; + // wtf is wrong with this ternary? + //$rootScope.runMode = (loginData.enableLowBandwith==true)? "low": "normal"; + + + + + if (typeof loginData.autoSwitchBandwidth == 'undefined') { + + + loginData.autoSwitchBandwidth = false; + + } + + + if (typeof loginData.refreshSecLowBW == 'undefined') { @@ -1079,6 +1096,33 @@ angular.module('zmApp.controllers') }, + //-------------------------------------------------------------------------- + // returns high or low BW mode + //-------------------------------------------------------------------------- + getBandwidth: function () { + // if mode is not on always return high + if (loginData.enableLowBandwidth == false) + { + return "highbw"; + } + // if mode is force on, return low + if (loginData.enableLowBandwidth == true && loginData.autoSwitchBandwidth != true) + { + return "lowbw"; + } + // else return real state + var networkState = navigator.connection.type; + var strState; + switch (networkState) + { + + case Connection.WIFI: strState="highbw"; break; + case Connection.ETHERNET: strState="highbw"; break; + default: strState = "lowbw"; break; + + } + return strState; + }, //-------------------------------------------------------------------------- // This is really a hack for now & is very ugly. I need to clean this up a lot -- cgit v1.2.3