From efb7cc98aef256c185a798c1f2388ec2bab146fe Mon Sep 17 00:00:00 2001 From: Hinton Date: Mon, 23 Nov 2020 18:37:04 +0100 Subject: [PATCH] *Wip* Run proxy app through electron --- package.json | 36 +++--------- proxy/global.d.ts | 4 -- proxy/tsconfig.json | 56 ------------------- src/main.ts | 11 +++- {proxy => src/proxy}/ipc.ts | 3 +- .../proxy/native-messaging-proxy.ts | 7 +-- {proxy => src/proxy}/nativemessage.ts | 2 +- 7 files changed, 21 insertions(+), 98 deletions(-) delete mode 100644 proxy/global.d.ts delete mode 100644 proxy/tsconfig.json rename {proxy => src/proxy}/ipc.ts (96%) rename proxy/app.ts => src/proxy/native-messaging-proxy.ts (87%) rename {proxy => src/proxy}/nativemessage.ts (99%) diff --git a/package.json b/package.json index 4f3627fc..7d26b73c 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "build:main": "webpack --config webpack.main.js", "build:renderer": "gulp prebuild:renderer && webpack --config webpack.renderer.js", "build:renderer:watch": "gulp prebuild:renderer && webpack --config webpack.renderer.js --watch", - "build:proxy": "tsc --build proxy", "electron": "npm run build:main && concurrently -k -n Main,Rend -c yellow,cyan \"electron --inspect=5858 ./build --watch\" \"npm run build:renderer:watch\"", "clean:dist": "rimraf ./dist/*", "clean:l10n": "git push origin --delete l10n_master", @@ -43,15 +42,13 @@ "pack:mac:masdev": "npm run clean:dist && electron-builder --mac mas-dev -p never", "pack:win": "npm run clean:dist && electron-builder --win --x64 --ia32 -p never -c.win.certificateSubjectName=\"8bit Solutions LLC\"", "pack:win:ci": "npm run clean:dist && electron-builder --win --x64 --ia32 -p never", - "pack:proxy": "pkg build/proxy/app.js --out-path build/proxies", - "dist:dir": "npm run build && npm run dist:proxy && npm run pack:dir", - "dist:lin": "npm run build && npm run dist:proxy && npm run pack:lin", - "dist:mac": "npm run build && npm run dist:proxy && npm run pack:mac", - "dist:mac:mas": "npm run build && npm run dist:proxy && npm run pack:mac:mas", - "dist:mac:masdev": "npm run build && npm run dist:proxy && npm run pack:mac:masdev", - "dist:win": "npm run build && npm run dist:proxy && npm run pack:win", - "dist:win:ci": "npm run build && npm run dist:proxy && npm run pack:win:ci", - "dist:proxy": "npm run build:proxy && npm run pack:proxy", + "dist:dir": "npm run build && npm run pack:dir", + "dist:lin": "npm run build && npm run pack:lin", + "dist:mac": "npm run build && npm run pack:mac", + "dist:mac:mas": "npm run build && npm run pack:mac:mas", + "dist:mac:masdev": "npm run build && npm run pack:mac:masdev", + "dist:win": "npm run build && npm run pack:win", + "dist:win:ci": "npm run build && npm run pack:win:ci", "publish:lin": "npm run build && npm run clean:dist && electron-builder --linux --x64 -p always", "publish:mac": "npm run build && npm run clean:dist && electron-builder --mac -p always", "publish:mac:mas": "npm run dist:mac:mas && npm run upload:mas", @@ -114,12 +111,6 @@ "target": [ "dmg", "zip" - ], - "extraResources": [ - { - "from": "build/proxies/app-macos", - "to": "proxy" - } ] }, "win": { @@ -130,10 +121,6 @@ "appx" ], "extraResources": [ - { - "from": "build/proxies/app-win.exe", - "to": "proxy.exe" - }, { "from": "node_modules/regedit/vbs", "to": "regedit/vbs", @@ -157,13 +144,7 @@ "Name": "Bitwarden", "Type": "Application", "GenericName": "Password Manager" - }, - "extraResources": [ - { - "from": "build/proxies/app-linux", - "to": "proxy" - } - ] + } }, "dmg": { "icon": "dmg.icns", @@ -290,7 +271,6 @@ "node-abi": "^2.9.0", "node-loader": "^0.6.0", "node-sass": "^4.13.1", - "pkg": "^4.4.9", "rimraf": "^2.6.2", "sass-loader": "^7.1.0", "ts-loader": "^8.0.2", diff --git a/proxy/global.d.ts b/proxy/global.d.ts deleted file mode 100644 index 685934dc..00000000 --- a/proxy/global.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare module 'node-ipc' { - const x: any; - export = x; -} diff --git a/proxy/tsconfig.json b/proxy/tsconfig.json deleted file mode 100644 index e574539a..00000000 --- a/proxy/tsconfig.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "compilerOptions": { - "moduleResolution": "node", - "noImplicitAny": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "module": "CommonJS", - "target": "ES2016", - "allowJs": true, - "sourceMap": true, - "types": ["sweetalert2", "node"], - "baseUrl": ".", - "outDir": "../build/proxy", - "paths": { - "tldjs": [ - "jslib/src/misc/tldjs.noop" - ], - "jslib/*": [ - "jslib/src/*" - ], - "@angular/*": [ - "node_modules/@angular/*" - ], - "electron": [ - "node_modules/electron" - ], - "electron-log": [ - "node_modules/electron-log" - ], - "electron-store": [ - "node_modules/electron-store" - ], - "node": [ - "node_modules/@types/node" - ], - "duo_web_sdk": [ - "node_modules/duo_web_sdk" - ] - } - }, - "angularCompilerOptions": { - "preserveWhitespaces": true - }, - "exclude": [ - "node_modules", - "jslib/node_modules", - "dist", - "dist-safari", - "jslib/dist", - "build", - "jslib/spec", - "jslib/src/cli", - "jslib/src/services/nodeApi.service.ts", - "jslib/src/services/lowdbStorage.service.ts" - ] -} diff --git a/src/main.ts b/src/main.ts index 39405e9c..fee26a82 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,6 +19,7 @@ import { TrayMain } from 'jslib/electron/tray.main'; import { UpdaterMain } from 'jslib/electron/updater.main'; import { WindowMain } from 'jslib/electron/window.main'; import { NativeMessagingMain } from './main/nativeMessaging.main'; +import { NativeMessagingProxy } from './proxy/native-messaging-proxy'; export class Main { logService: ElectronLogService; @@ -183,5 +184,11 @@ export class Main { } } -const main = new Main(); -main.bootstrap(); +console.error(process.argv); +if (process.argv.some(arg => arg.indexOf('chrome-extension://') !== -1 || arg.indexOf('{') !== -1)) { + const proxy = new NativeMessagingProxy(); + proxy.run(); +} else { + const main = new Main(); + main.bootstrap(); +} diff --git a/proxy/ipc.ts b/src/proxy/ipc.ts similarity index 96% rename from proxy/ipc.ts rename to src/proxy/ipc.ts index 3009f198..2bd9eb5e 100644 --- a/proxy/ipc.ts +++ b/src/proxy/ipc.ts @@ -6,8 +6,9 @@ ipc.config.retry = 1500; ipc.config.logger = console.warn; // Stdout is used for native messaging export default class IPC { + onMessage: (message: object) => void + private connected = false; - public onMessage: (message: object) => void connect() { ipc.connectTo('bitwarden', () => { diff --git a/proxy/app.ts b/src/proxy/native-messaging-proxy.ts similarity index 87% rename from proxy/app.ts rename to src/proxy/native-messaging-proxy.ts index c67b4643..59e96a25 100644 --- a/proxy/app.ts +++ b/src/proxy/native-messaging-proxy.ts @@ -1,13 +1,11 @@ import NativeMessage from './nativemessage'; import IPC from './ipc'; -const args = process.argv.slice(2); - // Proxy is a lightweight application which provides bi-directional communication // between the browser extension and a running desktop application. // // Browser extension <-[native messaging]-> proxy <-[ipc]-> desktop -class Proxy { +export class NativeMessagingProxy { private ipc: IPC; private nativeMessage: NativeMessage; @@ -23,6 +21,3 @@ class Proxy { this.ipc.onMessage = this.nativeMessage.send; } } - -const proxy = new Proxy(); -proxy.run(); diff --git a/proxy/nativemessage.ts b/src/proxy/nativemessage.ts similarity index 99% rename from proxy/nativemessage.ts rename to src/proxy/nativemessage.ts index f3f61633..36601237 100644 --- a/proxy/nativemessage.ts +++ b/src/proxy/nativemessage.ts @@ -1,5 +1,5 @@ /* tslint:disable:no-console */ -import IPC from 'ipc'; +import IPC from './ipc'; // Mostly based on the example from MDN, // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging