From b50aef8f15bfb52f569d6eacbdaec8f916c84a0c Mon Sep 17 00:00:00 2001 From: John Knox Date: Mon, 7 Oct 2019 08:49:05 -0700 Subject: [PATCH] Restart after changing settings Summary: Gets flipper to restart when settings are updated. In theory most settings should not need this, but the current only one does (android home) because the path is set at startup only, and this modifies the input to it. It would be a bit awkward to modify the path more than once, but doable. Reviewed By: passy Differential Revision: D17737582 fbshipit-source-id: d4669dcc7acc95469f15783fc6a5ba6794750234 --- src/chrome/SettingsSheet.tsx | 7 ++++++- src/init.tsx | 5 ++++- src/utils/persistor.tsx | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/utils/persistor.tsx diff --git a/src/chrome/SettingsSheet.tsx b/src/chrome/SettingsSheet.tsx index 23119c140..14c292d29 100644 --- a/src/chrome/SettingsSheet.tsx +++ b/src/chrome/SettingsSheet.tsx @@ -21,6 +21,7 @@ import {updateSettings, Action} from '../reducers/settings'; import {connect} from 'react-redux'; import {State as Store} from '../reducers'; import {Settings} from '../reducers/settings'; +import {flush} from '../utils/persistor'; import {promises as fs} from 'fs'; import {remote} from 'electron'; import path from 'path'; @@ -129,6 +130,10 @@ class SignInSheet extends Component { applyChanges = async () => { this.props.updateSettings(this.state.updatedSettings); this.props.onHide(); + flush().then(() => { + remote.app.relaunch(); + remote.app.exit(); + }); }; render() { @@ -154,7 +159,7 @@ class SignInSheet extends Component { Cancel diff --git a/src/init.tsx b/src/init.tsx index b55093cd3..2741ad804 100644 --- a/src/init.tsx +++ b/src/init.tsx @@ -26,6 +26,7 @@ import initCrashReporter from './utils/electronCrashReporter'; import fbConfig from './fb-stubs/config'; import {isFBEmployee} from './utils/fbEmployee'; import WarningEmployee from './chrome/WarningEmployee'; +import {setPersistor} from './utils/persistor'; import React from 'react'; import path from 'path'; @@ -100,7 +101,7 @@ function init() { } // rehydrate app state before exposing init -persistStore(store, undefined, () => { +const persistor = persistStore(store, undefined, () => { // Make sure process state is set before dispatchers run setProcessState(store); dispatcher(store, logger); @@ -108,3 +109,5 @@ persistStore(store, undefined, () => { window.Flipper.init = init; window.dispatchEvent(new Event('flipper-store-ready')); }); + +setPersistor(persistor); diff --git a/src/utils/persistor.tsx b/src/utils/persistor.tsx new file mode 100644 index 000000000..319ce3b27 --- /dev/null +++ b/src/utils/persistor.tsx @@ -0,0 +1,20 @@ +/** + * Copyright 2018-present Facebook. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * @format + */ + +import {Persistor} from 'redux-persist'; + +let _persistor: Persistor | null = null; + +export function setPersistor(persistor: Persistor) { + _persistor = persistor; +} + +export function flush(): Promise { + return _persistor + ? _persistor.flush() + : Promise.reject(new Error('Persistor not set.')); +}