1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-22 11:45:59 +01:00

update icon when vault is locked/unlocked

This commit is contained in:
Kyle Spearrin 2016-10-25 23:17:46 -04:00
parent 124ac06419
commit e4c5ab88fb
6 changed files with 31 additions and 23 deletions

View File

@ -103,6 +103,10 @@
"message": "No matching sites.", "message": "No matching sites.",
"description": "No matching sites." "description": "No matching sites."
}, },
"vaultLocked": {
"message": "Vault is locked.",
"description": "Vault is locked."
},
"autoFillInfo": { "autoFillInfo": {
"message": "There are no sites available to auto-fill for the current browser tab.", "message": "There are no sites available to auto-fill for the current browser tab.",
"description": "There are no sites available to auto-fill for the current browser tab." "description": "There are no sites available to auto-fill for the current browser tab."

View File

@ -27,13 +27,10 @@ chrome.commands.onCommand.addListener(function (command) {
}); });
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) { chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.command === 'loggedOut') { if (msg.command === 'loggedOut' || msg.command === 'loggedIn' || msg.command === 'unlocked' || msg.command === 'locked') {
setIcon(true); setIcon();
refreshBadgeAndMenu(); refreshBadgeAndMenu();
} }
else if (msg.command === 'loggedIn') {
setIcon(false);
}
else if (msg.command === 'syncCompleted' && msg.successfully) { else if (msg.command === 'syncCompleted' && msg.successfully) {
setTimeout(refreshBadgeAndMenu, 2000); setTimeout(refreshBadgeAndMenu, 2000);
} }
@ -45,21 +42,25 @@ chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
} }
}); });
userService.isAuthenticated(function (isAuthenticated) { setIcon();
setIcon(!isAuthenticated); function setIcon() {
}); userService.isAuthenticated(function (isAuthenticated) {
cryptoService.getKey(false, function (key) {
var suffix = '';
if (!isAuthenticated) {
suffix = '_gray';
}
else if (!key) {
suffix = '_locked';
}
function setIcon(grayedOut) { chrome.browserAction.setIcon({
var suffix = ''; path: {
if (grayedOut) { '19': 'images/icon19' + suffix + '.png',
suffix = '_gray'; '38': 'images/icon38' + suffix + '.png',
} }
});
chrome.browserAction.setIcon({ });
path: {
'19': 'images/icon19' + suffix + '.png',
'38': 'images/icon38' + suffix + '.png',
}
}); });
} }
@ -190,14 +191,14 @@ function loadMenuAndUpdateBadge(url, tabId, loadContextMenuOptions) {
}); });
} }
else { else {
loadNoSitesContextMenuOptions(); loadNoSitesContextMenuOptions(i18nService.noMatchingSites);
chrome.browserAction.setBadgeText({ chrome.browserAction.setBadgeText({
text: '', text: '',
tabId: tabId tabId: tabId
}); });
} }
}, function () { }, function () {
loadNoSitesContextMenuOptions(); loadNoSitesContextMenuOptions(i18nService.vaultLocked);
chrome.browserAction.setBadgeText({ chrome.browserAction.setBadgeText({
text: '', text: '',
tabId: tabId tabId: tabId
@ -334,8 +335,8 @@ function loadSiteContextMenuOptions(site) {
loadContextMenuOptions(title, site.id, site); loadContextMenuOptions(title, site.id, site);
} }
function loadNoSitesContextMenuOptions() { function loadNoSitesContextMenuOptions(noSitesMessage) {
loadContextMenuOptions(i18nService.noMatchingSites, 'noop', null); loadContextMenuOptions(noSitesMessage, 'noop', null);
} }
function loadContextMenuOptions(title, idSuffix, site) { function loadContextMenuOptions(title, idSuffix, site) {
@ -444,6 +445,7 @@ function checkLock() {
if (diffSeconds >= lockOptionSeconds) { if (diffSeconds >= lockOptionSeconds) {
// need to lock now // need to lock now
cryptoService.clearKey(function () { cryptoService.clearKey(function () {
setIcon();
folderService.clearCache(); folderService.clearCache();
siteService.clearCache(); siteService.clearCache();
refreshBadgeAndMenu(); refreshBadgeAndMenu();

Binary file not shown.

After

Width:  |  Height:  |  Size: 584 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 996 B

View File

@ -32,6 +32,7 @@
cryptoService.getKeyHash(true, function (storedKeyHash) { cryptoService.getKeyHash(true, function (storedKeyHash) {
if (storedKeyHash && keyHash && storedKeyHash === keyHash) { if (storedKeyHash && keyHash && storedKeyHash === keyHash) {
cryptoService.setKey(key, function () { cryptoService.setKey(key, function () {
chrome.runtime.sendMessage({ command: 'unlocked' });
$state.go('tabs.current'); $state.go('tabs.current');
}); });
} }

View File

@ -23,6 +23,7 @@ function i18nService() {
autoFill: chrome.i18n.getMessage('autoFill'), autoFill: chrome.i18n.getMessage('autoFill'),
generatePasswordCopied: chrome.i18n.getMessage('generatePasswordCopied'), generatePasswordCopied: chrome.i18n.getMessage('generatePasswordCopied'),
noMatchingSites: chrome.i18n.getMessage('noMatchingSites'), noMatchingSites: chrome.i18n.getMessage('noMatchingSites'),
vaultLocked: chrome.i18n.getMessage('vaultLocked'),
autoFillInfo: chrome.i18n.getMessage('autoFillInfo'), autoFillInfo: chrome.i18n.getMessage('autoFillInfo'),
addSite: chrome.i18n.getMessage('addSite'), addSite: chrome.i18n.getMessage('addSite'),
passwordHint: chrome.i18n.getMessage('passwordHint'), passwordHint: chrome.i18n.getMessage('passwordHint'),