Remove remaining Electron imports from product code: paths & env

Summary:
This diff removes most remaining Electron imports, by storing env and path constants on the RenderHost. As nice side effect those paths are all cached now as well.

To make sure RenderHost is initialised before Flipper itself, forced loading Flipper through a require. Otherwise the setup is super sensitive to circular import statements, since a lot of module initialisation code depends on those paths / env vars.

Reviewed By: nikoant

Differential Revision: D31992230

fbshipit-source-id: 91beb430902272aaf4b051b35cdf12d2fc993347
This commit is contained in:
Michel Weststrate
2021-11-03 07:00:03 -07:00
committed by Facebook GitHub Bot
parent dba09542f9
commit 2e7015388c
20 changed files with 413 additions and 375 deletions

View File

@@ -10,8 +10,6 @@
import React from 'react';
import {styled, colors, FlexColumn} from 'flipper';
import electron from 'electron';
const devToolsNodeId = (url: string) =>
`hermes-chromedevtools-out-of-react-node-${url.replace(/\W+/g, '-')}`;
@@ -28,10 +26,16 @@ function createDevToolsNode(
return existing;
}
// It is necessary to activate chrome devtools in electron
electron.remote.getCurrentWindow().webContents.toggleDevTools();
electron.remote.getCurrentWindow().webContents.closeDevTools();
// It is necessary to deactivate chrome devtools in electron
try {
const electron = require('electron');
if (electron.default) {
electron.default.remote.getCurrentWindow().webContents.toggleDevTools();
electron.default.remote.getCurrentWindow().webContents.closeDevTools();
}
} catch (e) {
console.warn('Failed to close Electron devtools: ', e);
}
const wrapper = document.createElement('div');
wrapper.id = devToolsNodeId(url);
wrapper.style.height = '100%';