Files
flipper/desktop/static/setup.ts
Michel Weststrate 014e571f74 Start application in the right theme
Summary:
Changelog: Improved dark mode support!

This diff makes sure that the dark mode preference is written to the Flipper config, and applied during startup, so that the ugly light/dark flash when starting Flipper in dark mode disappears

Reviewed By: passy

Differential Revision: D29436059

fbshipit-source-id: 0f762149848298512026fbd216d9a9e0bf4276db
2021-06-29 08:39:34 -07:00

65 lines
1.5 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?: boolean;
};
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: [],
};
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,
updaterEnabled: argv.updater,
launcherEnabled: argv.launcher,
launcherMsg: argv.launcherMsg,
};
return {config, configPath};
}