Refactor Open
Summary: Extract our launch UI logic into flipper-server-core. Reviewed By: passy Differential Revision: D51115241 fbshipit-source-id: 185e381eab6b480d86a5e1201f45c070104d0cea
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9164e04e29
commit
137e75ad46
@@ -13,13 +13,13 @@ export * from './tracker';
|
||||
export {loadLauncherSettings} from './utils/launcherSettings';
|
||||
export {loadProcessConfig} from './utils/processConfig';
|
||||
export {getEnvironmentInfo} from './utils/environmentInfo';
|
||||
export {findInstallation} from './utils/findInstallation';
|
||||
export {getGatekeepers} from './gk';
|
||||
export {setupPrefetcher} from './fb-stubs/Prefetcher';
|
||||
export * from './server/attachSocketServer';
|
||||
export * from './server/startFlipperServer';
|
||||
export * from './server/startServer';
|
||||
export * from './server/utilities';
|
||||
export * from './utils/openUI';
|
||||
export {isFBBuild} from './fb-stubs/constants';
|
||||
export {initializeLogger} from './fb-stubs/Logger';
|
||||
|
||||
|
||||
59
desktop/flipper-server-core/src/utils/openUI.tsx
Normal file
59
desktop/flipper-server-core/src/utils/openUI.tsx
Normal file
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import open from 'open';
|
||||
import {getAuthToken} from '../app-connectivity/certificate-exchange/certificate-utils';
|
||||
import {findInstallation} from './findInstallation';
|
||||
import {tracker} from '../tracker';
|
||||
|
||||
export enum UIPreference {
|
||||
Browser,
|
||||
PWA,
|
||||
}
|
||||
|
||||
export async function openUI(preference: UIPreference, port: number) {
|
||||
console.info('[flipper-server] Launch UI');
|
||||
|
||||
const token = await getAuthToken();
|
||||
console.info(
|
||||
`[flipper-server] Get authentication token: ${token?.length != 0}`,
|
||||
);
|
||||
|
||||
const openInBrowser = async () => {
|
||||
console.info('[flipper-server] Open in browser');
|
||||
const url = new URL(`http://localhost:${port}`);
|
||||
|
||||
console.info(`[flipper-server] Go to: ${url.toString()}`);
|
||||
|
||||
open(url.toString(), {app: {name: open.apps.chrome}});
|
||||
|
||||
tracker.track('server-open-ui', {
|
||||
browser: true,
|
||||
hasToken: token?.length != 0,
|
||||
});
|
||||
};
|
||||
|
||||
if (preference === UIPreference.Browser) {
|
||||
await openInBrowser();
|
||||
} else {
|
||||
const path = await findInstallation();
|
||||
if (path) {
|
||||
console.info('[flipper-server] Open in PWA. Location:', path);
|
||||
tracker.track('server-open-ui', {
|
||||
browser: false,
|
||||
hasToken: token?.length != 0,
|
||||
});
|
||||
open(path);
|
||||
} else {
|
||||
await openInBrowser();
|
||||
}
|
||||
}
|
||||
|
||||
console.info('[flipper-server] Launch UI completed');
|
||||
}
|
||||
Reference in New Issue
Block a user