Skip to content

Commit

Permalink
feat(extensions): simplify context menu setup if only 1 domain is con…
Browse files Browse the repository at this point in the history
…figured
  • Loading branch information
edmundhung committed Aug 13, 2021
1 parent 39a8f56 commit b6308be
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions packages/extensions/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,33 @@ async function updateContextMenu(
): Promise<void> {
await browser.contextMenus.removeAll();

browser.contextMenus.create({
id: 'maildog',
title: 'maildog',
contexts: ['all'],
});
const list = Object.entries(emailsByDomain);

if (list.length === 0) {
return;
}

for (const [domain, emails] of Object.entries(emailsByDomain)) {
if (list.length > 1) {
browser.contextMenus.create({
id: `maildog-${domain}`,
parentId: 'maildog',
title: domain,
id: 'maildog',
title: 'maildog',
contexts: ['all'],
});
}

for (const [domain, emails] of list) {
if (list.length > 1) {
browser.contextMenus.create({
id: `maildog-${domain}`,
parentId: 'maildog',
title: domain,
});
} else {
browser.contextMenus.create({
id: `maildog-${domain}`,
title: `maildog (${domain})`,
});
}

for (const email of emails) {
browser.contextMenus.create({
Expand Down

0 comments on commit b6308be

Please sign in to comment.