1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.updateConfig = updateConfig;
|
7 | exports.getTime = getTime;
|
8 | exports.get = get;
|
9 |
|
10 | var _configstore = require('configstore');
|
11 |
|
12 | var _configstore2 = _interopRequireDefault(_configstore);
|
13 |
|
14 | var _deepEqual = require('deep-equal');
|
15 |
|
16 | var _deepEqual2 = _interopRequireDefault(_deepEqual);
|
17 |
|
18 | var _argv = require('./argv');
|
19 |
|
20 | var _networkInterface = require('./utils/networkInterface');
|
21 |
|
22 | var _networkInterface2 = _interopRequireDefault(_networkInterface);
|
23 |
|
24 | var _package = require('../package.json');
|
25 |
|
26 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
27 |
|
28 |
|
29 |
|
30 | const defaultConfig = () => {
|
31 | const networkInterface = (0, _networkInterface2.default)();
|
32 | return {
|
33 | display: 'chromium',
|
34 | url: `${_argv.serverHost}/no-config?ip=${networkInterface && networkInterface.ip}`
|
35 |
|
36 | };
|
37 | };
|
38 |
|
39 | const configStore = new _configstore2.default(_package.name, defaultConfig());
|
40 | let config = configStore.all;
|
41 |
|
42 | if (!config || !config.display || config.url && config.url.startsWith('undefined')) {
|
43 | config = defaultConfig();
|
44 | }
|
45 |
|
46 | function save() {
|
47 | configStore.all = config;
|
48 | }
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | function updateConfig(newConfig) {
|
56 | if ((0, _deepEqual2.default)(config, newConfig)) {
|
57 | return false;
|
58 | }
|
59 |
|
60 | config = newConfig;
|
61 | save();
|
62 | return true;
|
63 | }
|
64 |
|
65 | function getTime() {
|
66 | return config.time;
|
67 | }
|
68 |
|
69 | function get() {
|
70 | return config;
|
71 | }
|
72 |
|
\ | No newline at end of file |