From 4de3cad7128ae2b2ea1e917ebbf776174ae015c8 Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Tue, 11 Oct 2016 22:46:07 -0400 Subject: [PATCH] perf(startupService): remove timers, control splashscreen and statusbar from startupService --- .gitignore | 3 +++ src/js/controllers/onboarding/disclaimer.js | 7 ++++- .../onboarding/welcomeController.js | 6 ++++- src/js/controllers/tab-home.js | 6 ++++- src/js/routes.js | 6 +---- src/js/services/startupService.js | 26 +++++++++++++++++++ 6 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 src/js/services/startupService.js diff --git a/.gitignore b/.gitignore index 54427aba1..16ebb09f3 100644 --- a/.gitignore +++ b/.gitignore @@ -84,6 +84,9 @@ Session.vim .netrwhist *~ +.tags +.tags1 + # SASS src/sass/*.css .sass-cache diff --git a/src/js/controllers/onboarding/disclaimer.js b/src/js/controllers/onboarding/disclaimer.js index 7459b18da..a18be4e6d 100644 --- a/src/js/controllers/onboarding/disclaimer.js +++ b/src/js/controllers/onboarding/disclaimer.js @@ -1,6 +1,11 @@ 'use strict'; -angular.module('copayApp.controllers').controller('disclaimerController', function($scope, $timeout, $state, $log, $ionicModal, profileService, uxLanguage, externalLinkService, storageService, $stateParams) { +angular.module('copayApp.controllers').controller('disclaimerController', function($scope, $timeout, $state, $log, $ionicModal, profileService, uxLanguage, externalLinkService, storageService, $stateParams, startupService) { + + $scope.$on("$ionicView.afterEnter", function() { + startupService.ready(); + }); + $scope.init = function() { $scope.lang = uxLanguage.currentLanguage; $scope.terms = {}; diff --git a/src/js/controllers/onboarding/welcomeController.js b/src/js/controllers/onboarding/welcomeController.js index 6a7154c55..3a1651f75 100644 --- a/src/js/controllers/onboarding/welcomeController.js +++ b/src/js/controllers/onboarding/welcomeController.js @@ -1,9 +1,13 @@ 'use strict'; -angular.module('copayApp.controllers').controller('welcomeController', function($scope, $state, $timeout, $ionicConfig, $log, profileService) { +angular.module('copayApp.controllers').controller('welcomeController', function($scope, $state, $timeout, $ionicConfig, $log, profileService, startupService) { $ionicConfig.views.swipeBackEnabled(false); + $scope.$parent.$on("$ionicView.afterEnter", function() { + startupService.ready(); + }); + $scope.goImport = function(code) { $state.go('onboarding.import', { fromOnboarding: true, diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index 7cad213aa..c4fa9b106 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('tabHomeController', - function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, gettextCatalog, lodash, popupService, ongoingProcess, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, $window, bitpayCardService) { + function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, gettextCatalog, lodash, popupService, ongoingProcess, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, $window, bitpayCardService, startupService) { var wallet; var listeners = []; var notifications = []; @@ -13,6 +13,10 @@ angular.module('copayApp.controllers').controller('tabHomeController', $scope.homeTip = $stateParams.fromOnboarding; $scope.isCordova = platformInfo.isCordova; + $scope.$on("$ionicView.afterEnter", function() { + startupService.ready(); + }); + if (!$scope.homeTip) { storageService.getHomeTipAccepted(function(error, value) { $scope.homeTip = (value == 'false') ? false : true; diff --git a/src/js/routes.js b/src/js/routes.js index ed29cd0a0..09d99dfae 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -947,16 +947,12 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr }); $ionicPlatform.on('resume', function() { - // Nothing tot do + // Nothing to do }); $ionicPlatform.on('menubutton', function() { window.location = '#/preferences'; }); - - setTimeout(function() { - navigator.splashscreen.hide(); - }, 500); } diff --git a/src/js/services/startupService.js b/src/js/services/startupService.js new file mode 100644 index 000000000..d3d55fc02 --- /dev/null +++ b/src/js/services/startupService.js @@ -0,0 +1,26 @@ +'use strict'; + +angular.module('copayApp.services').service('startupService', function($log) { + + var splashscreenVisible = true; + var statusBarVisible = false; + + function _hideSplash(){ + if(navigator.splashscreen && splashscreenVisible){ + $log.debug('startupService is hiding the splashscreen...'); + navigator.splashscreen.hide(); + splashscreenVisible = false; + } + } + function _showStatusBar(){ + if(StatusBar && !statusBarVisible){ + $log.debug('startupService is showing the StatusBar...'); + StatusBar.show(); + statusBarVisible = true; + } + } + this.ready = function() { + _showStatusBar(); + _hideSplash(); + }; +});