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:
committed by
Facebook GitHub Bot
parent
eed19b3a3d
commit
bca169df73
67
desktop/flipper-server-core/src/utils/settings.tsx
Normal file
67
desktop/flipper-server-core/src/utils/settings.tsx
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 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 os from 'os';
|
||||
import {resolve} from 'path';
|
||||
import xdg from 'xdg-basedir';
|
||||
import {Settings, Tristate} from 'flipper-common';
|
||||
import {readFile, writeFile, access} from 'fs-extra';
|
||||
|
||||
export async function loadSettings(): Promise<Settings> {
|
||||
if (!access(getSettingsFile())) {
|
||||
return getDefaultSettings();
|
||||
}
|
||||
const json = await readFile(getSettingsFile(), {encoding: 'utf8'});
|
||||
return JSON.parse(json);
|
||||
}
|
||||
|
||||
export async function saveSettings(settings: Settings): Promise<void> {
|
||||
await writeFile(getSettingsFile(), JSON.stringify(settings, null, 2), {
|
||||
encoding: 'utf8',
|
||||
});
|
||||
}
|
||||
|
||||
function getSettingsFile() {
|
||||
return resolve(
|
||||
...(xdg.config ? [xdg.config] : [os.homedir(), '.config']),
|
||||
'flipper',
|
||||
'settings.json',
|
||||
);
|
||||
}
|
||||
|
||||
export const DEFAULT_ANDROID_SDK_PATH = getDefaultAndroidSdkPath();
|
||||
|
||||
function getDefaultSettings(): Settings {
|
||||
return {
|
||||
androidHome: getDefaultAndroidSdkPath(),
|
||||
enableAndroid: true,
|
||||
enableIOS: os.platform() === 'darwin',
|
||||
enablePhysicalIOS: os.platform() === 'darwin',
|
||||
enablePrefetching: Tristate.Unset,
|
||||
idbPath: '/usr/local/bin/idb',
|
||||
reactNative: {
|
||||
shortcuts: {
|
||||
enabled: false,
|
||||
reload: 'Alt+Shift+R',
|
||||
openDevMenu: 'Alt+Shift+D',
|
||||
},
|
||||
},
|
||||
darkMode: 'light',
|
||||
showWelcomeAtStartup: true,
|
||||
suppressPluginErrors: false,
|
||||
};
|
||||
}
|
||||
|
||||
function getDefaultAndroidSdkPath() {
|
||||
return os.platform() === 'win32' ? getWindowsSdkPath() : '/opt/android_sdk';
|
||||
}
|
||||
|
||||
function getWindowsSdkPath() {
|
||||
return `${os.homedir()}\\AppData\\Local\\android\\sdk`;
|
||||
}
|
||||
Reference in New Issue
Block a user