From 1da57aaa445fa2d74099c9223c5ee238f0ca25fb Mon Sep 17 00:00:00 2001 From: glacambre Date: Tue, 20 Mar 2018 22:09:32 +0100 Subject: [PATCH] Create stub that compiles and correctly requires files. --- package.json | 9 +++++---- src/background.ts | 16 ++++++++++++++++ src/content.ts | 3 +++ src/firenvim.d.ts | 29 +++++++++++++++++++++++++++++ src/firenvim.ts | 1 - src/manifest.json | 16 ++++++++++++++-- src/native_manifest.json | 7 +++++++ tsconfig.json | 2 +- 8 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 src/background.ts create mode 100644 src/content.ts create mode 100644 src/firenvim.d.ts delete mode 100644 src/firenvim.ts create mode 100644 src/native_manifest.json diff --git a/package.json b/package.json index 4334812..54e1cc5 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,13 @@ "typescript": "^2.5.3", "web-ext": "^1.8.1", "browserify": "^14.5.0", - "msgpack5": "^3.6.0" + "promised-neovim-client": "^2.0.2" }, "scripts": { - "build": "tsc && browserify build/firenvim.js -o build/firenvim.js && cp src/manifest.json build/manifest.json", - "run": "web-ext run --source-dir=./build --keep-profile-changes --firefox-profile=$HOME/.mozilla/firefox/firenvim.profile", - "package": "web-ext build" + "build": "((cargo build --release && (unlink ~/bin/firenvim ; cp target/release/firenvim ~/bin)) & tsc && browserify target/*.js -o target/background.js && cp src/manifest.json target/manifest.json && cp src/native_manifest.json $HOME/.mozilla/native-messaging-hosts/firenvim.json) || true", + "run": "web-ext run --source-dir=./target --keep-profile-changes --firefox-profile=$HOME/.mozilla/firefox/firenvim.profile", + "package": "web-ext target", + "clean": "rm -rf target" }, "author": "glacambre", "keywords": [ diff --git a/src/background.ts b/src/background.ts new file mode 100644 index 0000000..af4fb39 --- /dev/null +++ b/src/background.ts @@ -0,0 +1,16 @@ +/// + +console.log("Firenvim content script loaded."); +let NvimProcess = require("./NeovimProcess.js").NeovimProcess; +let nvim = new NvimProcess(); + +require("promised-neovim-client").attach(nvim.stdin, nvim.stdout).then((nvim: any) => { + nvim.on("request", (method: any, args: any, resp: any) => { + console.log("request", method, args, resp) + }); + nvim.on("notification", (method: any, args: any) => { + console.log("notification", method, args) + }); +}).catch((err: any) => console.log(err)); + +console.log("Promised-neovim-cleint required."); diff --git a/src/content.ts b/src/content.ts new file mode 100644 index 0000000..f3a57cf --- /dev/null +++ b/src/content.ts @@ -0,0 +1,3 @@ +/// + +console.log("Firenvim content script loaded."); diff --git a/src/firenvim.d.ts b/src/firenvim.d.ts new file mode 100644 index 0000000..676b8a6 --- /dev/null +++ b/src/firenvim.d.ts @@ -0,0 +1,29 @@ +declare class WebextensionEventTarget { + addListener(f: Function): void; + removeListener(f: Function): void; +} + +declare class RuntimeOnConnect extends WebextensionEventTarget{} + +declare class PortError { + message: string; +} + +declare class PortOnDisconnect extends WebextensionEventTarget{} + +declare class PortOnMessage extends WebextensionEventTarget{} + +declare class Port { + name: string; + disconnect(): void; + error: PortError; + onDisconnect: PortOnDisconnect; + onMessage: PortOnMessage; + postMessage(msg: string): void; +} + +declare namespace browser.runtime { + function connect(): Port; + function connectNative(name: string): Port; + let onConnect: RuntimeOnConnect; +} diff --git a/src/firenvim.ts b/src/firenvim.ts deleted file mode 100644 index 7728117..0000000 --- a/src/firenvim.ts +++ /dev/null @@ -1 +0,0 @@ -console.log("hello") diff --git a/src/manifest.json b/src/manifest.json index 9face6e..76a7ee5 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -10,8 +10,20 @@ "matches": [ "" ], - "js": ["firenvim.js"] + "js": ["content.js"] } - ] + ], + "background": { + "scripts": ["background.js"] + }, + + "applications": { + "gecko": { + "id": "firenvim@lacamb.re", + "strict_min_version": "50.0" + } + }, + + "permissions": ["nativeMessaging"] } diff --git a/src/native_manifest.json b/src/native_manifest.json new file mode 100644 index 0000000..441ef36 --- /dev/null +++ b/src/native_manifest.json @@ -0,0 +1,7 @@ +{ + "name": "firenvim", + "description": "Turn Firefox into a Neovim client.", + "path": "/home/me/bin/firenvim", + "type": "stdio", + "allowed_extensions": [ "firenvim@lacamb.re" ] +} diff --git a/tsconfig.json b/tsconfig.json index 8b0c039..1e15452 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "moduleResolution": "Node", "noImplicitAny": true, - "outDir": "./build", + "outDir": "./target", "sourceMap": true, "target": "ES2017", "typeRoots": ["node_modules/@types", "node_modules/web-ext-types/"], -- 2.34.2