indicate sync error as 'x' in icon badge
This commit is contained in:
parent
ade8d1981b
commit
3a0103dc8e
|
@ -1530,6 +1530,10 @@
|
||||||
"message": "The value cannot be saved. Try reducing the amount of text.",
|
"message": "The value cannot be saved. Try reducing the amount of text.",
|
||||||
"description": "Displayed when trying to save an excessively big value via storage.sync API"
|
"description": "Displayed when trying to save an excessively big value via storage.sync API"
|
||||||
},
|
},
|
||||||
|
"syncErrorRelogin": {
|
||||||
|
"message": "Sync failed.\nPlease re-login.",
|
||||||
|
"description": "Tooltip for the toolbar icon"
|
||||||
|
},
|
||||||
"toggleStyle": {
|
"toggleStyle": {
|
||||||
"message": "Toggle style",
|
"message": "Toggle style",
|
||||||
"description": "Label for the checkbox to enable/disable a style"
|
"description": "Label for the checkbox to enable/disable a style"
|
||||||
|
|
|
@ -5,10 +5,12 @@
|
||||||
/* global CHROME FIREFOX VIVALDI debounce ignoreChromeError */// toolbox.js
|
/* global CHROME FIREFOX VIVALDI debounce ignoreChromeError */// toolbox.js
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
(() => {
|
/* exported iconMan */
|
||||||
|
const iconMan = (() => {
|
||||||
const ICON_SIZES = FIREFOX || CHROME >= 55 && !VIVALDI ? [16, 32] : [19, 38];
|
const ICON_SIZES = FIREFOX || CHROME >= 55 && !VIVALDI ? [16, 32] : [19, 38];
|
||||||
const staleBadges = new Set();
|
const staleBadges = new Set();
|
||||||
const imageDataCache = new Map();
|
const imageDataCache = new Map();
|
||||||
|
const badgeOvr = {color: '', text: ''};
|
||||||
// https://github.com/openstyles/stylus/issues/335
|
// https://github.com/openstyles/stylus/issues/335
|
||||||
let hasCanvas = loadImage(`/images/icon/${ICON_SIZES[0]}.png`)
|
let hasCanvas = loadImage(`/images/icon/${ICON_SIZES[0]}.png`)
|
||||||
.then(({data}) => (hasCanvas = data.some(b => b !== 255)));
|
.then(({data}) => (hasCanvas = data.some(b => b !== 255)));
|
||||||
|
@ -54,6 +56,29 @@
|
||||||
], () => debounce(refreshAllIcons), {runNow: true});
|
], () => debounce(refreshAllIcons), {runNow: true});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
/** Calling with no params clears the override */
|
||||||
|
overrideBadge({text = '', color = ''} = {}) {
|
||||||
|
if (badgeOvr.text === text && badgeOvr.color === color) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
badgeOvr.text = text;
|
||||||
|
badgeOvr.color = color;
|
||||||
|
refreshIconBadgeColor();
|
||||||
|
setBadgeText({text});
|
||||||
|
for (const tabId of tabMan.list()) {
|
||||||
|
if (badgeOvr) {
|
||||||
|
setBadgeText({tabId, text});
|
||||||
|
} else {
|
||||||
|
refreshIconBadgeText(tabId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
chrome.browserAction.setTitle({
|
||||||
|
title: text ? chrome.i18n.getMessage('syncErrorRelogin') : '',
|
||||||
|
}, ignoreChromeError);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
function onPortDisconnected({sender}) {
|
function onPortDisconnected({sender}) {
|
||||||
if (tabMan.get(sender.tab.id, 'styleIds')) {
|
if (tabMan.get(sender.tab.id, 'styleIds')) {
|
||||||
API.updateIconBadge.call({sender}, [], {lazyBadge: true});
|
API.updateIconBadge.call({sender}, [], {lazyBadge: true});
|
||||||
|
@ -61,6 +86,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshIconBadgeText(tabId) {
|
function refreshIconBadgeText(tabId) {
|
||||||
|
if (badgeOvr.text) return;
|
||||||
const text = prefs.get('show-badge') ? `${getStyleCount(tabId)}` : '';
|
const text = prefs.get('show-badge') ? `${getStyleCount(tabId)}` : '';
|
||||||
setBadgeText({tabId, text});
|
setBadgeText({tabId, text});
|
||||||
}
|
}
|
||||||
|
@ -133,9 +159,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function refreshIconBadgeColor() {
|
function refreshIconBadgeColor() {
|
||||||
const color = prefs.get(prefs.get('disableAll') ? 'badgeDisabled' : 'badgeNormal');
|
|
||||||
setBadgeBackgroundColor({
|
setBadgeBackgroundColor({
|
||||||
color,
|
color: badgeOvr.color ||
|
||||||
|
prefs.get(prefs.get('disableAll') ? 'badgeDisabled' : 'badgeNormal'),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/* global API msg */// msg.js
|
/* global API msg */// msg.js
|
||||||
/* global chromeLocal */// storage-util.js
|
/* global chromeLocal */// storage-util.js
|
||||||
/* global compareRevision */// common.js
|
/* global compareRevision */// common.js
|
||||||
|
/* global iconMan */
|
||||||
/* global prefs */
|
/* global prefs */
|
||||||
/* global tokenMan */
|
/* global tokenMan */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
@ -99,8 +100,10 @@ const syncMan = (() => {
|
||||||
}
|
}
|
||||||
await syncMan.syncNow();
|
await syncMan.syncNow();
|
||||||
status.errorMessage = null;
|
status.errorMessage = null;
|
||||||
|
iconMan.overrideBadge();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
status.errorMessage = err.message;
|
status.errorMessage = err.message;
|
||||||
|
iconMan.overrideBadge({text: 'x', color: '#F00'});
|
||||||
// FIXME: should we move this logic to options.js?
|
// FIXME: should we move this logic to options.js?
|
||||||
if (!fromPref) {
|
if (!fromPref) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|
|
@ -53,6 +53,7 @@ const tabMan = (() => {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/** @returns {IterableIterator<number>} */
|
||||||
list() {
|
list() {
|
||||||
return cache.keys();
|
return cache.keys();
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user