#1663 Custom icon WIP

This commit is contained in:
GrzegorzZajac000 2024-09-26 12:03:27 +02:00
parent bd7e423c65
commit a994b0431a
12 changed files with 44 additions and 31 deletions

View File

@ -61,7 +61,8 @@ const generateDefaultStorage = browserInfo => {
extensionVersion: config.ExtensionVersion, extensionVersion: config.ExtensionVersion,
autoSubmitEnabled: false, autoSubmitEnabled: false,
autoSubmitExcludedDomains: defaultAutoSubmitExcludedDomains, autoSubmitExcludedDomains: defaultAutoSubmitExcludedDomains,
attempt: attempt + 1 attempt: attempt + 1,
extIcon: 0 // 0 - default
}); });
}) })
.then(storage => { .then(storage => {

View File

@ -18,46 +18,58 @@
// //
const browser = require('webextension-polyfill'); const browser = require('webextension-polyfill');
const loadFromLocalStorage = require('./loadFromLocalStorage');
const setIcon = async (tabId, active = true, changeTitle = false) => { const getIconObj = async (tabID, isActive) => {
const option = process.env.EXT_PLATFORM === 'Safari' ? 'safari' : ''; const isSafari = process.env.EXT_PLATFORM === 'Safari';
let type = 0;
let typeFilename = '';
let iconFileName = '';
const iconObj = if (isSafari) {
active typeFilename = 'safari';
? { iconFileName = isActive ? 'safari' : 'gray';
path: { } else {
16: browser.runtime.getURL(`images/icons/icon16${option}.png`), const storage = await loadFromLocalStorage(['extIcon']);
32: browser.runtime.getURL(`images/icons/icon32${option}.png`),
48: browser.runtime.getURL(`images/icons/icon48${option}.png`), if (storage && storage?.extIcon) {
96: browser.runtime.getURL(`images/icons/icon96${option}.png`), type = parseInt(storage.extIcon, 10);
128: browser.runtime.getURL(`images/icons/icon128${option}.png`) }
},
tabId if (type !== 0) {
} typeFilename = `_${type}`;
: { }
path: {
16: browser.runtime.getURL('images/icons/icon16gray.png'), iconFileName = isActive ? typeFilename : `${typeFilename}gray`;
32: browser.runtime.getURL('images/icons/icon32gray.png'), }
48: browser.runtime.getURL('images/icons/icon48gray.png'),
96: browser.runtime.getURL('images/icons/icon96gray.png'), return {
128: browser.runtime.getURL('images/icons/icon128gray.png') path: {
}, 16: browser.runtime.getURL(`images/icons/icon16${iconFileName}.png`),
tabId 32: browser.runtime.getURL(`images/icons/icon32${iconFileName}.png`),
}; 48: browser.runtime.getURL(`images/icons/icon48${iconFileName}.png`),
96: browser.runtime.getURL(`images/icons/icon96${iconFileName}.png`),
const iconTitle = active ? '2FAS - Two Factor Authentication' : browser.i18n.getMessage('inActiveTabInfo'); 128: browser.runtime.getURL(`images/icons/icon128${iconFileName}.png`)
},
tabId: tabID
};
};
const setIcon = async (tabID, isActive = true, changeTitle = false) => {
const iconObj = await getIconObj(tabID, isActive);
const iconTitle = isActive ? '2FAS - Two Factor Authentication' : browser.i18n.getMessage('inActiveTabInfo');
if (process.env.EXT_PLATFORM === 'Firefox' || process.env.EXT_PLATFORM === 'Safari') { if (process.env.EXT_PLATFORM === 'Firefox' || process.env.EXT_PLATFORM === 'Safari') {
browser.browserAction.setIcon(iconObj); browser.browserAction.setIcon(iconObj);
if (active || (!active && changeTitle)) { if (isActive || (!isActive && changeTitle)) {
await browser.browserAction.setTitle({ tabId, title: iconTitle }); await browser.browserAction.setTitle({ tabID, title: iconTitle });
} }
} else { } else {
browser.action.setIcon(iconObj); browser.action.setIcon(iconObj);
if (active || (!active && changeTitle)) { if (isActive || (!isActive && changeTitle)) {
await browser.action.setTitle({ tabId, title: iconTitle }); await browser.action.setTitle({ tabID, title: iconTitle });
} }
} }
}; };

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 590 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 901 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB