Skip to content

Commit

Permalink
Refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
mtusnio committed Oct 4, 2024
1 parent d3813a5 commit 0a35d63
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions lib/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});

Expand Down Expand Up @@ -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();
Expand All @@ -150,5 +150,5 @@ async function activateExtensionToggle(currentTab) {
}


export { activateExtension, activateExtensionToggle, deactivateExtension, getDictionary, install, loadDictionary };
export { activateExtension, deactivateExtension, getDictionary, install, loadDictionary, toggleExtension };

4 changes: 2 additions & 2 deletions lib/setup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ test("activate extension toggle switches correctly", async () => {
}
]);

await setup.activateExtensionToggle({
await setup.toggleExtension({
id: 10
})
let data = await chrome.storage.local.get(["enabled"])
expect(data.enabled).toBe(true)
expect(sendMessage).toHaveBeenCalledWith(10, { type: "enable" })


await setup.activateExtensionToggle({
await setup.toggleExtension({
id: 10
})
data = await chrome.storage.local.get(["enabled"])
Expand Down
8 changes: 4 additions & 4 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down

0 comments on commit 0a35d63

Please sign in to comment.