Extract flipper server instantiation

Summary:
^

This is a very small refactoring and addition to the Flipper Desktop app.

The instantiation of FlipperServer was extracted to a separate function.

This a very tiny change that allows to switch the implementation we use for FlipperServer in a more convenient way.

In this same change, an unused function is added which will create a separate FlipperServer instance that uses a web-socket underneath which makes it possible to use with flipper-server.

So, if interested, it is enough to call that function instead of the one currently in use and it will make Flipper connect to flipper-server instead.

https://pxl.cl/24j8R

Reviewed By: passy

Differential Revision: D36440574

fbshipit-source-id: 94ea2ab7208b898a82ac5e7fd7edd9cb824b4810
This commit is contained in:
Lorenzo Blasa
2022-05-17 04:20:30 -07:00
committed by Facebook GitHub Bot
parent 23b551c8bf
commit eabc1c556e
3 changed files with 27 additions and 4 deletions

View File

@@ -16,6 +16,7 @@
"dependencies": {
"flipper-common": "0.0.0",
"flipper-server-core": "0.0.0",
"flipper-frontend-core": "0.0.0",
"flipper-ui-core": "0.0.0",
"fs-extra": "^10.1.0",
"invariant": "^2.2.2",

View File

@@ -16,7 +16,7 @@ import {
} from 'flipper-plugin';
// eslint-disable-next-line no-restricted-imports,flipper/no-electron-remote-imports
import {remote} from 'electron';
import os from 'os';
import {createFlipperServer, FlipperServerState} from 'flipper-frontend-core';
import {
FlipperServerImpl,
getEnvironmentInfo,
@@ -27,6 +27,7 @@ import {
setupPrefetcher,
} from 'flipper-server-core';
import {
FlipperServer,
getLogger,
isTest,
Logger,
@@ -41,7 +42,9 @@ import fs from 'fs-extra';
enableMapSet();
async function start() {
async function getEmbeddedFlipperServer(
logger: Logger,
): Promise<FlipperServer> {
const app = remote.app;
const execPath = process.execPath || remote.process.execPath;
const appPath = app.getAppPath();
@@ -49,8 +52,6 @@ async function start() {
const isProduction = !/node_modules[\\/]electron[\\/]/.test(execPath);
const env = process.env;
const environmentInfo = await getEnvironmentInfo(staticPath, isProduction);
const logger = createDelegatedLogger();
setLoggerInstance(logger);
let keytar: any = undefined;
try {
@@ -94,6 +95,24 @@ async function start() {
keytar,
);
return flipperServer;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function getFlipperServer(_logger: Logger): Promise<FlipperServer> {
const flipperServer = await createFlipperServer(
'localhost',
52342,
(_state: FlipperServerState) => {},
);
return flipperServer;
}
async function start() {
const logger = createDelegatedLogger();
setLoggerInstance(logger);
const flipperServer: FlipperServer = await getEmbeddedFlipperServer(logger);
const flipperServerConfig = await flipperServer.exec('get-config');
initializeElectron(flipperServer, flipperServerConfig);

View File

@@ -14,6 +14,9 @@
{
"path": "../flipper-common"
},
{
"path": "../flipper-frontend-core"
},
{
"path": "../flipper-server-core"
},