1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-24 11:55:50 +01:00

Fix electron error on native messaging

This commit is contained in:
Hinton 2020-12-29 20:53:29 +01:00
parent d5249f3acd
commit 2c93385fce
3 changed files with 35 additions and 23 deletions

33
src/entry.ts Normal file
View File

@ -0,0 +1,33 @@
import { NativeMessagingProxy } from './proxy/native-messaging-proxy';
// We need to import the other dependencies using `reqiuire` since import will
// generate `Error: Cannot find module 'electron'`. The cause of this error is
// due to native messaging setting the ELECTRON_RUN_AS_NODE env flag on windows
// which removes the electron module. This flag is needed for stdin/out to work
// properly on Windows.
if (process.argv.some(arg => arg.indexOf('chrome-extension://') !== -1 || arg.indexOf('{') !== -1)) {
if (process.platform === 'darwin') {
// tslint:disable-next-line
const app = require('electron').app;
app.on('ready', () => {
app.dock.hide();
});
}
process.stdout.on('error', (e) => {
if (e.code === 'EPIPE') {
process.exit(0);
}
});
const proxy = new NativeMessagingProxy();
proxy.run();
} else {
// tslint:disable-next-line
const Main = require('./main').Main;
const main = new Main();
main.bootstrap();
}

View File

@ -1,4 +1,4 @@
import { app, globalShortcut } from 'electron'; import { app } from 'electron';
import * as path from 'path'; import * as path from 'path';
import { I18nService } from './services/i18n.service'; import { I18nService } from './services/i18n.service';
@ -19,7 +19,6 @@ import { TrayMain } from 'jslib/electron/tray.main';
import { UpdaterMain } from 'jslib/electron/updater.main'; import { UpdaterMain } from 'jslib/electron/updater.main';
import { WindowMain } from 'jslib/electron/window.main'; import { WindowMain } from 'jslib/electron/window.main';
import { NativeMessagingMain } from './main/nativeMessaging.main'; import { NativeMessagingMain } from './main/nativeMessaging.main';
import { NativeMessagingProxy } from './proxy/native-messaging-proxy';
export class Main { export class Main {
logService: ElectronLogService; logService: ElectronLogService;
@ -183,23 +182,3 @@ export class Main {
}); });
} }
} }
if (process.argv.some(arg => arg.indexOf('chrome-extension://') !== -1 || arg.indexOf('{') !== -1)) {
if (process.platform === 'darwin') {
app.on('ready', () => {
app.dock.hide();
});
}
process.stdout.on('error', (e) => {
if (e.code === 'EPIPE') {
process.exit(0);
}
});
const proxy = new NativeMessagingProxy();
proxy.run();
} else {
const main = new Main();
main.bootstrap();
}

View File

@ -41,7 +41,7 @@ const main = {
__filename: false, __filename: false,
}, },
entry: { entry: {
'main': './src/main.ts', 'main': './src/entry.ts',
}, },
optimization: { optimization: {
minimize: false, minimize: false,