From 82a253cf28bd391d5153fadfef215e90fe4fb4d1 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Tue, 22 Oct 2019 08:08:26 -0700 Subject: [PATCH] Add launcher prefetch setting Summary: Allows users to override the GK status of prefetching. It is implemented as a Tri-State. "Unset" means that the local Flipper config won't take precedent over the GK setting and will leave it unchanged. If a user interacts with the setting, it gets persisted into the config and will from then-on override the GK, meaning that the user has an opt-in mechanism and if we open the GK to more people, they effectively have an opt-out. Reviewed By: jknoxville Differential Revision: D18008259 fbshipit-source-id: bdfde9a8b9acf43aa60c84800a7979a29a4e9364 --- src/chrome/SettingsSheet.tsx | 12 ++++++++++++ src/fb-stubs/LauncherSettingsPanel.tsx | 17 +++++++++++++++++ src/fb-stubs/Prefetcher.tsx | 1 + src/reducers/settings.tsx | 13 +++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 src/fb-stubs/LauncherSettingsPanel.tsx diff --git a/src/chrome/SettingsSheet.tsx b/src/chrome/SettingsSheet.tsx index a6b048d7a..4903c3f9a 100644 --- a/src/chrome/SettingsSheet.tsx +++ b/src/chrome/SettingsSheet.tsx @@ -18,6 +18,7 @@ import ToggledSection from './settings/ToggledSection'; import {FilePathConfigField, ConfigText} from './settings/configFields'; import isEqual from 'lodash.isequal'; import restartFlipper from '../utils/restartFlipper'; +import LauncherSettingsPanel from '../fb-stubs/LauncherSettingsPanel'; const Container = styled(FlexColumn)({ padding: 20, @@ -102,6 +103,17 @@ class SettingsSheet extends Component { frozen /> + { + this.setState({ + updatedSettings: { + ...this.state.updatedSettings, + enablePrefetching: v, + }, + }); + }} + />
diff --git a/src/fb-stubs/LauncherSettingsPanel.tsx b/src/fb-stubs/LauncherSettingsPanel.tsx new file mode 100644 index 000000000..06fce1136 --- /dev/null +++ b/src/fb-stubs/LauncherSettingsPanel.tsx @@ -0,0 +1,17 @@ +/** + * 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 {Tristate} from 'src/reducers/settings'; + +export default function(_props: { + enabledInConfig: Tristate; + onChange: (v: Tristate) => void; +}) { + return null; +} diff --git a/src/fb-stubs/Prefetcher.tsx b/src/fb-stubs/Prefetcher.tsx index 8cb8a7580..34b6d0f44 100644 --- a/src/fb-stubs/Prefetcher.tsx +++ b/src/fb-stubs/Prefetcher.tsx @@ -8,3 +8,4 @@ */ export default async function setupPrefetcher() {} +export const shouldInstallPrefetcher = () => false; diff --git a/src/reducers/settings.tsx b/src/reducers/settings.tsx index 5b4678eed..2b1517e40 100644 --- a/src/reducers/settings.tsx +++ b/src/reducers/settings.tsx @@ -9,9 +9,21 @@ import {Actions} from './index'; +export enum Tristate { + True, + False, + Unset, +} + export type Settings = { androidHome: string; enableAndroid: 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; }; export type Action = @@ -24,6 +36,7 @@ export type Action = const initialState: Settings = { androidHome: '/opt/android_sdk', enableAndroid: true, + enablePrefetching: Tristate.Unset, }; export default function reducer(