1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-06 09:20:43 +01:00

sidebar badge

This commit is contained in:
Kyle Spearrin 2017-09-28 14:03:01 -04:00
parent 3ce2fb484a
commit 9f45603611

View File

@ -24,7 +24,8 @@ var bg_isBackground = true,
menuOptionsLoaded = [], menuOptionsLoaded = [],
pendingAuthRequests = [], pendingAuthRequests = [],
syncTimeout = null, syncTimeout = null,
bg_loginsToAdd = []; bg_loginsToAdd = [],
bg_sidebarAction = (typeof opr !== 'undefined') && opr.sidebarAction ? opr.sidebarAction : chrome.sidebarAction;
// init services // init services
bg_utilsService = new UtilsService(); bg_utilsService = new UtilsService();
@ -371,7 +372,7 @@ var bg_isBackground = true,
} }
function setIcon() { function setIcon() {
if (!chrome.browserAction && !chrome.sidebarAction) { if (!chrome.browserAction && !bg_sidebarAction) {
return; return;
} }
@ -386,7 +387,7 @@ var bg_isBackground = true,
} }
actionSetIcon(chrome.browserAction, suffix); actionSetIcon(chrome.browserAction, suffix);
actionSetIcon(chrome.sidebarAction, suffix); actionSetIcon(bg_sidebarAction, suffix);
}); });
}); });
@ -437,7 +438,11 @@ var bg_isBackground = true,
} }
function loadMenuAndUpdateBadge(url, tabId, contextMenuEnabled) { function loadMenuAndUpdateBadge(url, tabId, contextMenuEnabled) {
if (!chrome.browserAction.setBadgeBackgroundColor || !url) { if (!chrome.browserAction && !bg_sidebarAction) {
return;
}
if (!url) {
return; return;
} }
@ -446,11 +451,8 @@ var bg_isBackground = true,
return; return;
} }
chrome.browserAction.setBadgeBackgroundColor({ color: '#294e5f' }); setActionBadgeColor(chrome.browserAction);
setActionBadgeColor(bg_sidebarAction);
if (!chrome.browserAction.setBadgeText) {
return;
}
menuOptionsLoaded = []; menuOptionsLoaded = [];
bg_loginService.getAllDecryptedForDomain(tabDomain).then(function (logins) { bg_loginService.getAllDecryptedForDomain(tabDomain).then(function (logins) {
@ -462,37 +464,67 @@ var bg_isBackground = true,
} }
} }
var theText = '';
if (logins.length > 0 && logins.length < 9) { if (logins.length > 0 && logins.length < 9) {
chrome.browserAction.setBadgeText({ theText = logins.length.toString();
text: logins.length.toString(),
tabId: tabId
});
} }
else if (logins.length > 0) { else if (logins.length > 0) {
chrome.browserAction.setBadgeText({ theText = '9+';
text: '9+',
tabId: tabId
});
} }
else { else {
if (contextMenuEnabled) { if (contextMenuEnabled) {
loadNoLoginsContextMenuOptions(bg_i18nService.noMatchingLogins); loadNoLoginsContextMenuOptions(bg_i18nService.noMatchingLogins);
} }
chrome.browserAction.setBadgeText({
text: '',
tabId: tabId
});
} }
setBrowserActionText(theText, tabId);
setSidebarActionText(theText, tabId);
}, function () { }, function () {
if (contextMenuEnabled) { if (contextMenuEnabled) {
loadNoLoginsContextMenuOptions(bg_i18nService.vaultLocked); loadNoLoginsContextMenuOptions(bg_i18nService.vaultLocked);
} }
setBrowserActionText('', tabId);
setSidebarActionText('', tabId);
});
function setActionBadgeColor(theAction) {
if (theAction && theAction.setBadgeBackgroundColor) {
theAction.setBadgeBackgroundColor({ color: '#294e5f' });
}
}
function setBrowserActionText(text, tabId) {
if (chrome.browserAction && chrome.browserAction.setBadgeText) {
chrome.browserAction.setBadgeText({ chrome.browserAction.setBadgeText({
text: '', text: text,
tabId: tabId tabId: tabId
}); });
}
}
function setSidebarActionText(text, tabId) {
if (!bg_sidebarAction) {
return;
}
if (bg_sidebarAction.setBadgeText) {
bg_sidebarAction.setBadgeText({
text: text,
tabId: tabId
}); });
} }
else if (bg_sidebarAction.setTitle) {
var title = 'bitwarden';
if (text && text !== '') {
title += (' [' + text + ']');
}
bg_sidebarAction.setTitle({
title: title,
tabId: tabId
});
}
}
}
function messageCurrentTab(command, data) { function messageCurrentTab(command, data) {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {