simplify/deduplicate badge error logic

also correctly restore the real badge info when error is cleared
This commit is contained in:
tophf 2021-02-09 12:37:36 +03:00
parent c60c764d34
commit c00c748c1e
2 changed files with 15 additions and 18 deletions

View File

@ -67,13 +67,15 @@ const iconMan = (() => {
refreshIconBadgeColor(); refreshIconBadgeColor();
setBadgeText({text}); setBadgeText({text});
for (const tabId of tabMan.list()) { for (const tabId of tabMan.list()) {
if (badgeOvr) { if (text) {
setBadgeText({tabId, text}); setBadgeText({tabId, text});
} else { } else {
refreshIconBadgeText(tabId); refreshIconBadgeText(tabId);
} }
} }
chrome.browserAction.setTitle({title}); chrome.browserAction.setTitle({
title: title && chrome.i18n.getMessage(title) || title || '',
});
}, },
}; };

View File

@ -209,22 +209,7 @@ const syncMan = (() => {
function emitStatusChange() { function emitStatusChange() {
msg.broadcastExtension({method: 'syncStatusUpdate', status}); msg.broadcastExtension({method: 'syncStatusUpdate', status});
iconMan.overrideBadge(getErrorBadge());
if (status.state !== STATES.connected || !lastError || isNetworkError(lastError)) {
iconMan.overrideBadge({});
} else if (isGrantError(lastError)) {
iconMan.overrideBadge({
text: 'x',
color: '#F00',
title: chrome.i18n.getMessage('syncErrorRelogin'),
});
} else {
iconMan.overrideBadge({
text: 'x',
color: '#F00',
title: chrome.i18n.getMessage('syncError'),
});
}
} }
function isNetworkError(err) { function isNetworkError(err) {
@ -237,6 +222,16 @@ const syncMan = (() => {
return false; return false;
} }
function getErrorBadge() {
if (status.state === STATES.connected && lastError && !isNetworkError(lastError)) {
return {
text: 'x',
color: '#F00',
title: isGrantError(lastError) ? 'syncErrorRelogin' : 'syncError',
};
}
}
function getDrive(name) { function getDrive(name) {
if (name === 'dropbox' || name === 'google' || name === 'onedrive') { if (name === 'dropbox' || name === 'google' || name === 'onedrive') {
return dbToCloud.drive[name]({ return dbToCloud.drive[name]({