Make contextMenus usage Chromium compatible.
This commit is contained in:
parent
8d99e8200b
commit
ded38c7bf7
|
@ -3,17 +3,13 @@ import browser from 'webextension-polyfill';
|
|||
import {Settings} from '../settings/settings.js';
|
||||
import {updateBadge} from '../utilities/badge.js';
|
||||
|
||||
export async function initializeContextMenus(): Promise<void> {
|
||||
const contextMenus: browser.Menus.CreateCreatePropertiesType[] = [
|
||||
{
|
||||
id: 'queue-add-new-link',
|
||||
title: 'Add to Queue',
|
||||
contexts: ['link'],
|
||||
},
|
||||
{
|
||||
id: 'queue-add-new-link-tab',
|
||||
title: 'Add to Queue',
|
||||
contexts: ['tab'],
|
||||
},
|
||||
{
|
||||
id: 'queue-open-next-link-in-new-tab',
|
||||
title: 'Open next link in new tab',
|
||||
|
@ -26,27 +22,39 @@ const contextMenus: browser.Menus.CreateCreatePropertiesType[] = [
|
|||
},
|
||||
];
|
||||
|
||||
if (import.meta.env.VITE_BROWSER === 'firefox') {
|
||||
contextMenus.push({
|
||||
id: 'queue-add-new-link-tab',
|
||||
title: 'Add to Queue',
|
||||
contexts: ['tab'],
|
||||
});
|
||||
}
|
||||
|
||||
const contextMenuIds = new Set<string>(
|
||||
contextMenus.map(({id}) => id ?? 'queue-unknown'),
|
||||
);
|
||||
|
||||
export function initializeContextMenus(): void {
|
||||
await browser.contextMenus.removeAll();
|
||||
|
||||
for (const contextMenu of contextMenus) {
|
||||
browser.contextMenus.create(contextMenu, contextCreated);
|
||||
}
|
||||
|
||||
browser.contextMenus.onClicked.addListener(contextClicked);
|
||||
browser.contextMenus.onClicked.addListener(async (info, tab) => {
|
||||
await contextClicked(contextMenuIds, info, tab);
|
||||
});
|
||||
}
|
||||
|
||||
function contextCreated(): void {
|
||||
const error = browser.runtime.lastError;
|
||||
|
||||
if (error !== null && error !== undefined) {
|
||||
console.error('Queue', error);
|
||||
console.error('Queue', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function contextClicked(
|
||||
contextMenuIds: Set<string>,
|
||||
info: browser.Menus.OnClickData,
|
||||
tab?: browser.Tabs.Tab,
|
||||
): Promise<void> {
|
||||
|
|
Loading…
Reference in New Issue