actually switch the icon

This commit is contained in:
tophf 2022-02-15 19:32:31 +03:00
parent 58140a56cf
commit b9d7ceb4b7
3 changed files with 23 additions and 12 deletions

View File

@ -1139,7 +1139,7 @@
"description": "Heading for options section on manage page." "description": "Heading for options section on manage page."
}, },
"optionsIconAuto": { "optionsIconAuto": {
"message": "Match the Dark/Light mode automatically" "message": "Match the Dark/Light mode"
}, },
"optionsIconDark": { "optionsIconDark": {
"message": "Dark browser themes" "message": "Dark browser themes"

View File

@ -1,5 +1,6 @@
/* global API */// msg.js /* global API */// msg.js
/* global addAPI bgReady */// common.js /* global addAPI bgReady */// common.js
/* global colorScheme */
/* global prefs */ /* global prefs */
/* global tabMan */ /* global tabMan */
/* global CHROME FIREFOX UA debounce ignoreChromeError */// toolbox.js /* global CHROME FIREFOX UA debounce ignoreChromeError */// toolbox.js
@ -13,7 +14,7 @@ const iconMan = (() => {
const badgeOvr = {color: '', text: ''}; const badgeOvr = {color: '', text: ''};
// https://github.com/openstyles/stylus/issues/1287 Fenix can't use custom ImageData // https://github.com/openstyles/stylus/issues/1287 Fenix can't use custom ImageData
const FIREFOX_ANDROID = FIREFOX && UA.mobile; const FIREFOX_ANDROID = FIREFOX && UA.mobile;
let isDark;
// https://github.com/openstyles/stylus/issues/335 // https://github.com/openstyles/stylus/issues/335
let hasCanvas = FIREFOX_ANDROID ? false : loadImage(`/images/icon/${ICON_SIZES[0]}.png`) let hasCanvas = FIREFOX_ANDROID ? false : loadImage(`/images/icon/${ICON_SIZES[0]}.png`)
.then(({data}) => (hasCanvas = data.some(b => b !== 255))); .then(({data}) => (hasCanvas = data.some(b => b !== 255)));
@ -37,13 +38,17 @@ const iconMan = (() => {
chrome.webNavigation.onCommitted.addListener(({tabId, frameId}) => { chrome.webNavigation.onCommitted.addListener(({tabId, frameId}) => {
if (!frameId) tabMan.set(tabId, 'styleIds', undefined); if (!frameId) tabMan.set(tabId, 'styleIds', undefined);
}); });
chrome.runtime.onConnect.addListener(port => { chrome.runtime.onConnect.addListener(port => {
if (port.name === 'iframe') { if (port.name === 'iframe') {
port.onDisconnect.addListener(onPortDisconnected); port.onDisconnect.addListener(onPortDisconnected);
} }
}); });
colorScheme.onChange(val => {
isDark = val;
if (prefs.get('iconsetAuto')) {
debounce(refreshAllIcons);
}
});
bgReady.all.then(() => { bgReady.all.then(() => {
prefs.subscribe([ prefs.subscribe([
'disableAll', 'disableAll',
@ -55,6 +60,7 @@ const iconMan = (() => {
], () => debounce(refreshAllIconsBadgeText), {runNow: true}); ], () => debounce(refreshAllIconsBadgeText), {runNow: true});
prefs.subscribe([ prefs.subscribe([
'disableAll', 'disableAll',
'iconsetAuto',
'iconset', 'iconset',
], () => debounce(refreshAllIcons), {runNow: true}); ], () => debounce(refreshAllIcons), {runNow: true});
}); });
@ -95,7 +101,12 @@ const iconMan = (() => {
} }
function getIconName(hasStyles = false) { function getIconName(hasStyles = false) {
const iconset = prefs.get('iconset') === 1 ? 'light/' : ''; const iconset = (
prefs.get('iconsetAuto') && isDark != null
? !isDark
: prefs.get('iconset')
) ? 'light/'
: '';
const postfix = prefs.get('disableAll') ? 'x' : !hasStyles ? 'w' : ''; const postfix = prefs.get('disableAll') ? 'x' : !hasStyles ? 'w' : '';
return `${iconset}$SIZE$${postfix}`; return `${iconset}$SIZE$${postfix}`;
} }

View File

@ -78,13 +78,6 @@
<div class="block"> <div class="block">
<h1 i18n-text="optionsCustomizeIcon"></h1> <h1 i18n-text="optionsCustomizeIcon"></h1>
<div class="items"> <div class="items">
<label>
<span i18n-text="optionsIconAuto"></span>
<span class="onoffswitch">
<input type="checkbox" id="iconsetAuto" class="slider">
<span></span>
</span>
</label>
<label> <label>
<span i18n-text="optionsIconDark"></span> <span i18n-text="optionsIconDark"></span>
<div class="iconset"> <div class="iconset">
@ -103,6 +96,13 @@
<img src="/images/icon/light/16x.png"> <img src="/images/icon/light/16x.png">
</div> </div>
</label> </label>
<label>
<span i18n-text="optionsIconAuto"></span>
<span class="onoffswitch">
<input type="checkbox" id="iconsetAuto" class="slider">
<span></span>
</span>
</label>
</div> </div>
</div> </div>