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