From c63f145ffbd6805cd29e2db5c8b38ea88adc9598 Mon Sep 17 00:00:00 2001 From: John Knox Date: Tue, 22 Oct 2019 04:20:38 -0700 Subject: [PATCH] Add restartFlipper utility Summary: Centralizes the restart logic. And adds ability for it to work in dev mode as well. Reviewed By: passy Differential Revision: D18008197 fbshipit-source-id: b76ac7935d5859dfdbb8cf593462f8ac02348181 --- src/chrome/PluginInstaller.tsx | 4 ++-- src/chrome/SettingsSheet.tsx | 5 ++--- src/utils/restartFlipper.tsx | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 src/utils/restartFlipper.tsx diff --git a/src/chrome/PluginInstaller.tsx b/src/chrome/PluginInstaller.tsx index e20bdf901..f32f71b3c 100644 --- a/src/chrome/PluginInstaller.tsx +++ b/src/chrome/PluginInstaller.tsx @@ -35,6 +35,7 @@ import {promisify} from 'util'; import {homedir} from 'os'; import {PluginManager as PM} from 'live-plugin-manager'; import {reportPlatformFailures, reportUsage} from '../utils/metrics'; +import restartFlipper from '../utils/restartFlipper'; const PLUGIN_DIR = path.join(homedir(), '.flipper', 'thirdparty'); const ALGOLIA_APPLICATION_ID = 'OFCNCOG2CU'; @@ -121,8 +122,7 @@ const PluginInstaller = function props(props: Props) { props.getInstalledPlugins, ); const restartApp = useCallback(() => { - remote.app.relaunch(); - remote.app.exit(); + restartFlipper(); }, []); return ( diff --git a/src/chrome/SettingsSheet.tsx b/src/chrome/SettingsSheet.tsx index 84f70b97f..a6b048d7a 100644 --- a/src/chrome/SettingsSheet.tsx +++ b/src/chrome/SettingsSheet.tsx @@ -16,8 +16,8 @@ import {Settings} from '../reducers/settings'; import {flush} from '../utils/persistor'; import ToggledSection from './settings/ToggledSection'; import {FilePathConfigField, ConfigText} from './settings/configFields'; -import {remote} from 'electron'; import isEqual from 'lodash.isequal'; +import restartFlipper from '../utils/restartFlipper'; const Container = styled(FlexColumn)({ padding: 20, @@ -58,8 +58,7 @@ class SettingsSheet extends Component { this.props.updateSettings(this.state.updatedSettings); this.props.onHide(); flush().then(() => { - remote.app.relaunch(); - remote.app.exit(); + restartFlipper(); }); }; diff --git a/src/utils/restartFlipper.tsx b/src/utils/restartFlipper.tsx new file mode 100644 index 000000000..3d533a9c9 --- /dev/null +++ b/src/utils/restartFlipper.tsx @@ -0,0 +1,24 @@ +/** + * 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 {remote} from 'electron'; +import isProduction from './isProduction'; + +export default function restart() { + if (isProduction()) { + remote.app.relaunch(); + remote.app.exit(); + } else { + // Relaunching the process doesn't work in dev mode + // because it just launches an empty electron shell. + // Instead, approximate it by doing a refresh. + // Should be roughly equivalent but there may be some differences. + remote.getCurrentWindow().reload(); + } +}