diff options
| author | Pliable Pixels <pliablepixels@gmail.com> | 2018-05-31 08:21:51 -0400 |
|---|---|---|
| committer | Pliable Pixels <pliablepixels@gmail.com> | 2018-05-31 08:21:51 -0400 |
| commit | 49263c5ddd92c4374b23cff4273c1e6460823f80 (patch) | |
| tree | 757fbd96ffdb3bc4d8856bc444a06cc0aa9447c0 /www/js | |
| parent | fd3b8ae2015b8071cb89bd5831ebcfffda3f1709 (diff) | |
#636 introduce DB get/set checks
Diffstat (limited to 'www/js')
| -rwxr-xr-x | www/js/DataModel.js | 126 | ||||
| -rw-r--r-- | www/js/LoginCtrl.js | 6 | ||||
| -rwxr-xr-x | www/js/app.js | 142 |
3 files changed, 175 insertions, 99 deletions
diff --git a/www/js/DataModel.js b/www/js/DataModel.js index 3993ebbb..b5abe67f 100755 --- a/www/js/DataModel.js +++ b/www/js/DataModel.js @@ -514,33 +514,33 @@ angular.module('zmApp.controllers') //var d = $q.defer(); // if we are here, we should remove cache - localforage.removeItem("settings-temp-data"); + loginData = angular.copy(newLogin); serverGroupList[loginData.serverName] = angular.copy(loginData); var ct = CryptoJS.AES.encrypt(JSON.stringify(serverGroupList), zm.cipherKey).toString(); - return localforage.setItem("serverGroupList", ct) - .then(function () { + + //debug ("Crypto is: " + ct); + + localforage.setItem("serverGroupList", ct) + .then(function () { + debug ("saving serverGroupList worked"); return localforage.setItem("defaultServerName", loginData.serverName); - }) - .catch(function (err) { - log("localforage store error " + JSON.stringify(err)); + }) + .then (function () { + debug ("saving defaultServerName worked"); + return localforage.removeItem("settings-temp-data"); + }) + .then (function() { + debug ("removing settings-temp-data worked"); + }) + .catch(function (err) { + log("SetLogin localforage store error " + JSON.stringify(err)); }); - //console.log ("****serverLogin was encrypted to " + ct); - //$localstorage.setObject("serverGroupList", serverGroupList); - /* return localforage.setItem("serverGroupList", ct, function(err) - { - if (err) log("localforage store error " + JSON.stringify(err)); - }); - //$localstorage.set("defaultServerName", loginData.serverName); - return localforage.setItem("defaultServerName", loginData.serverName, function(err) - { - if (err) log("localforage store error " + JSON.stringify(err)); - });*/ - // return (d.promise); + } //credit: https://gist.github.com/alexey-bass/1115557 @@ -1507,7 +1507,10 @@ angular.module('zmApp.controllers') //localforage.setItem("isFirstUse", val, // function(err) {if (err) log ("localforage error, //storing isFirstUse: " + JSON.stringify(err));}); isFirstUse = val; - localforage.setItem("isFirstUse", val); + debug ("Setting isFirstUse to:"+val); + localforage.setItem("isFirstUse", val) + .then (function (succ) { debug ("Saved isFirstUse ok");}) + .catch (function (err) { debug ("Error Saving isFirstUse:" + JSON.stringify(err));}); //console.log (">>>>>>setting isFirstUse to " + val); }, @@ -2516,6 +2519,91 @@ angular.module('zmApp.controllers') return "(Unknown)"; }, + // tries to set up a DB + // set/get a value and if it fails + // goes back to localstorage + // needed for some old Android phones where index setting works, but actually fails + + configureStorageDB: function () { + + debug ("Inside configureStorageDB"); + var d = $q.defer(); + localforage.config({ + name: zm.dbName + + }); + + if ($rootScope.platformOS == 'ios') { + order = [window.cordovaSQLiteDriver._driver, + localforage.INDEXEDDB, + localforage.LOCALSTORAGE + ]; + } else { + // don't do SQL for Android + // large keys hang on some devices + // see https://github.com/litehelpers/Cordova-sqlite-storage/issues/533 + order = [ + localforage.INDEXEDDB, + localforage.LOCALSTORAGE, + ]; + } + + debug ("configureStorageDB: trying order:" + JSON.stringify(order)); + + localforage.defineDriver(window.cordovaSQLiteDriver).then(function () { + return localforage.setDriver( + // Try setting cordovaSQLiteDriver if available, + // for desktops, it will pick the next one + order + ); + }) + .then ( function (succ) { + log("configureStorageDB:localforage driver for storage:" + localforage.driver()); + debug ("configureStorageDB:Making sure this storage driver works..."); + return localforage.setItem('testPromiseKey', 'testPromiseValue'); + }) + .then (function (succ) { + return localforage.getItem('testPromiseKey'); + }) + .then (function (succ) { + if (succ != 'testPromiseValue') { + log ("configureStorageDB:this driver could not restore a test val, reverting to localstorage and hoping for the best..."); + return forceLocalStorage(); + } + else { + debug ("configureStorageDB:test get/set worked, this driver is ok..."); + d.resolve(true); + return d.promise; + } + }) + .catch (function (err) { + log ("configureStorageDB:this driver errored, reverting to localstorage and hoping for the best...: " + JSON.stringify(err)); + return forceLocalStorage(); + }); + + return d.promise; + + function forceLocalStorage() { + + // var d = $q.defer(); + localforage.setDriver (localforage.LOCALSTORAGE) + .then (function (succ) { + log ("configureStorageDB:localforage forced setting to localstorage returned a driver of: " + localforage.driver()); + d.resolve(true); + return d.promise; + }, + function (err) { + log ("*** configureStorageDB: Error setting localStorage too, zmNinja WILL NOT SAVE ***"); + log ("*** configureStorageDB: Dance, rejoice, keep re-configuring everytime you run ***"); + d.resolve(true); + return d.promise; + }); + return d.promise; + + } + + }, + getBaseURL: function (id) { var idnum = parseInt(id); for (var i = 0; i < monitors.length; i++) { diff --git a/www/js/LoginCtrl.js b/www/js/LoginCtrl.js index dd18724e..14b8d511 100644 --- a/www/js/LoginCtrl.js +++ b/www/js/LoginCtrl.js @@ -456,6 +456,9 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r //console.log ("*********** SAVE ITEMS CALLED "); //console.log('Saving login'); + + NVRDataModel.debug ("Inside save Items"); + NVRDataModel.setFirstUse(false); NVRDataModel.setCurrentServerVersion(''); NVRDataModel.setCurrentServerMultiPortSupported(false); @@ -601,7 +604,7 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r .then(function (data) { - console.log ("DOLOGIN RETURNED "+ JSON.stringify(data)); + //console.log ("DOLOGIN RETURNED "+ JSON.stringify(data)); // Now let's validate if the API works @@ -727,6 +730,7 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r $scope.saveItems = function () { + NVRDataModel.debug ("User tapped save, calling SaveItems"); NVRDataModel.clearZmsMultiPortSupport(); if (!$scope.loginData.serverName) { $rootScope.zmPopup = $ionicPopup.alert({ diff --git a/www/js/app.js b/www/js/app.js index b93188f3..04f05987 100755 --- a/www/js/app.js +++ b/www/js/app.js @@ -1308,11 +1308,11 @@ angular.module('zmApp', [ // when ready add ionic cordova plugin add https://github.com/pliablepixels/cordova-plugin-android-tv.git // console.log (JSON.stringify(ionic.Platform.device())); - if (0 && $ionicPlatform.is('android')) { + /* if (0 && $ionicPlatform.is('android')) { window.addEventListener('keydown', dPadHandler, true); } else { NVRDataModel.log("Not registering D-PAD handler, as you are not on android"); - } + }*/ function dPadHandler(evt) { @@ -1623,40 +1623,8 @@ angular.module('zmApp', [ //$rootScope.lastStateParam = "0"; //console.log("localforage config"); - localforage.config({ - name: zm.dbName - - }); - - var order = []; - - if ($rootScope.platformOS == 'ios') { - order = [window.cordovaSQLiteDriver._driver, - localforage.INDEXEDDB, - localforage.WEBSQL, - localforage.LOCALSTORAGE - ]; - } else - - { - // don't do SQL for non IOS - seems to hang? - order = [ - - localforage.INDEXEDDB, - localforage.WEBSQL, - localforage.LOCALSTORAGE, - ]; - - } - - //console.log("forage driver"); - localforage.defineDriver(window.cordovaSQLiteDriver).then(function () { - return localforage.setDriver( - // Try setting cordovaSQLiteDriver if available, - order - - ); - }).then(function () { + NVRDataModel.configureStorageDB() + .then(function () { // this should alert "cordovaSQLiteDriver" when in an emulator or a device NVRDataModel.log("localforage driver for storage:" + localforage.driver()); @@ -1698,6 +1666,7 @@ angular.module('zmApp', [ NVRDataModel.log(">>>>migrated defaultLang..."); NVRDataModel.setFirstUse(ifu); + NVRDataModel.log ("migration: setting isFirstUse = "+ifu); return localforage.setItem('isFirstUse', ifu); }) .then(function () { @@ -1835,10 +1804,12 @@ angular.module('zmApp', [ localforage.getItem("isFirstUse") .then(function (val) { //console.log ("isFirstUse is " + val); - if (val == null || val == true) { - NVRDataModel.log("First time detected"); + NVRDataModel.debug ("isFirstUse returned: "+val); + if (val == null || val == true ) { + NVRDataModel.log("First time detected "); $state.go("app.first-use"); - return; + return; + //continueRestOfInit(); } else { continueRestOfInit(); } @@ -1912,51 +1883,48 @@ angular.module('zmApp', [ $ionicPlatform.ready(function () { NVRDataModel.log("App is resuming from background"); $rootScope.isDownloading = false; - var forceDelay = NVRDataModel.getLogin().resumeDelay; - NVRDataModel.log(">>> Resume delayed for " + forceDelay + " ms, to wait for network stack..."); + + var ld = NVRDataModel.getLogin(); - $timeout(function () { - var ld = NVRDataModel.getLogin(); + NVRDataModel.setBackground(false); + // don't animate + $ionicHistory.nextViewOptions({ + disableAnimate: true, + disableBack: true + }); - NVRDataModel.setBackground(false); - // don't animate + // remember the last state so we can + // go back there after auth + if ($ionicHistory.currentView()) { + $rootScope.lastState = $ionicHistory.currentView().stateName; + $rootScope.lastStateParam = + $ionicHistory.currentView().stateParams; + NVRDataModel.debug("Last State recorded:" + + JSON.stringify($ionicHistory.currentView())); + + if ($rootScope.lastState == "app.zm-portal-login") { + NVRDataModel.debug("Last state was portal-login, so forcing montage"); + $rootScope.lastState = "app.montage"; + } + + NVRDataModel.debug("going to portal login"); $ionicHistory.nextViewOptions({ - disableAnimate: true, - disableBack: true + disableAnimate: true }); + $state.go("app.zm-portal-login"); + return; + } else { + $rootScope.lastState = ""; + $rootScope.lastStateParam = ""; + NVRDataModel.debug("reset lastState to null"); + $ionicHistory.nextViewOptions({ + disableAnimate: true + }); + $state.go("app.zm-portal-login"); + return; + } - // remember the last state so we can - // go back there after auth - if ($ionicHistory.currentView()) { - $rootScope.lastState = $ionicHistory.currentView().stateName; - $rootScope.lastStateParam = - $ionicHistory.currentView().stateParams; - NVRDataModel.debug("Last State recorded:" + - JSON.stringify($ionicHistory.currentView())); - - if ($rootScope.lastState == "app.zm-portal-login") { - NVRDataModel.debug("Last state was portal-login, so forcing montage"); - $rootScope.lastState = "app.montage"; - } - - NVRDataModel.debug("going to portal login"); - $ionicHistory.nextViewOptions({ - disableAnimate: true - }); - $state.go("app.zm-portal-login"); - return; - } else { - $rootScope.lastState = ""; - $rootScope.lastStateParam = ""; - NVRDataModel.debug("reset lastState to null"); - $ionicHistory.nextViewOptions({ - disableAnimate: true - }); - $state.go("app.zm-portal-login"); - return; - } - - }, forceDelay); + }); }, false); @@ -2086,6 +2054,7 @@ angular.module('zmApp', [ url: '/app', abstract: true, templateUrl: 'templates/menu.html', + cache: false, //controller: 'AppCtrl' @@ -2113,6 +2082,18 @@ angular.module('zmApp', [ }) + .state('app.bookmark', { + data: { + requireLogin: false + }, + url: "/bookmark", + cache: false, + templateUrl: "templates/bookmark.html", + controller: 'zmApp.BookmarkCtrl', + + }) + + .state('app.news', { data: { requireLogin: false @@ -2234,6 +2215,9 @@ angular.module('zmApp', [ data: { requireLogin: true }, + params: { + shortcut: null + }, cache: false, url: "/state", templateUrl: "templates/state.html", |
