From 2c93385fcee26ad86b9edb2fb63aa420baa665c1 Mon Sep 17 00:00:00 2001 From: Hinton Date: Tue, 29 Dec 2020 20:53:29 +0100 Subject: [PATCH 1/2] Fix electron error on native messaging --- src/entry.ts | 33 +++++++++++++++++++++++++++++++++ src/main.ts | 23 +---------------------- webpack.main.js | 2 +- 3 files changed, 35 insertions(+), 23 deletions(-) create mode 100644 src/entry.ts diff --git a/src/entry.ts b/src/entry.ts new file mode 100644 index 0000000000..2c6704a3ae --- /dev/null +++ b/src/entry.ts @@ -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(); +} diff --git a/src/main.ts b/src/main.ts index 5ad6540cd0..d2d2350a52 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import { app, globalShortcut } from 'electron'; +import { app } from 'electron'; import * as path from 'path'; 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 { 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,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(); -} diff --git a/webpack.main.js b/webpack.main.js index ab1b1c3734..2f8264f7b1 100644 --- a/webpack.main.js +++ b/webpack.main.js @@ -41,7 +41,7 @@ const main = { __filename: false, }, entry: { - 'main': './src/main.ts', + 'main': './src/entry.ts', }, optimization: { minimize: false, From ef785eab8181397f708af7862758bd092b9b34b5 Mon Sep 17 00:00:00 2001 From: Hinton Date: Tue, 29 Dec 2020 21:01:47 +0100 Subject: [PATCH 2/2] Spelling --- src/entry.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/entry.ts b/src/entry.ts index 2c6704a3ae..d4cd12cfe6 100644 --- a/src/entry.ts +++ b/src/entry.ts @@ -1,6 +1,6 @@ import { NativeMessagingProxy } from './proxy/native-messaging-proxy'; -// We need to import the other dependencies using `reqiuire` since import will +// We need to import the other dependencies using `require` 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