Pass plugins via ipc instead of env to fix loading of plugins on Windows
Summary: Fixed the issue with empty plugin list on Windows because of env var length limit Reviewed By: passy Differential Revision: D19411466 fbshipit-source-id: 7fa390f7dd342e23e965b2135fbeb8e88e5857ef
This commit is contained in:
committed by
Facebook Github Bot
parent
2f3b9e1be9
commit
73e0f9035a
@@ -20,4 +20,5 @@ module.exports = {
|
||||
},
|
||||
getCurrentWindow: () => ({isFocused: () => true}),
|
||||
},
|
||||
ipcRenderer: {},
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ import dispatcher, {
|
||||
requirePlugin,
|
||||
} from '../plugins.tsx';
|
||||
import path from 'path';
|
||||
import {remote} from 'electron';
|
||||
import {ipcRenderer, remote} from 'electron';
|
||||
import {FlipperPlugin} from 'flipper';
|
||||
import reducers from '../../reducers/index.tsx';
|
||||
import {init as initLogger} from '../../fb-stubs/Logger.tsx';
|
||||
@@ -31,24 +31,20 @@ test('dispatcher dispatches REGISTER_PLUGINS', () => {
|
||||
expect(actions.map(a => a.type)).toContain('REGISTER_PLUGINS');
|
||||
});
|
||||
|
||||
test('getDynamicPlugins returns empty array', () => {
|
||||
// $FlowFixMe process.env not defined in electron API spec
|
||||
remote.process.env.PLUGINS = null;
|
||||
test('getDynamicPlugins returns empty array on errors', () => {
|
||||
ipcRenderer.sendSync = jest.fn();
|
||||
ipcRenderer.sendSync.mockImplementation(() => {
|
||||
console.log('aaa');
|
||||
throw new Error('ooops');
|
||||
});
|
||||
const res = getDynamicPlugins();
|
||||
expect(res).toEqual([]);
|
||||
});
|
||||
|
||||
test('getDynamicPlugins returns empty array for invalid JSON', () => {
|
||||
// $FlowFixMe process.env not defined in electron API spec
|
||||
remote.process.env.PLUGINS = 'invalid JOSN }}[]';
|
||||
const res = getDynamicPlugins();
|
||||
expect(res).toEqual([]);
|
||||
});
|
||||
|
||||
test('getDynamicPlugins from env', () => {
|
||||
test('getDynamicPlugins from main process via ipc', () => {
|
||||
const plugins = [{name: 'test'}];
|
||||
// $FlowFixMe process.env not defined in electron API spec
|
||||
remote.process.env.PLUGINS = JSON.stringify(plugins);
|
||||
ipcRenderer.sendSync = jest.fn();
|
||||
ipcRenderer.sendSync.mockReturnValue(plugins);
|
||||
const res = getDynamicPlugins();
|
||||
expect(res).toEqual(plugins);
|
||||
});
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
addDisabledPlugins,
|
||||
addFailedPlugins,
|
||||
} from '../reducers/plugins';
|
||||
import {remote} from 'electron';
|
||||
import {ipcRenderer} from 'electron';
|
||||
import GK from '../fb-stubs/GK';
|
||||
import {FlipperBasePlugin} from '../plugin';
|
||||
import {setupMenuBar} from '../MenuBar';
|
||||
@@ -110,9 +110,7 @@ function getBundledPlugins(): Array<PluginDefinition> {
|
||||
export function getDynamicPlugins() {
|
||||
let dynamicPlugins: Array<PluginDefinition> = [];
|
||||
try {
|
||||
dynamicPlugins = JSON.parse(
|
||||
(remote && remote.process.env.PLUGINS) || process.env.PLUGINS || '[]',
|
||||
);
|
||||
dynamicPlugins = ipcRenderer.sendSync('get-dynamic-plugins');
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,9 @@ compilePlugins(
|
||||
pluginPaths,
|
||||
path.join(flipperDir, 'plugins'),
|
||||
).then(dynamicPlugins => {
|
||||
process.env.PLUGINS = JSON.stringify(dynamicPlugins);
|
||||
ipcMain.on('get-dynamic-plugins', event => {
|
||||
event.returnValue = dynamicPlugins;
|
||||
});
|
||||
pluginsCompiled = true;
|
||||
tryCreateWindow();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user