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
@@ -49,16 +49,14 @@ import styled from '@emotion/styled';
|
||||
import {CopyOutlined} from '@ant-design/icons';
|
||||
import {getVersionString} from './utils/versionString';
|
||||
import {PersistGate} from 'redux-persist/integration/react';
|
||||
// eslint-disable-next-line flipper/no-electron-remote-imports
|
||||
import {ipcRenderer, remote, SaveDialogReturnValue} from 'electron';
|
||||
import {
|
||||
setLoggerInstance,
|
||||
setUserSessionManagerInstance,
|
||||
GK as flipperCommonGK,
|
||||
} from 'flipper-common';
|
||||
import {internGraphPOSTAPIRequest} from './fb-stubs/user';
|
||||
import {getRenderHostInstance, setRenderHostInstance} from './RenderHost';
|
||||
import {clipboard} from 'electron';
|
||||
import {getRenderHostInstance} from './RenderHost';
|
||||
import {initializeElectron} from './electron/initializeElectron';
|
||||
|
||||
if (process.env.NODE_ENV === 'development' && os.platform() === 'darwin') {
|
||||
// By default Node.JS has its internal certificate storage and doesn't use
|
||||
@@ -189,7 +187,7 @@ function setProcessState(store: Store) {
|
||||
}
|
||||
|
||||
function init() {
|
||||
initializeFlipperForElectron();
|
||||
initializeElectron();
|
||||
// TODO: centralise all those initialisations in a single configuration call
|
||||
flipperCommonGK.get = (name) => GK.get(name);
|
||||
const store = getStore();
|
||||
@@ -259,59 +257,3 @@ const CodeBlock = styled(Input.TextArea)({
|
||||
...theme.monospace,
|
||||
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