Summary: During testing, observed that Flipper always starts with an exception if `darkMode` is `true` or `false` (the old format) during startup, and this exception keeps on happening until the setting is changed. The root cause is that the setting is treated verbatim since D30666966 (9a4d94c971), trigger a very confusing Electron error. This diff addresses that.
Reviewed By: timur-valiev
Differential Revision: D30806453
fbshipit-source-id: fc7bbdda4e8bdf2dc4e3ca7ab1b05984c9406c68
72 lines
1.7 KiB
TypeScript
72 lines
1.7 KiB
TypeScript
/**
|
|
* 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 path from 'path';
|
|
import os from 'os';
|
|
import fs from 'fs';
|
|
|
|
export type Config = {
|
|
pluginPaths?: string[];
|
|
disabledPlugins?: string[];
|
|
lastWindowPosition?: {
|
|
x: number;
|
|
y: number;
|
|
width: number;
|
|
height: number;
|
|
};
|
|
updater?: boolean | undefined;
|
|
launcherMsg?: string | undefined;
|
|
updaterEnabled?: boolean;
|
|
launcherEnabled?: boolean;
|
|
darkMode: 'system' | 'light' | 'dark';
|
|
};
|
|
|
|
export default function setup(argv: any) {
|
|
// ensure .flipper folder and config exist
|
|
const flipperDir = path.join(os.homedir(), '.flipper');
|
|
if (!fs.existsSync(flipperDir)) {
|
|
fs.mkdirSync(flipperDir);
|
|
}
|
|
|
|
const configPath = path.join(flipperDir, 'config.json');
|
|
let config: Config = {
|
|
pluginPaths: [],
|
|
disabledPlugins: [],
|
|
darkMode: 'light',
|
|
};
|
|
|
|
try {
|
|
config = {
|
|
...config,
|
|
...JSON.parse(fs.readFileSync(configPath).toString()),
|
|
};
|
|
} catch (e) {
|
|
// file not readable or not parsable, overwrite it with the new config
|
|
console.warn(`Failed to read ${configPath}: ${e}`);
|
|
console.info('Writing new default config.');
|
|
fs.writeFileSync(configPath, JSON.stringify(config));
|
|
}
|
|
|
|
// Non-persistent CLI arguments.
|
|
config = {
|
|
...config,
|
|
darkMode:
|
|
typeof config.darkMode === 'boolean'
|
|
? config.darkMode // normalise darkmode from old format
|
|
? 'dark'
|
|
: 'light'
|
|
: config.darkMode,
|
|
updaterEnabled: argv.updater,
|
|
launcherEnabled: argv.launcher,
|
|
launcherMsg: argv.launcherMsg,
|
|
};
|
|
|
|
return {config, configPath};
|
|
}
|