Skip to content

Commit

Permalink
Fire and forget activation promises
Browse files Browse the repository at this point in the history
  • Loading branch information
mtusnio committed Oct 26, 2024
1 parent 03e057c commit 96c3c61
Showing 1 changed file with 34 additions and 38 deletions.
72 changes: 34 additions & 38 deletions lib/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,59 +78,55 @@ async function activateExtension(tabId, showHelp) {
isActive = true

if (showHelp) {
await chrome.tabs.sendMessage(tabId, {
chrome.tabs.sendMessage(tabId, {
'type': 'showHelp'
});
}

await Promise.all([
chrome.action.setBadgeBackgroundColor({
color: [255, 0, 0, 255],
}),
chrome.action.setBadgeText({
text: 'On',
}),
chrome.action.setIcon({
path: {
16: "images/on_icon-16x16.png",
48: "images/on_icon-48x48.png",
128: "images/on_icon-128x128.png",
192: "images/on_icon-192x192.png",
512: "images/on_icon-512x512.png"
},
})
])
chrome.action.setBadgeBackgroundColor({
color: [255, 0, 0, 255],
})
chrome.action.setBadgeText({
text: 'On',
})
chrome.action.setIcon({
path: {
16: "images/on_icon-16x16.png",
48: "images/on_icon-48x48.png",
128: "images/on_icon-128x128.png",
192: "images/on_icon-192x192.png",
512: "images/on_icon-512x512.png"
},
})

if (!dict) {
await loadDictionary()
}

await chrome.tabs.sendMessage(tabId, {
chrome.tabs.sendMessage(tabId, {
'type': 'enable',
});
}

async function deactivateExtension() {
dict = null;

await Promise.all([
chrome.action.setBadgeBackgroundColor({
color: [0, 0, 0, 0],
}),
chrome.action.setBadgeText({
text: '',
}),
chrome.action.setIcon({
path: {
16: "images/logo-16x16.png",
48: "images/logo-48x48.png",
128: "images/logo-128x128.png",
192: "images/logo-192x192.png",
512: "images/logo-512x512.png"
},
})
]
)
chrome.action.setBadgeBackgroundColor({
color: [0, 0, 0, 0],
})
chrome.action.setBadgeText({
text: '',
})
chrome.action.setIcon({
path: {
16: "images/logo-16x16.png",
48: "images/logo-48x48.png",
128: "images/logo-128x128.png",
192: "images/logo-192x192.png",
512: "images/logo-512x512.png"
},
})


await chrome.storage.local.set({ "enabled": false })
isActive = false
Expand All @@ -142,7 +138,7 @@ async function deactivateExtension() {
for (let i = 0; i < windows.length; ++i) {
let tabs = windows[i].tabs;
for (let j = 0; j < tabs.length; ++j) {
await chrome.tabs.sendMessage(tabs[j].id, {
chrome.tabs.sendMessage(tabs[j].id, {
'type': 'disable'
});
}
Expand Down

0 comments on commit 96c3c61

Please sign in to comment.