From 8d458d176229c8c4c278337d4b18efd8d4f34fbe Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 21 Sep 2016 00:26:23 -0400 Subject: [PATCH] poll full sync on interval. broadcast messages from background --- src/background.js | 13 ++++++++++--- src/popup/app/current/currentController.js | 4 +++- src/popup/app/global/mainController.js | 9 +++++++++ src/popup/app/vault/vaultController.js | 4 +++- src/services/syncService.js | 2 ++ 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/background.js b/src/background.js index 686fd114a9..2a0a9bdbb8 100644 --- a/src/background.js +++ b/src/background.js @@ -85,7 +85,7 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { sortSites(sites); for (var i = 0; i < sites.length; i++) { - if (sites[i].domain && tabDomain == sites[i].domain) { + if (sites[i].domain && tabDomain === sites[i].domain) { count++; loadContextMenuOptions(sites[i]); } @@ -118,7 +118,7 @@ chrome.contextMenus.onClicked.addListener(function (info, tab) { var id = info.menuItemId.split('_')[1]; siteService.getAllDecrypted().then(function (sites) { for (var i = 0; i < sites.length; i++) { - if (sites[i].id == id) { + if (sites[i].id === id) { if (info.parentMenuItemId === 'autofill') { autofillPage(sites[i]); } @@ -191,7 +191,7 @@ function buildContextMenuOptions(url) { siteService.getAllDecrypted().then(function (sites) { sortSites(sites); for (var i = 0; i < sites.length; i++) { - if (sites[i].domain && tabDomain == sites[i].domain) { + if (sites[i].domain && tabDomain === sites[i].domain) { loadContextMenuOptions(sites[i]); } } @@ -251,3 +251,10 @@ function copyToClipboard(text) { } } } + +fullSync(); +setInterval(fullSync, 60 * 1000); + +function fullSync() { + syncService.fullSync(function() {}); +} diff --git a/src/popup/app/current/currentController.js b/src/popup/app/current/currentController.js index 4bb7675aa0..2eec1dcfbd 100644 --- a/src/popup/app/current/currentController.js +++ b/src/popup/app/current/currentController.js @@ -86,6 +86,8 @@ angular }; $scope.$on('syncCompleted', function (event, args) { - setTimeout(loadVault, 500); + if ($scope.loaded) { + setTimeout(loadVault, 500); + } }); }); diff --git a/src/popup/app/global/mainController.js b/src/popup/app/global/mainController.js index 40ce959ac2..e245500390 100644 --- a/src/popup/app/global/mainController.js +++ b/src/popup/app/global/mainController.js @@ -15,4 +15,13 @@ self.animation = ''; } }); + + chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) { + if (msg.command === 'syncCompleted') { + $scope.$broadcast('syncCompleted'); + } + else if (msg.command === 'syncStarted') { + $scope.$broadcast('syncStarted'); + } + }); }); diff --git a/src/popup/app/vault/vaultController.js b/src/popup/app/vault/vaultController.js index ee809c3c22..088f871fd9 100644 --- a/src/popup/app/vault/vaultController.js +++ b/src/popup/app/vault/vaultController.js @@ -109,7 +109,9 @@ }; $scope.$on('syncCompleted', function (event, args) { - setTimeout(loadVault, 500); + if ($scope.loaded) { + setTimeout(loadVault, 500); + } }); function getScrollY() { diff --git a/src/services/syncService.js b/src/services/syncService.js index d182383b05..97d317e3a0 100644 --- a/src/services/syncService.js +++ b/src/services/syncService.js @@ -169,10 +169,12 @@ function initSyncService() { function syncStarted() { this.syncInProgress = true; + chrome.runtime.sendMessage(null, { command: 'syncStarted' }); } function syncCompleted(successfully) { this.syncInProgress = false; + chrome.runtime.sendMessage(null, { command: 'syncCompleted', successfully: successfully }); } function handleError() {