From 733ab6f964e314aac042468a54fdb205fe818371 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Wed, 12 Apr 2023 17:39:04 -0500 Subject: [PATCH] Add native package manifest --- package-lock.json | 13 ++++++++++++ package.json | 1 + .../src/{manifest.json => manifest.json5} | 13 ++++++++++-- parasite/src/native-manifest.json5 | 20 +++++++++++++++++++ parasite/webpack.config.ts | 5 +++-- 5 files changed, 48 insertions(+), 4 deletions(-) rename parasite/src/{manifest.json => manifest.json5} (60%) create mode 100644 parasite/src/native-manifest.json5 diff --git a/package-lock.json b/package-lock.json index 513612c..fb4e203 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,9 +5,22 @@ "packages": { "": { "devDependencies": { + "json5": "^2.2.3", "typescript": "^5.0.4" } }, + "node_modules/json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true, + "bin": { + "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/typescript": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", diff --git a/package.json b/package.json index ebd2079..c905eda 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "devDependencies": { + "json5": "^2.2.3", "typescript": "^5.0.4" } } diff --git a/parasite/src/manifest.json b/parasite/src/manifest.json5 similarity index 60% rename from parasite/src/manifest.json rename to parasite/src/manifest.json5 index 01d6cd1..beb418e 100644 --- a/parasite/src/manifest.json +++ b/parasite/src/manifest.json5 @@ -1,15 +1,24 @@ { "name": "Parasite", + "background": { - "scripts": ["background.bundle.js"] + "scripts": ["background.bundle.js"], }, + "browser_action": { "default_popup": "popup.html", "default_icon": "icon-34.png" }, + "icons": {}, "manifest_version": 2, "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'", - "permissions": ["nativeMessaging", "tabs"] + "applications": { + "gecko": { + "id": "ping_pong@example.org", + } + }, + + "permissions": ["nativeMessaging", "tabs"], } diff --git a/parasite/src/native-manifest.json5 b/parasite/src/native-manifest.json5 new file mode 100644 index 0000000..2215e3a --- /dev/null +++ b/parasite/src/native-manifest.json5 @@ -0,0 +1,20 @@ +// This is a file that describes how browsers should call the native messenger. +// +// On firefox, we just need to put this file in +// ~/.mozilla/native-messaging-hosts/[name].json +// See this[1] page for more details. +// +// On chrome, we need to put it in +// ~/.config/google-chrome/NativeMessagingHosts/[name].json +// See this[2] page for more details. +// +// [1]: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_manifests#linux +// [2]: https://developer.chrome.com/docs/apps/nativeMessaging/#native-messaging-host-location + +{ + "name": "io.mzhang.navigation_tools.parasite_messenger", + "description": "Example host for native messaging", + "path": "/path/to/native-messaging/app/ping_pong.py", + "type": "stdio", + "allowed_extensions": ["ping_pong@example.org"], +} diff --git a/parasite/webpack.config.ts b/parasite/webpack.config.ts index 0faa842..efa979b 100644 --- a/parasite/webpack.config.ts +++ b/parasite/webpack.config.ts @@ -1,5 +1,6 @@ import path from "path"; import webpack from "webpack"; +import json5 from "json5"; import CopyWebpackPlugin from "copy-webpack-plugin"; @@ -46,9 +47,9 @@ const options: webpack.Configuration = { // Copy the manifest, adding in the version and the description from the // package.json file. { - from: "src/manifest.json", + from: "src/manifest.json5", transform: (content, _) => { - const oldContent = JSON.parse(content.toString()); + const oldContent = json5.parse(content.toString()); const newContent = { description: process.env.npm_package_description, version: process.env.npm_package_version,