From e5570dbedc1aeeefd98671e092973d7e381abf48 Mon Sep 17 00:00:00 2001 From: GrzegorzZajac000 Date: Thu, 26 Sep 2024 13:02:51 +0200 Subject: [PATCH] #1663 Custom icon WIP --- package.json | 1 + src/_locales/en/general.json | 1 + src/_locales/en/optionsPage.json | 3 +- src/background/functions/setIcon.js | 6 ++-- src/optionsPage/functions/index.js | 1 + src/optionsPage/functions/setIconSelect.js | 37 ++++++++++++++++++++++ src/optionsPage/optionsPage.js | 3 +- src/optionsPage/optionsPage.scss | 1 + src/optionsPage/styles/_content.scss | 5 +++ src/views/optionsViews/firefox.html | 6 ++++ src/views/optionsViews/normal.html | 6 ++++ 11 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 src/optionsPage/functions/setIconSelect.js diff --git a/package.json b/package.json index 0353c0e..c753c0e 100644 --- a/package.json +++ b/package.json @@ -112,6 +112,7 @@ "dependencies": { "@babel/runtime": "^7.24.7", "qrcode": "^1.5.3", + "slim-select": "^2.9.0", "uuid": "^10.0.0" } } diff --git a/src/_locales/en/general.json b/src/_locales/en/general.json index e522d2e..7f5e1f0 100644 --- a/src/_locales/en/general.json +++ b/src/_locales/en/general.json @@ -19,6 +19,7 @@ "add": "Add", "cancel": "Cancel", "shortcut": "Shortcut", + "icon": "Icon", "options": "Options", "neverShowAgain": "Never show again", "isNotSupportedByExt": "is not supported by 2FAS Extension", diff --git a/src/_locales/en/optionsPage.json b/src/_locales/en/optionsPage.json index 50d7807..1c4258d 100644 --- a/src/_locales/en/optionsPage.json +++ b/src/_locales/en/optionsPage.json @@ -41,5 +41,6 @@ "optionsDomainRequired": "Domain is required", "optionsDomainTooLong": "Domain is too long", "optionsDomainIncorrect": "Domain is not correct", - "optionsDomainExists": "Domain exists on excluded list" + "optionsDomainExists": "Domain exists on excluded list", + "optionsIconDesc": "Choose an icon for the 2FAS Browser Extension to personalize its appearance in your browser." } \ No newline at end of file diff --git a/src/background/functions/setIcon.js b/src/background/functions/setIcon.js index bc24f27..3ee5d43 100644 --- a/src/background/functions/setIcon.js +++ b/src/background/functions/setIcon.js @@ -18,7 +18,7 @@ // const browser = require('webextension-polyfill'); -const loadFromLocalStorage = require('./loadFromLocalStorage'); +const loadFromLocalStorage = require('../../localStorage/loadFromLocalStorage'); const getIconObj = async (tabID, isActive) => { const isSafari = process.env.EXT_PLATFORM === 'Safari'; @@ -63,13 +63,13 @@ const setIcon = async (tabID, isActive = true, changeTitle = false) => { browser.browserAction.setIcon(iconObj); if (isActive || (!isActive && changeTitle)) { - await browser.browserAction.setTitle({ tabID, title: iconTitle }); + await browser.browserAction.setTitle({ tabId: tabID, title: iconTitle }); } } else { browser.action.setIcon(iconObj); if (isActive || (!isActive && changeTitle)) { - await browser.action.setTitle({ tabID, title: iconTitle }); + await browser.action.setTitle({ tabId: tabID, title: iconTitle }); } } }; diff --git a/src/optionsPage/functions/index.js b/src/optionsPage/functions/index.js index df8b0b6..35b2a4e 100644 --- a/src/optionsPage/functions/index.js +++ b/src/optionsPage/functions/index.js @@ -53,6 +53,7 @@ exports.setExtNameUpdateForm = require('./setExtNameUpdateForm'); exports.setExtVersion = require('./setExtVersion'); exports.setPinInfoBtns = require('./setPinInfoBtns'); exports.setHamburger = require('./setHamburger'); +exports.setIconSelect = require('./setIconSelect'); exports.setImportDefaultExcludedDomains = require('./setImportDefaultExcludedDomains'); exports.setLoggingToggle = require('./setLoggingToggle'); exports.setMenuLinks = require('./setMenuLinks'); diff --git a/src/optionsPage/functions/setIconSelect.js b/src/optionsPage/functions/setIconSelect.js new file mode 100644 index 0000000..4d3fb6c --- /dev/null +++ b/src/optionsPage/functions/setIconSelect.js @@ -0,0 +1,37 @@ +const SlimSelect = require('slim-select'); +const browser = require('webextension-polyfill'); +const saveToLocalStorage = require('../../localStorage/saveToLocalStorage'); +const checkTabCS = require('../../background/functions/checkTabCS'); + +const setIconSelect = () => { + // eslint-disable-next-line no-new + new SlimSelect({ + select: '#twofas-icon-select', + data: [ + { + html: `DefaultDefault`, + text: 'Default', + value: 0 + }, + { + html: `Type1Type 1`, + text: 'Type 1', + value: 1 + } + ], + settings: { + showSearch: false, + closeOnSelect: true + }, + events: { + afterChange: async item => { + const tabID = await browser.tabs.query({ active: true, currentWindow: true }).then(tabs => tabs[0].id); + + await saveToLocalStorage({ extIcon: parseInt(item[0].value, 10) }); + await checkTabCS(tabID); + } + } + }); +}; + +module.exports = setIconSelect; diff --git a/src/optionsPage/optionsPage.js b/src/optionsPage/optionsPage.js index a11683f..264611c 100644 --- a/src/optionsPage/optionsPage.js +++ b/src/optionsPage/optionsPage.js @@ -25,7 +25,7 @@ const TwoFasNotification = require('../notification'); const SDK = require('../sdk'); const extPageOnMessage = require('../partials/extPageOnMessage'); const { delay, storeLog, handleTargetBlank, hidePreloader, storageValidation } = require('../partials'); -const { generateDevicesList, setLoggingToggle, setContextMenuToggle, setPushRadio, setPinInfo, setExtName, setExtNameUpdateForm, setModalsListeners, setAdvanced, setMenuLinks, setPinInfoBtns, setShortcutBox, setHamburger, setExtVersion, generateShortcutBox, generateShortcutLink, showIntegrityError, generateDomainsList, setImportDefaultExcludedDomains, setAutoSubmitSwitch } = require('./functions'); +const { generateDevicesList, setLoggingToggle, setContextMenuToggle, setPushRadio, setPinInfo, setExtName, setExtNameUpdateForm, setModalsListeners, setAdvanced, setMenuLinks, setPinInfoBtns, setShortcutBox, setHamburger, setExtVersion, generateShortcutBox, generateShortcutLink, showIntegrityError, generateDomainsList, setImportDefaultExcludedDomains, setAutoSubmitSwitch, setIconSelect } = require('./functions'); const init = async storage => { i18n(); @@ -67,6 +67,7 @@ const init = async storage => { .then(setPushRadio) .then(setHamburger) .then(handleTargetBlank) + .then(setIconSelect) .then(() => browser.runtime.onMessage.addListener(extPageOnMessage)) .then(() => hidePreloader()); }; diff --git a/src/optionsPage/optionsPage.scss b/src/optionsPage/optionsPage.scss index 05c3ef0..0615244 100644 --- a/src/optionsPage/optionsPage.scss +++ b/src/optionsPage/optionsPage.scss @@ -18,6 +18,7 @@ // @import "../global-styles/variables", "../global-styles/global", "../global-styles/input", "../global-styles/buttons", "../global-styles/shortcut", "styles/modal"; +@import url('/node_modules/slim-select/dist/slimselect.css'); .twofas-options-page { background-color: $bg; diff --git a/src/optionsPage/styles/_content.scss b/src/optionsPage/styles/_content.scss index b773dbc..23758bb 100644 --- a/src/optionsPage/styles/_content.scss +++ b/src/optionsPage/styles/_content.scss @@ -614,6 +614,11 @@ } } + &-icon { + margin-top: 20px; + max-width: 305px; + } + &-advanced { margin-bottom: 20px; margin-top: 40px; diff --git a/src/views/optionsViews/firefox.html b/src/views/optionsViews/firefox.html index 628dbcd..8852a63 100644 --- a/src/views/optionsViews/firefox.html +++ b/src/views/optionsViews/firefox.html @@ -42,6 +42,12 @@

Use this shortcut to open the 2FAS Browser Extension on any page.

+
+

Icon:

+ +

Choose an icon for the 2FAS Browser Extension to personalize its appearance in your browser.

+ +

diff --git a/src/views/optionsViews/normal.html b/src/views/optionsViews/normal.html index a67b27a..7fa2e08 100644 --- a/src/views/optionsViews/normal.html +++ b/src/views/optionsViews/normal.html @@ -28,6 +28,12 @@

Use this shortcut to open the 2FAS Browser Extension on any page.

+
+

Icon:

+ +

Choose an icon for the 2FAS Browser Extension to personalize its appearance in your browser.

+
+