Move configuration to module
Summary: Moves the JSON config access to one module instead of ad-hoc de-serialising the object all over the place. This also adds a type for it so we hopefully won't typo things that easily. Reviewed By: danielbuechele Differential Revision: D13956612 fbshipit-source-id: 48098deafedf18cc86c8802a3c40fba9394b8262
This commit is contained in:
committed by
Facebook Github Bot
parent
e78bd57514
commit
14ae2fea2c
40
src/utils/processConfig.js
Normal file
40
src/utils/processConfig.js
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 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 {remote} from 'electron';
|
||||
|
||||
export type ProcessConfig = {|
|
||||
disabledPlugins: Set<string>,
|
||||
pluginPaths: Array<string>,
|
||||
lastWindowPosition: ?{x: number, y: number, width: number, height: number},
|
||||
screenCapturePath: ?string,
|
||||
updaterEnabled: boolean,
|
||||
|};
|
||||
|
||||
let configObj = null;
|
||||
export default function config(): ProcessConfig {
|
||||
if (configObj === null) {
|
||||
const json = JSON.parse(
|
||||
// $FlowFixMe: process.env not in type defs
|
||||
remote?.process.env.CONFIG || process.env.CONFIG || '{}',
|
||||
);
|
||||
configObj = {
|
||||
disabledPlugins: new Set(json.disabledPlugins || []),
|
||||
pluginPaths: json.pluginPaths || [],
|
||||
lastWindowPosition: json.lastWindowPosition,
|
||||
updaterEnabled:
|
||||
typeof json.updaterEnabled === 'boolean' ? json.updaterEnabled : true,
|
||||
screenCapturePath: json.screenCapturePath,
|
||||
};
|
||||
}
|
||||
|
||||
return configObj;
|
||||
}
|
||||
|
||||
export function resetConfigForTesting() {
|
||||
configObj = null;
|
||||
}
|
||||
Reference in New Issue
Block a user