Replace manifest file with createManifest function.

This commit is contained in:
Bauke 2022-03-23 14:02:08 +01:00
parent 7b63504323
commit 08c3f467cf
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
3 changed files with 52 additions and 38 deletions

View File

@ -1,37 +0,0 @@
{
"manifest_version": 2,
"name": "Fangs",
"description": "Inject custom DuckDuckGo Bangs into your browsing experience.",
"version": "0.1.3",
"permissions": [
"storage",
"tabs",
"webNavigation"
],
"content_security_policy": "script-src 'self'; object-src 'self'; style-src 'unsafe-inline'",
"web_accessible_resources": [
"assets/**"
],
"icons": {
"128": "assets/fangs-128.png"
},
"browser_action": {
"default_icon": {
"128": "assets/fangs-128.png"
}
},
"options_ui": {
"page": "options/index.html",
"open_in_tab": true
},
"background": {
"scripts": [
"background-scripts/initialize.ts"
]
},
"applications": {
"gecko": {
"id": "{cbb8b06b-9d6f-42f2-9d8d-7581f411653c}"
}
}
}

49
source/manifest.ts Normal file
View File

@ -0,0 +1,49 @@
/* eslint-disable @typescript-eslint/naming-convention */
export default function createManifest(
target: string,
): Record<string, unknown> {
const manifest: Record<string, unknown> = {
name: 'Fangs',
description:
'Inject custom DuckDuckGo Bangs into your browsing experience.',
version: '0.1.3',
permissions: ['storage', 'tabs', 'webNavigation'],
options_ui: {
page: 'options/index.html',
open_in_tab: true,
},
};
const icons = {
128: 'assets/fangs-128.png',
};
const browserAction = {
default_icon: icons,
};
const backgroundScript = 'background-scripts/initialize.ts';
if (target === 'chromium') {
manifest.manifest_version = 3;
manifest.action = browserAction;
manifest.background = {
service_worker: backgroundScript,
type: 'module',
};
} else {
manifest.manifest_version = 2;
manifest.browser_action = browserAction;
manifest.background = {
scripts: [backgroundScript],
};
manifest.applications = {
gecko: {
id: '{cbb8b06b-9d6f-42f2-9d8d-7581f411653c}',
},
};
}
return manifest;
}

View File

@ -9,6 +9,8 @@ import {defineConfig} from 'vite';
import preactPreset from '@preact/preset-vite';
import webExtension from 'vite-plugin-web-extension';
import createManifest from './source/manifest.js';
const targetBrowser = process.env.VITE_BROWSER ?? 'firefox';
process.env.VITE_BROWSER = targetBrowser;
@ -47,7 +49,7 @@ export default defineConfig({
webExtension({
assets: 'assets',
browser: targetBrowser,
manifest: path.join(sourceDir, 'manifest.json'),
manifest: () => createManifest(targetBrowser),
webExtConfig,
}),
],