Launch early, even if not ready

Summary:
Flipper Launcher downloads, unpacks, launches Flipper, and closes itself.

This is fine except for the fact that Flipper may be initiating and thus there's a gap of a few seconds until engineers see the main Flipper UI.

This change improves this by launching earlier, even if just showing a loading page until Flipper is actually ready.

Reviewed By: passy, aigoncharov

Differential Revision: D48824479

fbshipit-source-id: aa6147a09f313d80592c9b08d089660ba73773a4
This commit is contained in:
Lorenzo Blasa
2023-08-30 05:08:26 -07:00
committed by Facebook GitHub Bot
parent 3e8f94ceda
commit 2858259497
3 changed files with 84 additions and 7 deletions

View File

@@ -72,6 +72,8 @@ const verifyAuthToken = (req: http.IncomingMessage): boolean => {
return true;
};
let isReady = false;
/**
* Orchestrates the creation of the HTTP server, proxy, and WS server.
* @param config Server configuration.
@@ -108,7 +110,10 @@ async function startHTTPServer(config: Config): Promise<{
});
app.get('/', (_req, res) => {
fs.readFile(path.join(config.staticPath, config.entry), (_err, content) => {
const resource = isReady
? path.join(config.staticPath, config.entry)
: path.join(config.staticPath, 'loading.html');
fs.readFile(resource, (_err, content) => {
res.end(content);
});
});
@@ -127,6 +132,8 @@ async function startHTTPServer(config: Config): Promise<{
server.close();
});
server.listen(config.port);
return new Promise((resolve) => {
console.log(`Starting server on http://localhost:${config.port}`);
const readyForIncomingConnections = (
@@ -134,13 +141,12 @@ async function startHTTPServer(config: Config): Promise<{
companionEnv: FlipperServerCompanionEnv,
): Promise<void> => {
attachSocketServer(socket, serverImpl, companionEnv);
isReady = true;
return new Promise((resolve) => {
server.listen(config.port, undefined, () => {
tracker.track('server-started', {
port: config.port,
});
resolve();
tracker.track('server-started', {
port: config.port,
});
resolve();
});
};
resolve({app, server, socket, readyForIncomingConnections});