#1663 Custom icon WIP
@ -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 => {
|
||||||
|
@ -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 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
BIN
src/images/icons/icon128_1.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
src/images/icons/icon128_1gray.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
src/images/icons/icon16_1.png
Normal file
After Width: | Height: | Size: 362 B |
BIN
src/images/icons/icon16_1gray.png
Normal file
After Width: | Height: | Size: 311 B |
BIN
src/images/icons/icon32_1.png
Normal file
After Width: | Height: | Size: 676 B |
BIN
src/images/icons/icon32_1gray.png
Normal file
After Width: | Height: | Size: 590 B |
BIN
src/images/icons/icon48_1.png
Normal file
After Width: | Height: | Size: 901 B |
BIN
src/images/icons/icon48_1gray.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
src/images/icons/icon96_1.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
src/images/icons/icon96_1gray.png
Normal file
After Width: | Height: | Size: 1.3 KiB |