Summary: See D37139129 Reviewed By: lblasa Differential Revision: D37236435 fbshipit-source-id: 927e9f741bfedb65165f5d24f0acfb775925cdc7
157 lines
3.8 KiB
TypeScript
157 lines
3.8 KiB
TypeScript
/**
|
|
* 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
|
|
*/
|
|
|
|
// Use of sync methods is cached.
|
|
/* eslint-disable node/no-sync */
|
|
|
|
import type {State, Store} from '../reducers/index';
|
|
import {sideEffect} from './sideEffect';
|
|
import {Logger, deconstructClientId} from 'flipper-common';
|
|
import {getRenderHostInstance} from 'flipper-frontend-core';
|
|
|
|
type PlatformInfo = {
|
|
arch: string;
|
|
platform: string;
|
|
isHeadlessBuild: boolean;
|
|
unixname: string;
|
|
versions: {
|
|
[key: string]: string | undefined;
|
|
};
|
|
};
|
|
|
|
export type SelectionInfo = {
|
|
plugin: string | null;
|
|
pluginName: string | null;
|
|
pluginVersion: string | null;
|
|
pluginEnabled: boolean | null;
|
|
app: string | null;
|
|
os: string | null;
|
|
device: string | null;
|
|
deviceName: string | null;
|
|
deviceSerial: string | null;
|
|
deviceType: string | null;
|
|
archived: boolean | null;
|
|
};
|
|
|
|
export type Info = PlatformInfo & {
|
|
selection: SelectionInfo;
|
|
};
|
|
|
|
let platformInfo: PlatformInfo | undefined;
|
|
let selection: SelectionInfo = {
|
|
plugin: null,
|
|
pluginName: null,
|
|
pluginVersion: null,
|
|
pluginEnabled: null,
|
|
app: null,
|
|
os: null,
|
|
device: null,
|
|
deviceName: null,
|
|
deviceSerial: null,
|
|
deviceType: null,
|
|
archived: null,
|
|
};
|
|
|
|
export default (store: Store, _logger: Logger) => {
|
|
return sideEffect(
|
|
store,
|
|
{
|
|
name: 'recomputeSelectionInfo',
|
|
throttleMs: 0,
|
|
noTimeBudgetWarns: true,
|
|
runSynchronously: true,
|
|
fireImmediately: true,
|
|
},
|
|
getSelectionInfo,
|
|
(newSelection, _store) => {
|
|
selection = newSelection;
|
|
},
|
|
);
|
|
};
|
|
|
|
/**
|
|
* This method builds up some metadata about the users environment that we send
|
|
* on bug reports, analytic events, errors etc.
|
|
*/
|
|
export function getInfo(): Info {
|
|
if (!platformInfo) {
|
|
const envInfo = getRenderHostInstance().serverConfig.environmentInfo;
|
|
|
|
platformInfo = {
|
|
arch: envInfo.os.arch,
|
|
platform: envInfo.os.platform,
|
|
isHeadlessBuild: envInfo.isHeadlessBuild,
|
|
unixname: envInfo.os.unixname,
|
|
versions: envInfo.versions,
|
|
};
|
|
}
|
|
return {
|
|
...platformInfo,
|
|
selection,
|
|
};
|
|
}
|
|
|
|
export function getAppVersion(): string {
|
|
return getRenderHostInstance().serverConfig.environmentInfo.appVersion;
|
|
}
|
|
|
|
export function stringifyInfo(info: Info): string {
|
|
const lines = [
|
|
`Platform: ${info.platform} ${info.arch} (${
|
|
info.isHeadlessBuild ? 'headless' : 'desktop'
|
|
})`,
|
|
`Unixname: ${info.unixname}`,
|
|
`Versions:`,
|
|
];
|
|
|
|
for (const key in info.versions) {
|
|
lines.push(` ${key}: ${String(info.versions[key])}`);
|
|
}
|
|
|
|
return lines.join('\n');
|
|
}
|
|
|
|
export function getSelectionInfo({
|
|
plugins: {clientPlugins, devicePlugins, loadedPlugins},
|
|
connections: {
|
|
selectedAppId,
|
|
selectedPlugin,
|
|
enabledDevicePlugins,
|
|
enabledPlugins,
|
|
selectedDevice,
|
|
},
|
|
}: State): SelectionInfo {
|
|
const clientIdParts = selectedAppId
|
|
? deconstructClientId(selectedAppId)
|
|
: null;
|
|
const loadedPlugin = selectedPlugin
|
|
? loadedPlugins.get(selectedPlugin)
|
|
: null;
|
|
const pluginEnabled =
|
|
!!selectedPlugin &&
|
|
((enabledDevicePlugins.has(selectedPlugin) &&
|
|
devicePlugins.has(selectedPlugin)) ||
|
|
(clientIdParts &&
|
|
enabledPlugins[clientIdParts.app]?.includes(selectedPlugin) &&
|
|
clientPlugins.has(selectedPlugin)));
|
|
return {
|
|
plugin: selectedPlugin || null,
|
|
pluginName: loadedPlugin?.name || null,
|
|
pluginVersion: loadedPlugin?.version || null,
|
|
pluginEnabled,
|
|
app: clientIdParts?.app || null,
|
|
device: selectedDevice?.title || null,
|
|
deviceName: clientIdParts?.device || null,
|
|
deviceSerial: selectedDevice?.serial || null,
|
|
deviceType: selectedDevice?.deviceType || null,
|
|
os: selectedDevice?.os || null,
|
|
archived: selectedDevice?.isArchived || false,
|
|
};
|
|
}
|