From 0a35d630fa843354c7c99824c9dfa95e0cce7211 Mon Sep 17 00:00:00 2001 From: Michal Tusnio Date: Fri, 4 Oct 2024 21:49:02 +0100 Subject: [PATCH] Refactors --- lib/setup.js | 10 +++++----- lib/setup.test.js | 4 ++-- worker.js | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/setup.js b/lib/setup.js index a4b0c97..4346e21 100644 --- a/lib/setup.js +++ b/lib/setup.js @@ -51,11 +51,11 @@ async function activateExtension(tabId) { await loadDictionary() } - chrome.tabs.sendMessage(tabId, { + await chrome.tabs.sendMessage(tabId, { 'type': 'enable', }); - chrome.tabs.sendMessage(tabId, { + await chrome.tabs.sendMessage(tabId, { 'type': 'showHelp' }); @@ -133,14 +133,14 @@ async function deactivateExtension() { for (let i = 0; i < windows.length; ++i) { let tabs = windows[i].tabs; for (let j = 0; j < tabs.length; ++j) { - chrome.tabs.sendMessage(tabs[j].id, { + await chrome.tabs.sendMessage(tabs[j].id, { 'type': 'disable' }); } } } -async function activateExtensionToggle(currentTab) { +async function toggleExtension(currentTab) { const data = await chrome.storage.local.get(["enabled"]) if (data.enabled) { await deactivateExtension(); @@ -150,5 +150,5 @@ async function activateExtensionToggle(currentTab) { } -export { activateExtension, activateExtensionToggle, deactivateExtension, getDictionary, install, loadDictionary }; +export { activateExtension, deactivateExtension, getDictionary, install, loadDictionary, toggleExtension }; diff --git a/lib/setup.test.js b/lib/setup.test.js index 710df1f..7eea64d 100644 --- a/lib/setup.test.js +++ b/lib/setup.test.js @@ -122,7 +122,7 @@ test("activate extension toggle switches correctly", async () => { } ]); - await setup.activateExtensionToggle({ + await setup.toggleExtension({ id: 10 }) let data = await chrome.storage.local.get(["enabled"]) @@ -130,7 +130,7 @@ test("activate extension toggle switches correctly", async () => { expect(sendMessage).toHaveBeenCalledWith(10, { type: "enable" }) - await setup.activateExtensionToggle({ + await setup.toggleExtension({ id: 10 }) data = await chrome.storage.local.get(["enabled"]) diff --git a/worker.js b/worker.js index 54d600a..cae4f3d 100644 --- a/worker.js +++ b/worker.js @@ -56,12 +56,12 @@ chrome.runtime.onInstalled.addListener(async () => { await setup.install() }); -chrome.action.onClicked.addListener(setup.activateExtensionToggle); +chrome.action.onClicked.addListener(setup.toggleExtension); -chrome.tabs.onActivated.addListener(activeInfo => actions.enableTab(activeInfo.tabId)); -chrome.tabs.onUpdated.addListener(function (tabId, changeInfo) { +chrome.tabs.onActivated.addListener(async (activeInfo) => await actions.enableTab(activeInfo.tabId)); +chrome.tabs.onUpdated.addListener(async function (tabId, changeInfo) { if (changeInfo.status === 'complete') { - actions.enableTab(tabId); + await actions.enableTab(tabId); } });