move sync upon login to vault controller initiated via state params.

This commit is contained in:
Kyle Spearrin 2016-09-26 20:29:23 -04:00
parent a59f7a4afc
commit d49f0fcac3
7 changed files with 29 additions and 25 deletions

View File

@ -39,7 +39,7 @@
$state.go('twoFactor', { animation: 'in-slide-left' }); $state.go('twoFactor', { animation: 'in-slide-left' });
} }
else { else {
$state.go('tabs.vault', { animation: 'in-slide-left' }); $state.go('tabs.vault', { animation: 'in-slide-left', syncOnLoad: true });
} }
}); });
}); });

View File

@ -15,7 +15,7 @@
$scope.loginPromise = loginService.logInTwoFactor(model.code); $scope.loginPromise = loginService.logInTwoFactor(model.code);
$scope.loginPromise.then(function () { $scope.loginPromise.then(function () {
$state.go('tabs.vault', { animation: 'in-slide-left' }); $state.go('tabs.vault', { animation: 'in-slide-left', syncOnLoad: true });
}); });
}; };
}); });

View File

@ -75,7 +75,7 @@
url: '/vault', url: '/vault',
templateUrl: 'app/vault/views/vault.html', templateUrl: 'app/vault/views/vault.html',
controller: 'vaultController', controller: 'vaultController',
params: { scrollY: 0, searchText: null } params: { scrollY: 0, searchText: null, syncOnLoad: false }
}) })
.state('tabs.settings', { .state('tabs.settings', {
url: '/settings', url: '/settings',

View File

@ -1,8 +1,8 @@
angular angular
.module('bit.services') .module('bit.services')
.factory('loginService', function (cryptoService, apiService, userService, tokenService, $q, syncService, .factory('loginService', function (cryptoService, apiService, userService, tokenService, $q, $rootScope, siteService,
$rootScope, siteService, folderService) { folderService) {
var _service = {}; var _service = {};
_service.logIn = function (email, masterPassword) { _service.logIn = function (email, masterPassword) {
@ -22,7 +22,6 @@
if (response.profile) { if (response.profile) {
userService.setUserId(response.profile.id, function () { userService.setUserId(response.profile.id, function () {
userService.setEmail(response.profile.email, function () { userService.setEmail(response.profile.email, function () {
syncService.fullSync(function () { });
deferred.resolve(response); deferred.resolve(response);
}); });
}); });
@ -52,7 +51,6 @@
tokenService.setToken(response.token, function () { tokenService.setToken(response.token, function () {
userService.setUserId(response.profile.id, function () { userService.setUserId(response.profile.id, function () {
userService.setEmail(response.profile.email, function () { userService.setEmail(response.profile.email, function () {
syncService.fullSync(function () { });
deferred.resolve(response); deferred.resolve(response);
}); });
}); });

View File

@ -2,9 +2,16 @@
.module('bit.vault') .module('bit.vault')
.controller('vaultController', function ($scope, $rootScope, siteService, folderService, $q, $state, $stateParams, toastr, .controller('vaultController', function ($scope, $rootScope, siteService, folderService, $q, $state, $stateParams, toastr,
syncService) { syncService, utilsService) {
$('#search').focus(); $('#search').focus();
var syncOnLoad = $stateParams.syncOnLoad;
if (syncOnLoad) {
setTimeout(function () {
syncService.fullSync(function () { });
}, utilsService.isFirefox() ? 500 : 0);
}
var delayLoad = true; var delayLoad = true;
$scope.loaded = true; $scope.loaded = true;
if (!$rootScope.vaultSites) { if (!$rootScope.vaultSites) {
@ -21,7 +28,7 @@
setTimeout(setScrollY, 100); setTimeout(setScrollY, 100);
setTimeout(loadVault, 1000); setTimeout(loadVault, 1000);
} }
else { else if (!syncOnLoad) {
loadVault(); loadVault();
} }
@ -43,11 +50,10 @@
promises.push(sitePromise); promises.push(sitePromise);
$q.all(promises).then(function () { $q.all(promises).then(function () {
if (decSites.length || !syncService.syncInProgress) { $scope.loaded = true;
$scope.loaded = true; $rootScope.vaultFolders = decFolders;
$rootScope.vaultFolders = decFolders; $rootScope.vaultSites = decSites;
$rootScope.vaultSites = decSites;
}
if (!delayLoad) { if (!delayLoad) {
setScrollY(); setScrollY();
} }

View File

@ -270,7 +270,7 @@ function initApiService() {
function handleError(errorCallback, jqXHR, textStatus, errorThrown) { function handleError(errorCallback, jqXHR, textStatus, errorThrown) {
if (jqXHR.status === 401 || jqXHR.status === 403) { if (jqXHR.status === 401 || jqXHR.status === 403) {
chrome.runtime.sendMessage(null, { command: 'logout' }); chrome.runtime.sendMessage({ command: 'logout' });
return; return;
} }

View File

@ -14,12 +14,12 @@ function initSyncService() {
throw 'callback function required'; throw 'callback function required';
} }
syncStarted();
var self = this; var self = this;
self.syncStarted();
self.userService.isAuthenticated(function (isAuthenticated) { self.userService.isAuthenticated(function (isAuthenticated) {
if (!isAuthenticated) { if (!isAuthenticated) {
syncCompleted(false); self.syncCompleted(false);
callback(false); callback(false);
return; return;
} }
@ -43,7 +43,7 @@ function initSyncService() {
self.folderService.replace(folders, function () { self.folderService.replace(folders, function () {
self.siteService.replace(sites, function () { self.siteService.replace(sites, function () {
self.setLastSync(now, function () { self.setLastSync(now, function () {
syncCompleted(true); self.syncCompleted(true);
callback(true); callback(true);
}); });
}); });
@ -169,15 +169,15 @@ function initSyncService() {
}); });
}; };
function syncStarted() { SyncService.prototype.syncStarted = function () {
this.syncInProgress = true; this.syncInProgress = true;
chrome.runtime.sendMessage(null, { command: 'syncStarted' }); chrome.runtime.sendMessage({ command: 'syncStarted' });
} };
function syncCompleted(successfully) { SyncService.prototype.syncCompleted = function (successfully) {
this.syncInProgress = false; this.syncInProgress = false;
chrome.runtime.sendMessage(null, { command: 'syncCompleted', successfully: successfully }); chrome.runtime.sendMessage({ command: 'syncCompleted', successfully: successfully });
} };
function handleError() { function handleError() {
syncCompleted(false); syncCompleted(false);