Fixed issues where onReplaced and onUpdated are called multiple times
This commit is contained in:
parent
0e2e17f2e7
commit
124ac06419
|
@ -72,29 +72,26 @@ if (chrome.runtime.onInstalled) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildContextMenu() {
|
function buildContextMenu(callback) {
|
||||||
chrome.contextMenus.removeAll();
|
chrome.contextMenus.removeAll(function () {
|
||||||
chrome.contextMenus.create({
|
chrome.contextMenus.create({
|
||||||
type: 'normal',
|
type: 'normal',
|
||||||
id: 'autofill',
|
id: 'autofill',
|
||||||
contexts: ['all'],
|
contexts: ['all'],
|
||||||
title: i18nService.autoFill
|
title: i18nService.autoFill
|
||||||
});
|
}, function () {
|
||||||
|
|
||||||
chrome.contextMenus.create({
|
chrome.contextMenus.create({
|
||||||
type: 'normal',
|
type: 'normal',
|
||||||
id: 'copy-username',
|
id: 'copy-username',
|
||||||
contexts: ['all'],
|
contexts: ['all'],
|
||||||
title: i18nService.copyUsername
|
title: i18nService.copyUsername
|
||||||
});
|
}, function () {
|
||||||
|
|
||||||
chrome.contextMenus.create({
|
chrome.contextMenus.create({
|
||||||
type: 'normal',
|
type: 'normal',
|
||||||
id: 'copy-password',
|
id: 'copy-password',
|
||||||
contexts: ['all'],
|
contexts: ['all'],
|
||||||
title: i18nService.copyPassword
|
title: i18nService.copyPassword
|
||||||
});
|
}, function () {
|
||||||
|
|
||||||
chrome.contextMenus.create({
|
chrome.contextMenus.create({
|
||||||
type: 'separator'
|
type: 'separator'
|
||||||
});
|
});
|
||||||
|
@ -104,16 +101,36 @@ function buildContextMenu() {
|
||||||
id: 'generate-password',
|
id: 'generate-password',
|
||||||
contexts: ['all'],
|
contexts: ['all'],
|
||||||
title: i18nService.generatePasswordCopied
|
title: i18nService.generatePasswordCopied
|
||||||
|
}, function () {
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.tabs.onActivated.addListener(function (activeInfo) {
|
chrome.tabs.onActivated.addListener(function (activeInfo) {
|
||||||
buildContextMenu();
|
|
||||||
refreshBadgeAndMenu();
|
refreshBadgeAndMenu();
|
||||||
});
|
});
|
||||||
|
|
||||||
var loadedMenu = false;
|
var onReplacedRan = false;
|
||||||
chrome.tabs.onReplaced.addListener(function (addedTabId, removedTabId) {
|
chrome.tabs.onReplaced.addListener(function (addedTabId, removedTabId) {
|
||||||
|
if (onReplacedRan) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onReplacedRan = true;
|
||||||
|
refreshBadgeAndMenu();
|
||||||
|
});
|
||||||
|
|
||||||
|
var onUpdatedRan = false;
|
||||||
|
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
||||||
|
if (onUpdatedRan) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onUpdatedRan = true;
|
||||||
refreshBadgeAndMenu();
|
refreshBadgeAndMenu();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -128,18 +145,14 @@ function refreshBadgeAndMenu() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
buildContextMenu();
|
buildContextMenu(function () {
|
||||||
loadMenuAndUpdateBadge(tab.url, tab.id, true);
|
loadMenuAndUpdateBadge(tab.url, tab.id, true);
|
||||||
|
onUpdatedRan = onReplacedRan = false;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
|
||||||
buildContextMenu();
|
|
||||||
loadMenuAndUpdateBadge(tab.url, tabId, true);
|
|
||||||
});
|
|
||||||
|
|
||||||
function loadMenuAndUpdateBadge(url, tabId, loadContextMenuOptions) {
|
function loadMenuAndUpdateBadge(url, tabId, loadContextMenuOptions) {
|
||||||
loadedMenu = false;
|
|
||||||
if (!url) {
|
if (!url) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -153,11 +166,6 @@ function loadMenuAndUpdateBadge(url, tabId, loadContextMenuOptions) {
|
||||||
chrome.browserAction.setBadgeBackgroundColor({ color: '#294e5f' });
|
chrome.browserAction.setBadgeBackgroundColor({ color: '#294e5f' });
|
||||||
|
|
||||||
siteService.getAllDecrypted().then(function (sites) {
|
siteService.getAllDecrypted().then(function (sites) {
|
||||||
if (loadedMenu) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
loadedMenu = true;
|
|
||||||
|
|
||||||
sortSites(sites);
|
sortSites(sites);
|
||||||
for (var i = 0; i < sites.length; i++) {
|
for (var i = 0; i < sites.length; i++) {
|
||||||
if (sites[i].domain && tabDomain === sites[i].domain) {
|
if (sites[i].domain && tabDomain === sites[i].domain) {
|
||||||
|
|
|
@ -71,12 +71,12 @@ function initFolderService() {
|
||||||
cryptoService.getKey(false, function (key) {
|
cryptoService.getKey(false, function (key) {
|
||||||
if (!key) {
|
if (!key) {
|
||||||
deferred.reject();
|
deferred.reject();
|
||||||
return deferred.promise;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.decryptedFolderCache) {
|
if (self.decryptedFolderCache) {
|
||||||
deferred.resolve(self.decryptedFolderCache);
|
deferred.resolve(self.decryptedFolderCache);
|
||||||
return deferred.promise;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var promises = [];
|
var promises = [];
|
||||||
|
|
|
@ -88,12 +88,12 @@ function initSiteService() {
|
||||||
cryptoService.getKey(false, function (key) {
|
cryptoService.getKey(false, function (key) {
|
||||||
if (!key) {
|
if (!key) {
|
||||||
deferred.reject();
|
deferred.reject();
|
||||||
return deferred.promise;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.decryptedSiteCache) {
|
if (self.decryptedSiteCache) {
|
||||||
deferred.resolve(self.decryptedSiteCache);
|
deferred.resolve(self.decryptedSiteCache);
|
||||||
return deferred.promise;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var promises = [];
|
var promises = [];
|
||||||
|
|
Loading…
Reference in New Issue