load vault on `$viewContentLoaded`. apply scope on current tab when no sites to load. switch to $timeout to go through angular lifecycle.

This commit is contained in:
Kyle Spearrin 2016-12-27 00:01:01 -05:00
parent 6af283b947
commit 304183aad8
2 changed files with 18 additions and 11 deletions

View File

@ -1,8 +1,8 @@
angular
.module('bit.current')
.controller('currentController', function ($scope, siteService, tldjs, toastr, $q, $window, $state, autofillService,
$analytics, i18nService) {
.controller('currentController', function ($scope, $rootScope, siteService, tldjs, toastr, $q, $window, $state, $timeout,
autofillService, $analytics, i18nService) {
$scope.i18n = i18nService;
var pageDetails = [],
@ -11,9 +11,13 @@ angular
domain = null,
canAutofill = false;
$scope.sites = [];
$scope.loaded = false;
loadVault();
$scope.$on('$viewContentLoaded', function () {
$timeout(loadVault, 0);
});
function loadVault() {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
if (tabs.length > 0) {
@ -22,13 +26,14 @@ angular
}
else {
$scope.loaded = true;
$scope.$apply();
return;
}
domain = tldjs.getDomain(url);
$scope.sites = [];
if (!domain) {
$scope.loaded = true;
$scope.$apply();
return;
}

View File

@ -2,7 +2,7 @@
.module('bit.vault')
.controller('vaultController', function ($scope, $rootScope, siteService, folderService, $q, $state, $stateParams, toastr,
syncService, utilsService, $analytics, i18nService, stateService) {
syncService, utilsService, $analytics, i18nService, stateService, $timeout) {
var stateKey = 'vault',
state = stateService.getState(stateKey) || {};
@ -11,9 +11,11 @@
var syncOnLoad = $stateParams.syncOnLoad;
if (syncOnLoad) {
setTimeout(function () {
syncService.fullSync(function () { });
}, utilsService.isFirefox() ? 500 : 0);
$scope.$on('$viewContentLoaded', function () {
$timeout(function () {
syncService.fullSync(function () { })
}, 0);
});
}
var delayLoad = true;
@ -29,8 +31,8 @@
}
if (delayLoad) {
setTimeout(setScrollY, 100);
setTimeout(loadVault, 1000);
$timeout(setScrollY, 100);
$timeout(loadVault, 1000);
}
else if (!syncOnLoad) {
loadVault();
@ -136,7 +138,7 @@
};
$scope.$on('syncCompleted', function (event, successfully) {
setTimeout(loadVault, 500);
$timeout(loadVault, 500);
});
function storeState() {