Move first pieces of functionality of Electron
Summary: Started abstraction some Electron specific APIs away, like process id, select directory dialogs etc. Reviewed By: timur-valiev, aigoncharov Differential Revision: D31827016 fbshipit-source-id: e835ac9095e63d7ea79dd0eaf7f2918ac8d09994
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9b16d0c29a
commit
27549ac5eb
@@ -50,13 +50,15 @@ 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} from 'electron';
|
||||
import {ipcRenderer, remote, SaveDialogReturnValue} from 'electron';
|
||||
import {
|
||||
setLoggerInstance,
|
||||
setUserSessionManagerInstance,
|
||||
GK as flipperCommonGK,
|
||||
} from 'flipper-common';
|
||||
import {internGraphPOSTAPIRequest} from './fb-stubs/user';
|
||||
import {setRenderHostInstance} from './RenderHost';
|
||||
import {clipboard} from 'electron';
|
||||
|
||||
if (process.env.NODE_ENV === 'development' && os.platform() === 'darwin') {
|
||||
// By default Node.JS has its internal certificate storage and doesn't use
|
||||
@@ -187,6 +189,7 @@ function setProcessState(store: Store) {
|
||||
}
|
||||
|
||||
function init() {
|
||||
initializeFlipperForElectron();
|
||||
// TODO: centralise all those initialisations in a single configuration call
|
||||
flipperCommonGK.get = (name) => GK.get(name);
|
||||
const store = getStore();
|
||||
@@ -262,3 +265,37 @@ const CodeBlock = styled(Input.TextArea)({
|
||||
...theme.monospace,
|
||||
color: theme.textColorSecondary,
|
||||
});
|
||||
|
||||
function initializeFlipperForElectron() {
|
||||
setRenderHostInstance({
|
||||
processId: remote.process.pid,
|
||||
readTextFromClipboard() {
|
||||
return clipboard.readText();
|
||||
},
|
||||
selectDirectory(defaultPath = path.resolve('/')) {
|
||||
return remote.dialog
|
||||
.showOpenDialog({
|
||||
properties: ['openDirectory', 'showHiddenFiles'],
|
||||
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();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user