UNPKG

1.19 kBJavaScriptView Raw
1import Configstore from 'configstore';
2import deepEqual from 'deep-equal';
3import { serverHost } from './argv';
4import findNetworkInterface from './utils/networkInterface';
5import { name } from '../package.json';
6// import availableDisplays from './utils/availableDisplays';
7
8const defaultConfig = () => {
9 const networkInterface = findNetworkInterface();
10 return {
11 display: 'chromium',
12 url: `${serverHost}/no-config?ip=${networkInterface && networkInterface.ip}`,
13 // url: `http://localhost${webPort === 80 ? '' : `:${webPort}`}/no-config`,
14 };
15};
16
17const configStore = new Configstore(name, defaultConfig());
18let config = configStore.all;
19
20if (!config || !config.display || (config.url && config.url.startsWith('undefined'))) {
21 config = defaultConfig();
22}
23
24function save() {
25 configStore.all = config;
26}
27
28// if (availableDisplays.indexOf(config.display) === -1) {
29// config.display = 'chromium';
30// save();
31// }
32
33export function updateConfig(newConfig: Object) {
34 if (deepEqual(config, newConfig)) {
35 return false;
36 }
37
38 config = newConfig;
39 save();
40 return true;
41}
42
43export function getTime() {
44 return config.time;
45}
46
47export function get() {
48 return config;
49}