Move settings, launcherSettings, GKs to app / flipper-server-core

Summary:
This diff moves a lot of stuff from the client to the server. This diff is fairly large, as a lot of concept closely relate, although some things have split off to the earlier diffs in the stack, or are still to follow (like making intern requests).

This diff primarily moves reading and storing settings and GKs from client to server (both flipper and launcher settings). This means that settings are no longer persisted by Redux (which only exists on client). Most other changes are fallout from that. For now settings are just one big object, although we might need to separate settings that are only make sense in an Electron context. For example launcher settings.

Reviewed By: passy, aigoncharov

Differential Revision: D32498649

fbshipit-source-id: d842faf7a7f03774b621c7656e53a9127afc6192
This commit is contained in:
Michel Weststrate
2021-12-08 04:25:28 -08:00
committed by Facebook GitHub Bot
parent eed19b3a3d
commit bca169df73
71 changed files with 844 additions and 830 deletions

View File

@@ -7,30 +7,17 @@
* @format
*/
import {default as reducer, updateSettings, Tristate} from '../settings';
test('init', () => {
const res = reducer(undefined, {type: 'INIT'});
expect(res.enableAndroid).toBeTruthy();
});
import {default as reducer, updateSettings} from '../settings';
import {Tristate} from 'flipper-common';
test('updateSettings', () => {
const initialSettings = reducer(undefined, {type: 'INIT'});
const updatedSettings = Object.assign(initialSettings, {
enableAndroid: false,
enablePrefetching: Tristate.True,
jsApps: {
webAppLauncher: {
height: 900,
},
},
});
const res = reducer(initialSettings, updateSettings(updatedSettings));
expect(res.enableAndroid).toBeFalsy();
expect(res.enablePrefetching).toEqual(Tristate.True);
expect(res.jsApps.webAppLauncher.height).toEqual(900);
expect(res.jsApps.webAppLauncher.width).toEqual(
initialSettings.jsApps.webAppLauncher.width,
);
});

View File

@@ -36,12 +36,8 @@ import supportForm, {
State as SupportFormState,
Action as SupportFormAction,
} from './supportForm';
import settings, {
Settings as SettingsState,
Action as SettingsAction,
} from './settings';
import settings, {Action as SettingsAction} from './settings';
import launcherSettings, {
LauncherSettings as LauncherSettingsState,
Action as LauncherSettingsAction,
} from './launcherSettings';
import pluginManager, {
@@ -61,18 +57,13 @@ import usageTracking, {
State as TrackingState,
} from './usageTracking';
import user, {State as UserState, Action as UserAction} from './user';
import JsonFileStorage from '../utils/jsonFileReduxPersistStorage';
import LauncherSettingsStorage from '../utils/launcherSettingsStorage';
import {launcherConfigDir} from '../utils/launcher';
import os from 'os';
import {resolve} from 'path';
import xdg from 'xdg-basedir';
import {createMigrate, createTransform, persistReducer} from 'redux-persist';
import {PersistPartial} from 'redux-persist/es/persistReducer';
import {Store as ReduxStore, MiddlewareAPI as ReduxMiddlewareAPI} from 'redux';
import storage from 'redux-persist/lib/storage';
import {TransformConfig} from 'redux-persist/es/createTransform';
import {LauncherSettings, Settings} from 'flipper-common';
export type Actions =
| ApplicationAction
@@ -97,8 +88,8 @@ export type State = {
notifications: NotificationsState & PersistPartial;
plugins: PluginsState & PersistPartial;
user: UserState & PersistPartial;
settingsState: SettingsState & PersistPartial;
launcherSettingsState: LauncherSettingsState & PersistPartial;
settingsState: Settings;
launcherSettingsState: LauncherSettings;
supportForm: SupportFormState;
pluginManager: PluginManagerState;
healthchecks: HealthcheckState & PersistPartial;
@@ -109,14 +100,6 @@ 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',
),
);
const setTransformer = (config: TransformConfig) =>
createTransform(
(set: Set<string>) => Array.from(set),
@@ -124,10 +107,6 @@ const setTransformer = (config: TransformConfig) =>
config,
);
const launcherSettingsStorage = new LauncherSettingsStorage(
resolve(launcherConfigDir(), 'flipper-launcher.toml'),
);
export function createRootReducer() {
return combineReducers<State, Actions>({
application,
@@ -181,20 +160,8 @@ export function createRootReducer() {
},
user,
),
settingsState: persistReducer(
{key: 'settings', storage: settingsStorage},
settings,
),
launcherSettingsState: persistReducer(
{
key: 'launcherSettings',
storage: launcherSettingsStorage,
serialize: false,
// @ts-ignore: property is erroneously missing in redux-persist type definitions
deserialize: false,
},
launcherSettings,
),
settingsState: settings,
launcherSettingsState: launcherSettings,
healthchecks: persistReducer<HealthcheckState, Actions>(
{
key: 'healthchecks',

View File

@@ -7,26 +7,18 @@
* @format
*/
import {LauncherSettings} from 'flipper-common';
import {getRenderHostInstance} from '../RenderHost';
import {Actions} from './index';
import ReleaseChannel from '../ReleaseChannel';
export type LauncherSettings = {
releaseChannel: ReleaseChannel;
ignoreLocalPin: boolean;
};
export type Action = {
type: 'UPDATE_LAUNCHER_SETTINGS';
payload: LauncherSettings;
};
export const defaultLauncherSettings: LauncherSettings = {
releaseChannel: ReleaseChannel.DEFAULT,
ignoreLocalPin: false,
};
export default function reducer(
state: LauncherSettings = defaultLauncherSettings,
state: LauncherSettings = getRenderHostInstance().serverConfig
.launcherSettings,
action: Actions,
): LauncherSettings {
if (action.type === 'UPDATE_LAUNCHER_SETTINGS') {

View File

@@ -8,45 +8,8 @@
*/
import {Actions} from './index';
import os from 'os';
import {getRenderHostInstance} from '../RenderHost';
export enum Tristate {
True,
False,
Unset,
}
export type Settings = {
androidHome: string;
enableAndroid: boolean;
enableIOS: boolean;
enablePhysicalIOS: boolean;
/**
* If unset, this will assume the value of the GK setting.
* Note that this setting has no effect in the open source version
* of Flipper.
*/
enablePrefetching: Tristate;
idbPath: string;
jsApps: {
webAppLauncher: {
url: string;
height: number;
width: number;
};
};
reactNative: {
shortcuts: {
enabled: boolean;
reload: string;
openDevMenu: string;
};
};
darkMode: 'dark' | 'light' | 'system';
showWelcomeAtStartup: boolean;
suppressPluginErrors: boolean;
};
import {Settings} from 'flipper-common';
export type Action =
| {type: 'INIT'}
@@ -55,36 +18,8 @@ export type Action =
payload: Settings;
};
export const DEFAULT_ANDROID_SDK_PATH = getDefaultAndroidSdkPath();
const initialState: Settings = {
androidHome: getDefaultAndroidSdkPath(),
enableAndroid: true,
enableIOS: os.platform() === 'darwin',
enablePhysicalIOS: os.platform() === 'darwin',
enablePrefetching: Tristate.Unset,
idbPath: '/usr/local/bin/idb',
jsApps: {
webAppLauncher: {
url: 'http://localhost:8888',
height: 600,
width: 800,
},
},
reactNative: {
shortcuts: {
enabled: false,
reload: 'Alt+Shift+R',
openDevMenu: 'Alt+Shift+D',
},
},
darkMode: 'light',
showWelcomeAtStartup: true,
suppressPluginErrors: false,
};
export default function reducer(
state: Settings = initialState,
state: Settings = getRenderHostInstance().serverConfig.settings,
action: Actions,
): Settings {
if (action.type === 'UPDATE_SETTINGS') {
@@ -99,13 +34,3 @@ export function updateSettings(settings: Settings): Action {
payload: settings,
};
}
function getDefaultAndroidSdkPath() {
return os.platform() === 'win32' ? getWindowsSdkPath() : '/opt/android_sdk';
}
function getWindowsSdkPath() {
return `${
getRenderHostInstance().paths.homePath
}\\AppData\\Local\\android\\sdk`;
}