From 33f34650dfe21a7bbd2d4ec34bf311d30d8b9417 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Thu, 23 Aug 2018 02:56:19 -0700 Subject: [PATCH] Fix plugin resolution on Linux Summary: Linux appears to spawn a completely separate browser process whereas MacOS either forks or uses a thread. Either way, Linux no longer has access to the parent process's environment variables we use to look up plugins. Using the remote module fixes that. In the medium term, we should convert the `plugin` module to not rely on import effects and instead use the IPC mechanism, making the plugin resolution asynchronous: https://electronjs.org/docs/api/web-contents#contentssendchannel-arg1-arg2- That would also allow us to do the plugin resolution while starting up the browser window, lowering the startup time. Reviewed By: danielbuechele Differential Revision: D9423628 fbshipit-source-id: 76351f267864147c4494aadaf4e16ea636952118 --- src/plugins/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/plugins/index.js b/src/plugins/index.js index c6b207286..429ff795b 100644 --- a/src/plugins/index.js +++ b/src/plugins/index.js @@ -10,8 +10,11 @@ import React from 'react'; import ReactDOM from 'react-dom'; import * as Sonar from 'sonar'; import {SonarPlugin, SonarBasePlugin} from '../plugin.js'; +import {remote} from 'electron'; const plugins = new Map(); +// $FlowFixMe process.env not defined in electron API spec +const remoteEnv = remote.process.env; // expose Sonar and exact globally for dynamically loaded plugins window.React = React; @@ -26,15 +29,14 @@ const addIfNotAdded = plugin => { let disabledPlugins = []; try { - disabledPlugins = - JSON.parse(window.process.env.CONFIG || '{}').disabledPlugins || []; + disabledPlugins = JSON.parse(remoteEnv.CONFIG || '{}').disabledPlugins || []; } catch (e) { console.error(e); } // Load dynamic plugins try { - JSON.parse(window.process.env.PLUGINS || '[]').forEach(addIfNotAdded); + JSON.parse(remoteEnv.PLUGINS || '[]').forEach(addIfNotAdded); } catch (e) { console.error(e); }