diff options
| author | Pliable Pixels <pliablepixels@gmail.com> | 2018-09-12 16:02:50 -0400 |
|---|---|---|
| committer | Pliable Pixels <pliablepixels@gmail.com> | 2018-09-12 16:02:50 -0400 |
| commit | 28c74214a035e16e2996bab805c6e5ee7325e3a1 (patch) | |
| tree | 3987de5c745849677b3801946f8e77c58a067f2d | |
| parent | 0eee7654d348a4b0c71e7097be3cd2d3b9ce62cd (diff) | |
#704 initial code, need to check error cases
| -rwxr-xr-x | make_desktop.sh | 140 | ||||
| -rw-r--r-- | www/js/LoginCtrl.js | 2 | ||||
| -rw-r--r-- | www/js/MenuController.js | 207 | ||||
| -rwxr-xr-x | www/js/app.js | 4 | ||||
| -rw-r--r-- | www/templates/menu.html | 2 |
5 files changed, 352 insertions, 3 deletions
diff --git a/make_desktop.sh b/make_desktop.sh new file mode 100755 index 00000000..2d2b3134 --- /dev/null +++ b/make_desktop.sh @@ -0,0 +1,140 @@ +#!/bin/bash +RED='\033[0;31m' +NC='\033[1m\033[0m' +GREEN='\033[0;32m' +ORANGE='\033[0;33m' +GREY='\033[0;37m' + + +err() { echo -e "${RED}$@${NC}"; } +warn() { echo -e "${ORANGE}$@${NC}"; } +success() { echo -e "${GREEN}$@${NC}"; } +debug() { echo -e "${GREY}->$@${NC}"; } + +exe() { debug "\$ $@" ; "$@" ; } + +if [ ! -d "desktop" ]; then + echo "You have not downloaded desktop images" + echo "Please run ./prepare_desktop.sh" + echo + exit +fi + +while [[ $# -gt 0 ]] +do + arg="$1" + case $arg in + -h|--help) + echo "./make_desktop.sh [--port|-p mac|linux32|linux64|linuxarm|win32|win64|arm|<any substring that matches one or more port names>]" + echo " so -p linux will build linux32/64/arm as they all match linux" + echo " [--nocolor|nc] to disable color output" + echo + exit + ;; + + -p|--port) + PORT="$2" + shift + shift + ;; + -nc|--nocolor) + RED='' + NC='' + GREEN='' + ORANGE='' + GREY='' + shift + ;; + *) + echo "Unknown argument $1, ignoring..." + shift + ;; + esac +done + +[[ ! -z $PORT ]] && echo "Only creating build for $PORT" && PORT="-$PORT" + +echo ---------------------------------------------------- +echo Pliable Pixels Desktop build process +echo ---------------------------------------------------- +APPVER=`cat config.xml | grep "widget " | sed 's/.* version=\"\([^\"]*\)\" xmlns.*/\1/'` +APPVER+="D" +echo "Application version:$APPVER" + +declare -a app_ports=("desktop/zmNinja-mac.app/Contents/Resources" "desktop/zmNinja-linux32bit/resources" "desktop/zmNinja-linux64bit/resources" "desktop/zmNinja-win64bit/resources" "desktop/zmNinja-win32bit/resources" "desktop/zmNinja-linuxarm/resources") + +for i in "${app_ports[@]}" +do + if [[ "$i" =~ $PORT || -z $PORT ]]; then + : + else + warn "$i will be skipped (did not match $PORT)" + continue + fi + if [ -d "$i" ]; then + DIRNAME=$i + + if [ "${i}" == "desktop/zmNinja-mac.app/Contents/Resources" ]; then + BASENAME="desktop/zmNinja-mac.app/Contents" + else + BASENAME=`expr "$i" : '\(.*\)/resources'` + fi + + echo "------------------------------------------------------------------------" + success "Working on packaging $i" + echo "------------------------------------------------------------------------" + echo Creating paths... + exe rm -fr $i/app + exe mkdir $i/app + exe mkdir $i/app/node_modules + exe mkdir $i/app/www + exe mkdir $i/app/electron_js + + echo Copying over relevant node modules... + exe cp -R node_modules/electron-window-state $i/app/node_modules + exe cp -R node_modules/jsonfile $i/app/node_modules + exe cp -R node_modules/mkdirp $i/app/node_modules + exe cp -R node_modules/deep-equal $i/app/node_modules + exe cp -R node_modules/minimist $i/app/node_modules + exe cp -R node_modules/menu $i/app/node_modules + exe cp -R node_modules/clivas $i/app/node_modules + exe cp -R node_modules/keypress $i/app/node_modules + + echo Copying over zmNinja code... + exe cp package.json $i/app + exe cp -R www/* $i/app/www + exe cp electron_js/main.js $i/app/electron_js + exe cp www/ZMNINJA-LICENSE-DESKTOP-CLIENT.txt $BASENAME + echo $APPVER > $BASENAME/version + exe cp resources/icon.png $BASENAME + exe cd $i + cat app/www/js/DataModel.js | sed "s/var zmAppVersion[ ]*=[ ]*\"unknown\"/var zmAppVersion=\"$APPVER\"/" > app/www/js/DataModel.js.tmp + exe rm -fr app/www/js/DataModel.js + exe mv app/www/js/DataModel.js.tmp app/www/js/DataModel.js + + + rm -fr app.asar + + # No idea why but asar is causing problems in windows + # main.js changes are not showig up. wuh? - Sep 29, 2017 + + #exe asar pack app app.asar + #read -p "Press a key to remove app dir for $i..." + #exe rm -fr app + cd - + #OSX ditto does a better job than zip! + #echo "Creating ZIP $ZIPNAME..." + #exe zip -r ../$ZIPNAME ../$DIRNAME + + success "Done!" + echo + + else # dirname exists + echo "$i does not exist, skipping" + fi +done +echo +warn "Note, SASS changes won't be reflected. Run 'ionic build' for that" +echo + + diff --git a/www/js/LoginCtrl.js b/www/js/LoginCtrl.js index 793d28cf..23d442bf 100644 --- a/www/js/LoginCtrl.js +++ b/www/js/LoginCtrl.js @@ -458,6 +458,8 @@ angular.module('zmApp.controllers').controller('zmApp.LoginCtrl', ['$scope', '$r //console.log('Saving login'); NVRDataModel.debug ("Inside save Items"); + + $rootScope.alarmCount = 0; NVRDataModel.setFirstUse(false); NVRDataModel.setCurrentServerVersion(''); diff --git a/www/js/MenuController.js b/www/js/MenuController.js index f09d1c69..acc5f266 100644 --- a/www/js/MenuController.js +++ b/www/js/MenuController.js @@ -2,7 +2,7 @@ /* jslint browser: true*/ /* global cordova,StatusBar,angular,console */ -angular.module('zmApp.controllers').controller('MenuController', ['$scope', '$ionicSideMenuDelegate', 'zm', '$stateParams', '$ionicHistory', '$state', 'NVRDataModel', '$rootScope', '$ionicPopup', '$translate', '$timeout', '$location',function ($scope, $ionicSideMenuDelegate, zm, $stateParams, $ionicHistory, $state, NVRDataModel, $rootScope, $ionicPopup, $translate, $timeout, $location) { +angular.module('zmApp.controllers').controller('MenuController', ['$scope', '$ionicSideMenuDelegate', 'zm', '$stateParams', '$ionicHistory', '$state', 'NVRDataModel', '$rootScope', '$ionicPopup', '$translate', '$timeout', '$location','EventServer', 'zmAutoLogin','$http',function ($scope, $ionicSideMenuDelegate, zm, $stateParams, $ionicHistory, $state, NVRDataModel, $rootScope, $ionicPopup, $translate, $timeout, $location, EventServer, zmAutoLogin, $http) { $scope.openMenu = function () { $ionicSideMenuDelegate.toggleLeft(); }; @@ -45,6 +45,211 @@ angular.module('zmApp.controllers').controller('MenuController', ['$scope', '$io }; + function switchToServer(s) { + + $rootScope.alarmCount = 0; + if ($ionicSideMenuDelegate.isOpen()) { + $ionicSideMenuDelegate.toggleLeft(); + + } + + // First lets kill current stuf + NVRDataModel.debug ("** Resetting existing server"); + var cld = NVRDataModel.getLogin(); + if (cld.isUseEventServer) { + NVRDataModel.debug ("Stopping Event server"); + EventServer.disconnect(); + } + + + NVRDataModel.debug ("**Switching to new server..."); + + var zmServers = NVRDataModel.getServerGroups(); + var loginData = zmServers[s]; + NVRDataModel.debug("Retrieved state for this profile:" + JSON.stringify(loginData)); + NVRDataModel.setLogin(loginData); + + if (loginData.isUseEventServer) { + EventServer.init(); + if ($rootScope.apnsToken && loginData.disablePush != true) { + NVRDataModel.log("Making sure we get push notifications"); + EventServer.sendMessage('push', { + type: 'token', + platform: $rootScope.platformOS, + token: $rootScope.apnsToken, + state: "enabled" + }, 1); + } + EventServer.sendMessage("control", { + type: 'filter', + monlist: loginData.eventServerMonitors, + intlist: loginData.eventServerInterval + }); + } + + + var apiurl = loginData.apiurl + '/host/getVersion.json'; + var portalurl = loginData.url + '/index.php'; + + zmAutoLogin.doLogin("<button class='button button-clear' style='line-height: normal; min-height: 0; min-width: 0; color:#fff;' ng-click='$root.cancelAuth()'><i class='ion-close-circled'></i> " + $translate.instant('kAuthenticating') + "...</button>") + // Do the happy menu only if authentication works + // if it does not work, there is an emitter for auth + // fail in app.js that will be called to show an error + // box + + .then(function (data) { + + + // possible image digits changed between servers + NVRDataModel.getKeyConfigParams(0); + + NVRDataModel.log("Validating APIs at " + apiurl); + $http.get(apiurl) + .success(function (data) { + + NVRDataModel.getTimeZone(true); + var loginStatus = $translate.instant('kExploreEnjoy') + " " + $rootScope.appName + "!"; + EventServer.refresh(); + + // now grab and report PATH_ZMS + NVRDataModel.getPathZms() + .then(function (data) { + var ld = NVRDataModel.getLogin(); + var zm_cgi = data.toLowerCase(); + + var user_cgi = (ld.streamingurl).toLowerCase(); + NVRDataModel.log("ZM relative cgi-path: " + zm_cgi + ", you entered: " + user_cgi); + + $http.get(ld.streamingurl + "/zms") + .success(function (data) { + NVRDataModel.debug("Urk! cgi-path returned success, but it should not have come here"); + loginStatus = $translate.instant('kLoginStatusNoCgi'); + + NVRDataModel.debug("refreshing API version..."); + NVRDataModel.getAPIversion() + .then(function (data) { + $rootScope.apiVersion = data; + var refresh = NVRDataModel.getMonitors(1) + .then (function () { + + + $state.go('app.refresh', { + "view": $state.current.name + }); + return; + }); + + + }, + function (error) { + var refresh = NVRDataModel.getMonitors(1); + + $rootScope.apiVersion = "0.0.0"; + NVRDataModel.debug("Error, failed API version, setting to " + $rootScope.apiVersion); + + $state.go('app.refresh', { + "view": $state.current.name + }); + return; + + }); + + }) + .error(function (error, status) { + // If its 5xx, then the cgi-bin path is valid + // if its 4xx then the cgi-bin path is not valid + + if (status < 500) { + loginStatus = $translate.instant('kLoginStatusNoCgiAlt'); + } + + NVRDataModel.displayBanner((status < 500) ? 'error' : 'info', [loginStatus]); + + NVRDataModel.debug("refreshing API version..."); + NVRDataModel.getAPIversion() + .then(function (data) { + var refresh = NVRDataModel.getMonitors(1); + $rootScope.apiVersion = data; + $state.go('app.refresh', { + "view": $state.current.name + }); + return; + }, + function (error) { + var refresh = NVRDataModel.getMonitors(1); + $rootScope.apiVersion = "0.0.0"; + NVRDataModel.debug("Error, failed API version, setting to " + $rootScope.apiVersion); + $state.go('app.refresh', { + "view": $state.current.name + }); + return; + }); + + }); + }); + + }) + .error(function (error) { + NVRDataModel.displayBanner('error', [$translate.instant('kBannerAPICheckFailed'), $translate.instant('kBannerPleaseCheck')]); + NVRDataModel.log("API login error " + JSON.stringify(error)); + + $rootScope.zmPopup = SecuredPopups.show('alert', { + title: $translate.instant('kLoginValidAPIFailedTitle'), + template: $translate.instant('kBannerPleaseCheck'), + okText: $translate.instant('kButtonOk'), + cancelText: $translate.instant('kButtonCancel'), + }); + }); + }); + + + } + + $scope.switchProfiles = function () { + + $scope.newServer = { + val:"" + } + $scope.avs = Object.keys(NVRDataModel.getServerGroups()); + + $scope.avs = $scope.avs.filter(function() { return true; }); + + if ($scope.avs.length <= 1) { + return; + } + + $rootScope.zmPopup = $ionicPopup.show({ + scope: $scope, + template: '<ion-radio-fix ng-if="item" ng-repeat="item in avs" ng-value="item" ng-model="newServer.val"> {{item}} </ion-radio-fix>', + + title: $translate.instant('kSelectLanguage'), + + buttons: [{ + text: $translate.instant('kButtonCancel'), + onTap: function (e) { + //return "CANCEL"; + } + + }, + { + text: $translate.instant('kButtonOk'), + onTap: function (e) { + NVRDataModel.log("Server selected:" + $scope.newServer.val); + switchToServer($scope.newServer.val); + + //$rootScope.$broadcast('server-changed'); + + //return "OK"; + + } + } + ] + }); + + + + }; + $scope.switchLang = function () { $scope.lang = NVRDataModel.getLanguages(); diff --git a/www/js/app.js b/www/js/app.js index b5f1b804..abe2b0bd 100755 --- a/www/js/app.js +++ b/www/js/app.js @@ -1751,7 +1751,7 @@ angular.module('zmApp', [ - if (NVRDataModel.hasLoginInfo() || toState.data.requireLogin == false) { + if ((NVRDataModel.hasLoginInfo() || toState.data.requireLogin == false) && toState.name != "app.invalidapi" && toState.name != "app.refresh") { //console.log("State transition is authorized"); NVRDataModel.debug ("Setting last-desktop-state to:"+JSON.stringify(toState)); localforage.setItem('last-desktop-state', { @@ -1766,7 +1766,7 @@ angular.module('zmApp', [ // $rootScope.dpadState = "login"; - $state.transitionTo('login'); + $state.transitionTo('app.login'); } diff --git a/www/templates/menu.html b/www/templates/menu.html index 0c1d06a3..32fc15e7 100644 --- a/www/templates/menu.html +++ b/www/templates/menu.html @@ -10,7 +10,9 @@ </ion-side-menu-content> <ion-side-menu> <ion-header-bar class="bar bar-header bar-stable"> + <button class="button icon ion-person-stalker" ng-click="switchProfiles()"></button> <h1 class="title">{{'kMenuOptions'|translate}}</h1> + </button> </ion-header-bar> <ion-content has-header="true" mouse-wheel-scroll> <!-- <ion-scroll scrollbar-y="false" style="height:100%" >--> |
