Persist settings in ${XDG_CONFIG_HOME}/flipper/settings
Summary: Moves the settings state from electron local storage into a json file in the users configured config location. Unless modified by the user, this will usually be `~/.config/flipper/settings.json` Settings will now persist across re-installs, and can now be easily inspected and backed up. Reviewed By: passy Differential Revision: D17712687 fbshipit-source-id: 1e778063e41d0a1a86145817b9797bf0458121da
This commit is contained in:
committed by
Facebook Github Bot
parent
7775e82851
commit
85c0ec0d13
@@ -27,11 +27,14 @@ import plugins, {
|
||||
Action as PluginsAction,
|
||||
} from './plugins';
|
||||
import settings, {
|
||||
State as SettingsState,
|
||||
Settings as SettingsState,
|
||||
Action as SettingsAction,
|
||||
} from './settings';
|
||||
import user, {State as UserState, Action as UserAction} from './user';
|
||||
|
||||
import JsonFileStorage from '../utils/jsonFileReduxPersistStorage';
|
||||
import os from 'os';
|
||||
import {resolve} from 'path';
|
||||
import xdg from 'xdg-basedir';
|
||||
import {persistReducer, PersistPartial} from 'redux-persist';
|
||||
|
||||
import {Store as ReduxStore, MiddlewareAPI as ReduxMiddlewareAPI} from 'redux';
|
||||
@@ -61,6 +64,14 @@ export type State = {
|
||||
export type Store = ReduxStore<State, Actions>;
|
||||
export type MiddlewareAPI = ReduxMiddlewareAPI<Dispatch<Actions>, State>;
|
||||
|
||||
const settingsStorage = new JsonFileStorage(
|
||||
resolve(
|
||||
...(xdg.config ? [xdg.config] : [os.homedir(), '.config']),
|
||||
'flipper',
|
||||
'settings.json',
|
||||
),
|
||||
);
|
||||
|
||||
export default combineReducers<State, Actions>({
|
||||
application: persistReducer<ApplicationState, Actions>(
|
||||
{
|
||||
@@ -101,7 +112,7 @@ export default combineReducers<State, Actions>({
|
||||
user,
|
||||
),
|
||||
settingsState: persistReducer(
|
||||
{key: 'settings', storage, whitelist: ['settings']},
|
||||
{key: 'settings', storage: settingsStorage},
|
||||
settings,
|
||||
),
|
||||
});
|
||||
|
||||
@@ -11,10 +11,6 @@ export type Settings = {
|
||||
androidHome: string;
|
||||
};
|
||||
|
||||
export type State = {
|
||||
settings: Settings;
|
||||
};
|
||||
|
||||
export type Action =
|
||||
| {type: 'INIT'}
|
||||
| {
|
||||
@@ -22,21 +18,16 @@ export type Action =
|
||||
payload: Settings;
|
||||
};
|
||||
|
||||
const initialState: State = {
|
||||
settings: {
|
||||
androidHome: '/opt/android_sdk',
|
||||
},
|
||||
const initialState: Settings = {
|
||||
androidHome: '/opt/android_sdk',
|
||||
};
|
||||
|
||||
export default function reducer(
|
||||
state: State = initialState,
|
||||
state: Settings = initialState,
|
||||
action: Actions,
|
||||
): State {
|
||||
): Settings {
|
||||
if (action.type === 'UPDATE_SETTINGS') {
|
||||
return {
|
||||
...state,
|
||||
settings: action.payload,
|
||||
};
|
||||
return action.payload;
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user