Update the manifest code.

This commit is contained in:
Bauke 2023-04-11 13:16:56 +02:00
parent 544d915233
commit 04b6c23093
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 33 additions and 22 deletions

View File

@ -1,11 +1,17 @@
/* eslint-disable @typescript-eslint/naming-convention */
export default function createManifest(
target: string,
): Record<string, unknown> {
const manifest: Record<string, unknown> = {
import {type Manifest} from 'webextension-polyfill';
/**
* Creates the WebExtension manifest based on the browser target.
*
* @param browser The browser target ("firefox" or "chromium").
* @returns The WebExtension manifest.
*/
export function createManifest(browser: string): Manifest.WebExtensionManifest {
const manifest: Manifest.WebExtensionManifest = {
manifest_version: Number.NaN,
name: 'Queue',
description: 'A WebExtension for queueing links.',
version: '0.3.2',
permissions: ['contextMenus', 'storage'],
options_ui: {
@ -14,36 +20,41 @@ export default function createManifest(
},
};
const icons = {
const icons: Manifest.IconPath = {
128: 'queue.png',
};
manifest.icons = icons;
const browserAction = {
const action: Manifest.ActionManifest = {
default_icon: icons,
};
const backgroundScript = 'background-scripts/initialize.ts';
const backgroundScript = 'background/setup.js';
if (target === 'chromium') {
if (browser === 'firefox') {
manifest.manifest_version = 2;
manifest.background = {
scripts: [backgroundScript],
};
manifest.browser_action = action;
manifest.browser_specific_settings = {
gecko: {
id: '{c3560e6b-00e5-4ab3-b89e-8a54ee5b2c9f}',
strict_min_version: '102.0',
},
};
} else if (browser === 'chromium') {
manifest.manifest_version = 3;
manifest.action = browserAction;
manifest.action = action;
manifest.background = {
service_worker: backgroundScript,
type: 'module',
};
} else {
manifest.manifest_version = 2;
manifest.browser_action = browserAction;
manifest.background = {
scripts: [backgroundScript],
};
manifest.applications = {
gecko: {
id: '{c3560e6b-00e5-4ab3-b89e-8a54ee5b2c9f}',
},
};
throw new Error(`Unknown target browser: ${browser}`);
}
if (Number.isNaN(manifest.manifest_version)) {
throw new TypeError('Manifest version is NaN');
}
return manifest;