From 08c3f467cf140cc19e89bcd276f34dd7fc205309 Mon Sep 17 00:00:00 2001 From: Bauke Date: Wed, 23 Mar 2022 14:02:08 +0100 Subject: [PATCH] Replace manifest file with createManifest function. --- source/manifest.json | 37 --------------------------------- source/manifest.ts | 49 ++++++++++++++++++++++++++++++++++++++++++++ vite.config.ts | 4 +++- 3 files changed, 52 insertions(+), 38 deletions(-) delete mode 100644 source/manifest.json create mode 100644 source/manifest.ts diff --git a/source/manifest.json b/source/manifest.json deleted file mode 100644 index 08996e1..0000000 --- a/source/manifest.json +++ /dev/null @@ -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}" - } - } -} diff --git a/source/manifest.ts b/source/manifest.ts new file mode 100644 index 0000000..6d6cded --- /dev/null +++ b/source/manifest.ts @@ -0,0 +1,49 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + +export default function createManifest( + target: string, +): Record { + const manifest: Record = { + 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; +} diff --git a/vite.config.ts b/vite.config.ts index 3fb506f..f6cec9d 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -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, }), ],