Move Electron stuff to separate folder, decapitate restart
Summary: Per title Reviewed By: passy Differential Revision: D31991715 fbshipit-source-id: 9ca58cdd26c1f540fbe09dcfc7b7f5e7a319ea7d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
7a19b1c8d4
commit
25590e14b9
@@ -59,6 +59,7 @@ export interface RenderHost {
|
|||||||
...args: ChildProcessEvents[Event]
|
...args: ChildProcessEvents[Event]
|
||||||
): void;
|
): void;
|
||||||
shouldUseDarkColors(): boolean;
|
shouldUseDarkColors(): boolean;
|
||||||
|
restartFlipper(update?: boolean): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
let renderHostInstance: RenderHost | undefined;
|
let renderHostInstance: RenderHost | undefined;
|
||||||
@@ -89,5 +90,6 @@ if (process.env.NODE_ENV === 'test') {
|
|||||||
shouldUseDarkColors() {
|
shouldUseDarkColors() {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
restartFlipper() {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ import {Settings} from '../reducers/settings';
|
|||||||
import {flush} from '../utils/persistor';
|
import {flush} from '../utils/persistor';
|
||||||
import ToggledSection from './settings/ToggledSection';
|
import ToggledSection from './settings/ToggledSection';
|
||||||
import {isEqual} from 'lodash';
|
import {isEqual} from 'lodash';
|
||||||
import restartFlipper from '../utils/restartFlipper';
|
|
||||||
import {reportUsage} from 'flipper-common';
|
import {reportUsage} from 'flipper-common';
|
||||||
import {Modal, Button} from 'antd';
|
import {Modal, Button} from 'antd';
|
||||||
import {Layout, withTrackingScope, _NuxManagerContext} from 'flipper-plugin';
|
import {Layout, withTrackingScope, _NuxManagerContext} from 'flipper-plugin';
|
||||||
|
import {getRenderHostInstance} from '../RenderHost';
|
||||||
|
|
||||||
const WIZARD_FINISHED_LOCAL_STORAGE_KEY = 'platformSelectWizardFinished';
|
const WIZARD_FINISHED_LOCAL_STORAGE_KEY = 'platformSelectWizardFinished';
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ class PlatformSelectWizard extends Component<Props, State> {
|
|||||||
return flush().then(() => {
|
return flush().then(() => {
|
||||||
if (!settingsPristine) {
|
if (!settingsPristine) {
|
||||||
reportUsage('platformwizard:action:changed');
|
reportUsage('platformwizard:action:changed');
|
||||||
restartFlipper(true);
|
getRenderHostInstance().restartFlipper();
|
||||||
} else {
|
} else {
|
||||||
reportUsage('platformwizard:action:noop');
|
reportUsage('platformwizard:action:noop');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ import ToggledSection from './settings/ToggledSection';
|
|||||||
import {FilePathConfigField, ConfigText} from './settings/configFields';
|
import {FilePathConfigField, ConfigText} from './settings/configFields';
|
||||||
import KeyboardShortcutInput from './settings/KeyboardShortcutInput';
|
import KeyboardShortcutInput from './settings/KeyboardShortcutInput';
|
||||||
import {isEqual, isMatch, isEmpty} from 'lodash';
|
import {isEqual, isMatch, isEmpty} from 'lodash';
|
||||||
import restartFlipper from '../utils/restartFlipper';
|
|
||||||
import LauncherSettingsPanel from '../fb-stubs/LauncherSettingsPanel';
|
import LauncherSettingsPanel from '../fb-stubs/LauncherSettingsPanel';
|
||||||
import {reportUsage} from 'flipper-common';
|
import {reportUsage} from 'flipper-common';
|
||||||
import {Modal, message, Button} from 'antd';
|
import {Modal, message, Button} from 'antd';
|
||||||
import {Layout, withTrackingScope, _NuxManagerContext} from 'flipper-plugin';
|
import {Layout, withTrackingScope, _NuxManagerContext} from 'flipper-plugin';
|
||||||
|
import {getRenderHostInstance} from '../RenderHost';
|
||||||
|
|
||||||
type OwnProps = {
|
type OwnProps = {
|
||||||
onHide: () => void;
|
onHide: () => void;
|
||||||
@@ -70,7 +70,7 @@ class SettingsSheet extends Component<Props, State> {
|
|||||||
this.props.updateLauncherSettings(this.state.updatedLauncherSettings);
|
this.props.updateLauncherSettings(this.state.updatedLauncherSettings);
|
||||||
this.props.onHide();
|
this.props.onHide();
|
||||||
return flush().then(() => {
|
return flush().then(() => {
|
||||||
restartFlipper(true);
|
getRenderHostInstance().restartFlipper(true);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import {loadPluginsFromMarketplace} from './fb-stubs/pluginMarketplace';
|
|||||||
import {loadPlugin, switchPlugin} from '../reducers/pluginManager';
|
import {loadPlugin, switchPlugin} from '../reducers/pluginManager';
|
||||||
import {startPluginDownload} from '../reducers/pluginDownloads';
|
import {startPluginDownload} from '../reducers/pluginDownloads';
|
||||||
import isProduction from '../utils/isProduction';
|
import isProduction from '../utils/isProduction';
|
||||||
import restart from '../utils/restartFlipper';
|
|
||||||
import BaseDevice from '../devices/BaseDevice';
|
import BaseDevice from '../devices/BaseDevice';
|
||||||
import Client from '../Client';
|
import Client from '../Client';
|
||||||
import {RocketOutlined} from '@ant-design/icons';
|
import {RocketOutlined} from '@ant-design/icons';
|
||||||
@@ -39,6 +38,7 @@ import {
|
|||||||
DeeplinkInteractionState,
|
DeeplinkInteractionState,
|
||||||
OpenPluginParams,
|
OpenPluginParams,
|
||||||
} from '../deeplinkTracking';
|
} from '../deeplinkTracking';
|
||||||
|
import {getRenderHostInstance} from '../RenderHost';
|
||||||
|
|
||||||
export function parseOpenPluginParams(query: string): OpenPluginParams {
|
export function parseOpenPluginParams(query: string): OpenPluginParams {
|
||||||
// 'flipper://open-plugin?plugin-id=graphql&client=facebook&devices=android,ios&chrome=1&payload='
|
// 'flipper://open-plugin?plugin-id=graphql&client=facebook&devices=android,ios&chrome=1&payload='
|
||||||
@@ -362,7 +362,7 @@ async function verifyPluginStatus(
|
|||||||
),
|
),
|
||||||
okText: 'Restart',
|
okText: 'Restart',
|
||||||
onConfirm: async () => {
|
onConfirm: async () => {
|
||||||
restart();
|
getRenderHostInstance().restartFlipper();
|
||||||
// intentionally forever pending, we're restarting...
|
// intentionally forever pending, we're restarting...
|
||||||
return new Promise(() => {});
|
return new Promise(() => {});
|
||||||
},
|
},
|
||||||
|
|||||||
80
desktop/app/src/electron/initializeElectron.tsx
Normal file
80
desktop/app/src/electron/initializeElectron.tsx
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) Facebook, Inc. and its 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 path from 'path';
|
||||||
|
import {
|
||||||
|
_NuxManagerContext,
|
||||||
|
_createNuxManager,
|
||||||
|
_setGlobalInteractionReporter,
|
||||||
|
_LoggerContext,
|
||||||
|
} from 'flipper-plugin';
|
||||||
|
// eslint-disable-next-line flipper/no-electron-remote-imports
|
||||||
|
import {ipcRenderer, remote, SaveDialogReturnValue} from 'electron';
|
||||||
|
import {setRenderHostInstance} from '../RenderHost';
|
||||||
|
import {clipboard} from 'electron';
|
||||||
|
import restart from './restartFlipper';
|
||||||
|
|
||||||
|
export function initializeElectron() {
|
||||||
|
setRenderHostInstance({
|
||||||
|
processId: remote.process.pid,
|
||||||
|
readTextFromClipboard() {
|
||||||
|
return clipboard.readText();
|
||||||
|
},
|
||||||
|
async showSaveDialog(options) {
|
||||||
|
return (await remote.dialog.showSaveDialog(options))?.filePath;
|
||||||
|
},
|
||||||
|
async showOpenDialog({filter, defaultPath}) {
|
||||||
|
const result = await remote.dialog.showOpenDialog({
|
||||||
|
defaultPath,
|
||||||
|
properties: ['openFile'],
|
||||||
|
filters: filter ? [filter] : undefined,
|
||||||
|
});
|
||||||
|
return result.filePaths?.[0];
|
||||||
|
},
|
||||||
|
showSelectDirectoryDialog(defaultPath = path.resolve('/')) {
|
||||||
|
return remote.dialog
|
||||||
|
.showOpenDialog({
|
||||||
|
properties: ['openDirectory'],
|
||||||
|
defaultPath,
|
||||||
|
})
|
||||||
|
.then((result: SaveDialogReturnValue & {filePaths: string[]}) => {
|
||||||
|
if (result.filePath) {
|
||||||
|
return result.filePath.toString();
|
||||||
|
}
|
||||||
|
// Electron typings seem of here, just in case,
|
||||||
|
// (can be tested with settings dialog)
|
||||||
|
// handle both situations
|
||||||
|
if (result.filePaths) {
|
||||||
|
return result.filePaths[0];
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
registerShortcut(shortcut, callback) {
|
||||||
|
remote.globalShortcut.register(shortcut, callback);
|
||||||
|
},
|
||||||
|
hasFocus() {
|
||||||
|
return remote.getCurrentWindow().isFocused();
|
||||||
|
},
|
||||||
|
onIpcEvent(event, callback) {
|
||||||
|
ipcRenderer.on(event, (_ev, ...args: any[]) => {
|
||||||
|
callback(...(args as any));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
sendIpcEvent(event, ...args: any[]) {
|
||||||
|
ipcRenderer.send(event, ...args);
|
||||||
|
},
|
||||||
|
shouldUseDarkColors() {
|
||||||
|
return remote.nativeTheme.shouldUseDarkColors;
|
||||||
|
},
|
||||||
|
restartFlipper() {
|
||||||
|
restart();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
// eslint-disable-next-line flipper/no-electron-remote-imports
|
// eslint-disable-next-line flipper/no-electron-remote-imports
|
||||||
import {remote} from 'electron';
|
import {remote} from 'electron';
|
||||||
import isProduction from './isProduction';
|
import isProduction from '../utils/isProduction';
|
||||||
|
|
||||||
export default function restart(update: boolean = false) {
|
export default function restart(update: boolean = false) {
|
||||||
if (isProduction()) {
|
if (isProduction()) {
|
||||||
@@ -49,16 +49,14 @@ import styled from '@emotion/styled';
|
|||||||
import {CopyOutlined} from '@ant-design/icons';
|
import {CopyOutlined} from '@ant-design/icons';
|
||||||
import {getVersionString} from './utils/versionString';
|
import {getVersionString} from './utils/versionString';
|
||||||
import {PersistGate} from 'redux-persist/integration/react';
|
import {PersistGate} from 'redux-persist/integration/react';
|
||||||
// eslint-disable-next-line flipper/no-electron-remote-imports
|
|
||||||
import {ipcRenderer, remote, SaveDialogReturnValue} from 'electron';
|
|
||||||
import {
|
import {
|
||||||
setLoggerInstance,
|
setLoggerInstance,
|
||||||
setUserSessionManagerInstance,
|
setUserSessionManagerInstance,
|
||||||
GK as flipperCommonGK,
|
GK as flipperCommonGK,
|
||||||
} from 'flipper-common';
|
} from 'flipper-common';
|
||||||
import {internGraphPOSTAPIRequest} from './fb-stubs/user';
|
import {internGraphPOSTAPIRequest} from './fb-stubs/user';
|
||||||
import {getRenderHostInstance, setRenderHostInstance} from './RenderHost';
|
import {getRenderHostInstance} from './RenderHost';
|
||||||
import {clipboard} from 'electron';
|
import {initializeElectron} from './electron/initializeElectron';
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'development' && os.platform() === 'darwin') {
|
if (process.env.NODE_ENV === 'development' && os.platform() === 'darwin') {
|
||||||
// By default Node.JS has its internal certificate storage and doesn't use
|
// By default Node.JS has its internal certificate storage and doesn't use
|
||||||
@@ -189,7 +187,7 @@ function setProcessState(store: Store) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
initializeFlipperForElectron();
|
initializeElectron();
|
||||||
// TODO: centralise all those initialisations in a single configuration call
|
// TODO: centralise all those initialisations in a single configuration call
|
||||||
flipperCommonGK.get = (name) => GK.get(name);
|
flipperCommonGK.get = (name) => GK.get(name);
|
||||||
const store = getStore();
|
const store = getStore();
|
||||||
@@ -259,59 +257,3 @@ const CodeBlock = styled(Input.TextArea)({
|
|||||||
...theme.monospace,
|
...theme.monospace,
|
||||||
color: theme.textColorSecondary,
|
color: theme.textColorSecondary,
|
||||||
});
|
});
|
||||||
|
|
||||||
function initializeFlipperForElectron() {
|
|
||||||
setRenderHostInstance({
|
|
||||||
processId: remote.process.pid,
|
|
||||||
readTextFromClipboard() {
|
|
||||||
return clipboard.readText();
|
|
||||||
},
|
|
||||||
async showSaveDialog(options) {
|
|
||||||
return (await remote.dialog.showSaveDialog(options))?.filePath;
|
|
||||||
},
|
|
||||||
async showOpenDialog({filter, defaultPath}) {
|
|
||||||
const result = await remote.dialog.showOpenDialog({
|
|
||||||
defaultPath,
|
|
||||||
properties: ['openFile'],
|
|
||||||
filters: filter ? [filter] : undefined,
|
|
||||||
});
|
|
||||||
return result.filePaths?.[0];
|
|
||||||
},
|
|
||||||
showSelectDirectoryDialog(defaultPath = path.resolve('/')) {
|
|
||||||
return remote.dialog
|
|
||||||
.showOpenDialog({
|
|
||||||
properties: ['openDirectory'],
|
|
||||||
defaultPath,
|
|
||||||
})
|
|
||||||
.then((result: SaveDialogReturnValue & {filePaths: string[]}) => {
|
|
||||||
if (result.filePath) {
|
|
||||||
return result.filePath.toString();
|
|
||||||
}
|
|
||||||
// Electron typings seem of here, just in case,
|
|
||||||
// (can be tested with settings dialog)
|
|
||||||
// handle both situations
|
|
||||||
if (result.filePaths) {
|
|
||||||
return result.filePaths[0];
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
registerShortcut(shortcut, callback) {
|
|
||||||
remote.globalShortcut.register(shortcut, callback);
|
|
||||||
},
|
|
||||||
hasFocus() {
|
|
||||||
return remote.getCurrentWindow().isFocused();
|
|
||||||
},
|
|
||||||
onIpcEvent(event, callback) {
|
|
||||||
ipcRenderer.on(event, (_ev, ...args: any[]) => {
|
|
||||||
callback(...(args as any));
|
|
||||||
});
|
|
||||||
},
|
|
||||||
sendIpcEvent(event, ...args: any[]) {
|
|
||||||
ipcRenderer.send(event, ...args);
|
|
||||||
},
|
|
||||||
shouldUseDarkColors() {
|
|
||||||
return remote.nativeTheme.shouldUseDarkColors;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user