Use getRenderHost from flipper-frontned-core in flipper-ui-core

Summary: See D37139129

Reviewed By: lblasa

Differential Revision: D37236435

fbshipit-source-id: 927e9f741bfedb65165f5d24f0acfb775925cdc7
This commit is contained in:
Andrey Goncharov
2022-06-20 12:18:40 -07:00
committed by Facebook GitHub Bot
parent fab8849c73
commit 17ab7a86ef
47 changed files with 49 additions and 197 deletions

View File

@@ -1,148 +0,0 @@
/**
* 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 type {NotificationEvents} from './dispatcher/notifications';
import type {PluginNotification} from './reducers/notifications';
import {FlipperLib} from 'flipper-plugin';
import {FlipperServer, FlipperServerConfig} from 'flipper-common';
import {Icon} from './utils/icons';
interface NotificationAction {
// Docs: https://electronjs.org/docs/api/structures/notification-action
/**
* The label for the given action.
*/
text?: string;
/**
* The type of action, can be `button`.
*/
type: 'button';
}
// Subset of electron.d.ts
interface NotificationConstructorOptions {
/**
* A title for the notification, which will be shown at the top of the notification
* window when it is shown.
*/
title: string;
/**
* The body text of the notification, which will be displayed below the title or
* subtitle.
*/
body: string;
/**
* Actions to add to the notification. Please read the available actions and
* limitations in the `NotificationAction` documentation.
*
* @platform darwin
*/
actions?: NotificationAction[];
/**
* A custom title for the close button of an alert. An empty string will cause the
* default localized text to be used.
*
* @platform darwin
*/
closeButtonText?: string;
}
// Events that are emitted from the main.ts ovr the IPC process bridge in Electron
type MainProcessEvents = {
'flipper-protocol-handler': [query: string];
'open-flipper-file': [url: string];
notificationEvent: [
eventName: NotificationEvents,
pluginNotification: PluginNotification,
arg: null | string | number,
];
trackUsage: any[];
getLaunchTime: [launchStartTime: number];
};
// Events that are emitted by the child process, to the main process
type ChildProcessEvents = {
setTheme: [theme: 'dark' | 'light' | 'system'];
sendNotification: [
{
payload: NotificationConstructorOptions;
pluginNotification: PluginNotification;
closeAfter?: number;
},
];
getLaunchTime: [];
componentDidMount: [];
};
/**
* Utilities provided by the render host, e.g. Electron, the Browser, etc
*/
export interface RenderHost {
readTextFromClipboard(): string | undefined;
writeTextToClipboard(text: string): void;
/**
* @deprecated
* WARNING!
* It is a low-level API call that might be removed in the future.
* It is not really deprecated yet, but we'll try to make it so.
* TODO: Remove in favor of "exportFile"
*/
showSaveDialog?(options: {
defaultPath?: string;
message?: string;
title?: string;
}): Promise<string | undefined>;
/**
* @deprecated
* WARNING!
* It is a low-level API call that might be removed in the future.
* It is not really deprecated yet, but we'll try to make it so.
* TODO: Remove in favor of "importFile"
*/
showOpenDialog?(options: {
defaultPath?: string;
filter?: {
extensions: string[];
name: string;
};
}): Promise<string | undefined>;
showSelectDirectoryDialog?(defaultPath?: string): Promise<string | undefined>;
importFile: FlipperLib['importFile'];
exportFile: FlipperLib['exportFile'];
hasFocus(): boolean;
onIpcEvent<Event extends keyof MainProcessEvents>(
event: Event,
callback: (...arg: MainProcessEvents[Event]) => void,
): void;
sendIpcEvent<Event extends keyof ChildProcessEvents>(
event: Event,
...args: ChildProcessEvents[Event]
): void;
shouldUseDarkColors(): boolean;
restartFlipper(update?: boolean): void;
openLink(url: string): void;
loadDefaultPlugins(): Record<string, any>;
GK(gatekeeper: string): boolean;
flipperServer: FlipperServer;
serverConfig: FlipperServerConfig;
requirePlugin(path: string): Promise<any>;
getStaticResourceUrl(relativePath: string): string;
// given the requested icon and proposed public url of the icon, rewrite it to a local icon if needed
getLocalIconUrl?(icon: Icon, publicUrl: string): string;
unloadModule?(path: string): void;
getPercentCPUUsage?(): number;
}
export function getRenderHostInstance(): RenderHost {
if (!FlipperRenderHostInstance) {
throw new Error('global FlipperRenderHostInstance was never set');
}
return FlipperRenderHostInstance;
}

View File

@@ -8,7 +8,11 @@
*/
import {createStore} from 'redux';
import {BaseDevice, TestDevice} from 'flipper-frontend-core';
import {
BaseDevice,
TestDevice,
getRenderHostInstance,
} from 'flipper-frontend-core';
import {createRootReducer} from '../../reducers';
import {Store} from '../../reducers/index';
import Client from '../../Client';
@@ -26,7 +30,6 @@ import {initializeFlipperLibImplementation} from '../../utils/flipperLibImplemen
import pluginManager from '../../dispatcher/pluginManager';
import {PluginDetails} from 'flipper-common';
import {ClientQuery, DeviceOS} from 'flipper-common';
import {getRenderHostInstance} from '../../RenderHost';
export interface AppOptions {
plugins?: PluginDefinition[];

View File

@@ -12,7 +12,7 @@ import React, {Component} from 'react';
import {reportUsage} from 'flipper-common';
import {Modal} from 'antd';
import {Dialog, theme} from 'flipper-plugin';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
const changelogKey = 'FlipperChangelogStatus';

View File

@@ -17,7 +17,7 @@ import {isEqual} from 'lodash';
import {Platform, reportUsage, Settings} from 'flipper-common';
import {Modal, Button} from 'antd';
import {Layout, withTrackingScope, _NuxManagerContext} from 'flipper-plugin';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
const WIZARD_FINISHED_LOCAL_STORAGE_KEY = 'platformSelectWizardFinished';

View File

@@ -32,7 +32,7 @@ import {useStore} from '../utils/useStore';
import {isLoggedIn} from '../fb-stubs/user';
import {useValue} from 'flipper-plugin';
import {reportPlatformFailures} from 'flipper-common';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
type NextAction = 'select-rating' | 'leave-comment' | 'finished';

View File

@@ -12,7 +12,7 @@ import React, {useState, useCallback} from 'react';
import {capture, getCaptureLocation, getFileName} from '../utils/screenshot';
import {CameraOutlined, VideoCameraOutlined} from '@ant-design/icons';
import {useStore} from '../utils/useStore';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
import {path} from 'flipper-plugin';
async function openFile(path: string) {

View File

@@ -40,7 +40,7 @@ import {
_NuxManagerContext,
NUX,
} from 'flipper-plugin';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
import {loadTheme} from '../utils/loadTheme';
type OwnProps = {

View File

@@ -8,9 +8,8 @@
*/
import React, {Component} from 'react';
import {BaseDevice} from 'flipper-frontend-core';
import {BaseDevice, getRenderHostInstance} from 'flipper-frontend-core';
import {Button, Glyph, colors} from '../ui';
import {getRenderHostInstance} from '../RenderHost';
import {path} from 'flipper-plugin';
type OwnProps = {

View File

@@ -25,7 +25,7 @@ import {Dispatch, Action} from 'redux';
import PluginPackageInstaller from './PluginPackageInstaller';
import {Toolbar} from 'flipper-plugin';
import {Alert, Button, Input, Tooltip, Typography} from 'antd';
import {getRenderHostInstance} from '../../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
import {WarningOutlined} from '@ant-design/icons';
const {Text, Link} = Typography;

View File

@@ -18,7 +18,7 @@ import {
import styled from '@emotion/styled';
import React, {useState} from 'react';
import {Toolbar, FileSelector} from 'flipper-plugin';
import {getRenderHostInstance} from '../../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
const CenteredGlyph = styled(Glyph)({
margin: 'auto',

View File

@@ -14,7 +14,7 @@ import configureStore from 'redux-mock-store';
import {Provider} from 'react-redux';
import type {PluginDetails, UpdatablePluginDetails} from 'flipper-common';
import {Store} from '../../../reducers';
import {getRenderHostInstance} from '../../../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
let getUpdatablePluginsMock: jest.Mock<any, any>;

View File

@@ -18,7 +18,7 @@ import {
} from '../../ui';
import React, {useState, useEffect} from 'react';
import {getFlipperLib, theme} from 'flipper-plugin';
import {getRenderHostInstance} from '../../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
export const ConfigFieldContainer = styled(FlexRow)({
paddingLeft: 10,

View File

@@ -21,7 +21,7 @@ import {getLogger} from 'flipper-common';
import configureStore from 'redux-mock-store';
import TestPlugin from './TestPlugin';
import {_SandyPluginDefinition} from 'flipper-plugin';
import {getRenderHostInstance} from '../../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
import path from 'path';
let loadDynamicPluginsMock: jest.Mock;

View File

@@ -16,7 +16,7 @@ import {
import {tryCatchReportPlatformFailures} from 'flipper-common';
import {handleDeeplink} from '../deeplink';
import {Dialog} from 'flipper-plugin';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
export default (store: Store, logger: Logger) => {
const renderHost = getRenderHostInstance();

View File

@@ -38,7 +38,7 @@ import {
DeeplinkInteractionState,
OpenPluginParams,
} from '../deeplinkTracking';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
import {waitFor} from '../utils/waitFor';
export function parseOpenPluginParams(query: string): OpenPluginParams {

View File

@@ -19,7 +19,7 @@ import {textContent} from 'flipper-plugin';
import {getPluginTitle} from '../utils/pluginUtils';
import {sideEffect} from '../utils/sideEffect';
import {openNotification} from '../sandy-chrome/notification/Notification';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
export type NotificationEvents =
| 'show'

View File

@@ -20,7 +20,7 @@ import {loadPlugin} from '../reducers/pluginManager';
import {showErrorNotification} from '../utils/notifications';
import {pluginInstalled} from '../reducers/plugins';
import {getAllClients} from '../reducers/connections';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
export default (store: Store) => {
sideEffect(

View File

@@ -43,7 +43,7 @@ import {
defaultEnabledBackgroundPlugins,
} from '../utils/pluginUtils';
import {getPluginKey} from '../utils/pluginKey';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
async function refreshInstalledPlugins(store: Store) {
const flipperServer = getRenderHostInstance().flipperServer;

View File

@@ -25,7 +25,7 @@ import {selectCompatibleMarketplaceVersions} from './plugins';
import isPluginVersionMoreRecent from '../utils/isPluginVersionMoreRecent';
import {isConnectivityOrAuthError} from 'flipper-common';
import {isLoggedIn} from '../fb-stubs/user';
import {getRenderHostInstance} from '..';
import {getRenderHostInstance} from 'flipper-frontend-core';
// TODO: provide this value from settings
export const pollingIntervalMs = getRenderHostInstance().serverConfig.env

View File

@@ -48,7 +48,7 @@ import {isDevicePluginDefinition} from '../utils/pluginUtils';
import isPluginCompatible from '../utils/isPluginCompatible';
import isPluginVersionMoreRecent from '../utils/isPluginVersionMoreRecent';
import {createSandyPluginWrapper} from '../utils/createSandyPluginWrapper';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
import pMap from 'p-map';
import * as deprecatedExports from '../deprecated-exports';

View File

@@ -27,7 +27,7 @@ import {deconstructClientId} from 'flipper-common';
import {sideEffect} from '../utils/sideEffect';
import {getSelectionInfo} from '../utils/info';
import type {SelectionInfo} from '../utils/info';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
const TIME_SPENT_EVENT = 'time-spent';

View File

@@ -8,7 +8,7 @@
*/
import {VersionCheckResult} from '../chrome/UpdateIndicator';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
const updateServer = 'https://www.facebook.com/fbflipper/public/latest.json';

View File

@@ -8,7 +8,6 @@
*/
import {StoreEnhancerStoreCreator} from 'redux';
import {RenderHost} from './RenderHost';
declare global {
interface StoreEnhancerStateSanitizer {

View File

@@ -10,7 +10,7 @@
// TODO: should not be exported anymore, but still needed for 'import from 'flipper'' stuff
export * from './deprecated-exports';
export {RenderHost, getRenderHostInstance} from './RenderHost';
export {RenderHost, getRenderHostInstance} from 'flipper-frontend-core';
export {startFlipperDesktop} from './startFlipperDesktop';

View File

@@ -8,7 +8,7 @@
*/
import {v1 as uuidv1} from 'uuid';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
import {Actions} from './';
export type LauncherMsg = {

View File

@@ -8,7 +8,7 @@
*/
import {LauncherSettings} from 'flipper-common';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
import {Actions} from './index';
export type Action = {

View File

@@ -8,7 +8,7 @@
*/
import {Actions} from './index';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
import {Settings} from 'flipper-common';
export type Action =

View File

@@ -10,7 +10,7 @@
import {produce} from 'immer';
import {Actions} from './';
import {SelectionInfo} from '../utils/info';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
export type TrackingEvent =
| {

View File

@@ -65,7 +65,7 @@ import {
} from '../utils/exportData';
import {openDeeplinkDialog} from '../deeplink';
import {css} from '@emotion/css';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
import openSupportRequestForm from '../fb-stubs/openSupportRequestForm';
import {StyleGuide} from './StyleGuide';

View File

@@ -40,7 +40,7 @@ import fbConfig from '../fb-stubs/config';
import {isFBEmployee} from '../utils/fbEmployee';
import {notification} from 'antd';
import isProduction from '../utils/isProduction';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
export type ToplevelNavItem =
| 'appinspect'

View File

@@ -31,7 +31,7 @@ import {State} from '../../reducers';
import {brandColors, brandIcons, colors} from '../../ui/components/colors';
import {TroubleshootingGuide} from './fb-stubs/TroubleshootingGuide';
import {getSelectableDevices} from '../../selectors/connections';
import {getRenderHostInstance} from '../../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
const {Text} = Typography;

View File

@@ -25,7 +25,7 @@ import {
} from 'flipper-plugin';
import {Provider} from 'react-redux';
import {IOSDeviceParams} from 'flipper-common';
import {getRenderHostInstance} from '../../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
import SettingsSheet from '../../chrome/SettingsSheet';
import {Link} from '../../ui';

View File

@@ -15,7 +15,7 @@ import {LaunchEmulatorDialog} from '../LaunchEmulator';
import {createRootReducer} from '../../../reducers';
import {sleep} from 'flipper-plugin';
import {getRenderHostInstance} from '../../../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
test('Can render and launch android apps - no emulators', async () => {
const store = createStore(createRootReducer());

View File

@@ -40,7 +40,7 @@ import {CopyOutlined} from '@ant-design/icons';
import {getVersionString} from './utils/versionString';
import {PersistGate} from 'redux-persist/integration/react';
import {setLoggerInstance, FlipperServer} from 'flipper-common';
import {getRenderHostInstance} from './RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
import {startGlobalErrorHandling} from './utils/globalErrorHandling';
import {loadTheme} from './utils/loadTheme';
import {connectFlipperServerToStore} from './dispatcher/flipperServer';

View File

@@ -20,7 +20,7 @@ import {debounce} from 'lodash';
import ToggleButton from '../ToggleSwitch';
import React from 'react';
import {Layout, theme, Toolbar} from 'flipper-plugin';
import {getRenderHostInstance} from '../../../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
const SearchBar = styled(Toolbar)({
height: 42,

View File

@@ -32,7 +32,7 @@ import {debounce} from 'lodash';
import {DEFAULT_ROW_HEIGHT} from './types';
import {notNull} from '../../../utils/typeUtils';
import {getFlipperLib, textContent} from 'flipper-plugin';
import {getRenderHostInstance} from '../../../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
const EMPTY_OBJECT = {};
Object.freeze(EMPTY_OBJECT);

View File

@@ -30,7 +30,7 @@ import {ClientQuery} from 'flipper-common';
import ShareSheetExportUrl from '../chrome/ShareSheetExportUrl';
import ShareSheetExportFile from '../chrome/ShareSheetExportFile';
import ExportDataPluginSheet from '../chrome/ExportDataPluginSheet';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
import {uploadFlipperMedia} from '../fb-stubs/user';
export const IMPORT_FLIPPER_TRACE_EVENT = 'import-flipper-trace';

View File

@@ -9,7 +9,7 @@
import {assertNever, DownloadFileUpdate} from 'flipper-common';
import {FlipperLib, DownloadFileResponse} from 'flipper-plugin';
import {RenderHost} from '../../RenderHost';
import {RenderHost} from 'flipper-frontend-core';
export const downloadFileFactory =
(renderHost: RenderHost): FlipperLib['remoteServerContext']['downloadFile'] =>

View File

@@ -26,7 +26,7 @@ import constants from '../../fb-stubs/constants';
import {addNotification} from '../../reducers/notifications';
import {deconstructPluginKey} from 'flipper-common';
import {DetailSidebarImpl} from '../../sandy-chrome/DetailSidebarImpl';
import {RenderHost} from '../../RenderHost';
import {RenderHost} from 'flipper-frontend-core';
import {setMenuEntries} from '../../reducers/connections';
import {downloadFileFactory} from './downloadFile';
import {Base64} from 'js-base64';

View File

@@ -7,7 +7,7 @@
* @format
*/
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
import {IconSize} from '../ui/components/Glyph';
const AVAILABLE_SIZES: IconSize[] = [8, 10, 12, 16, 18, 20, 24, 32];

View File

@@ -13,7 +13,7 @@
import type {State, Store} from '../reducers/index';
import {sideEffect} from './sideEffect';
import {Logger, deconstructClientId} from 'flipper-common';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
type PlatformInfo = {
arch: string;

View File

@@ -9,7 +9,7 @@
import {PluginDetails} from 'flipper-common';
import semver from 'semver';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
import {getAppVersion} from './info';
export function isPluginCompatible(plugin: PluginDetails) {

View File

@@ -7,7 +7,7 @@
* @format
*/
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
export default function isProduction() {
return getRenderHostInstance().serverConfig.environmentInfo.isProduction;

View File

@@ -8,7 +8,7 @@
*/
import {Settings} from 'flipper-common';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
export function loadTheme(theme: Settings['darkMode']) {
let shouldUseDarkMode = false;

View File

@@ -12,7 +12,7 @@ import {
reportPlatformFailures,
FlipperDoctor,
} from 'flipper-common';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
let healthcheckIsRunning: boolean;
let runningHealthcheck: Promise<void>;

View File

@@ -7,9 +7,8 @@
* @format
*/
import {BaseDevice} from 'flipper-frontend-core';
import {BaseDevice, getRenderHostInstance} from 'flipper-frontend-core';
import {reportPlatformFailures} from 'flipper-common';
import {getRenderHostInstance} from '../RenderHost';
import {getFlipperLib, path} from 'flipper-plugin';
import {assertNotNull} from './assertNotNull';

View File

@@ -8,7 +8,7 @@
*/
import {useStore} from './useStore';
import {getRenderHostInstance} from '../RenderHost';
import {getRenderHostInstance} from 'flipper-frontend-core';
/**
* This hook returns whether dark mode is currently being used.