1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-28 12:35:40 +01:00

*Wip* Run proxy app through electron

This commit is contained in:
Hinton 2020-11-23 18:37:04 +01:00
parent 4f466fba43
commit efb7cc98ae
7 changed files with 21 additions and 98 deletions

View File

@ -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",

4
proxy/global.d.ts vendored
View File

@ -1,4 +0,0 @@
declare module 'node-ipc' {
const x: any;
export = x;
}

View File

@ -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"
]
}

View File

@ -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();
}

View File

@ -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', () => {

View File

@ -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();

View File

@ -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