UNPKG

pooliot-client

Version:
51 lines (39 loc) 1.28 kB
import Configstore from 'configstore'; import deepEqual from 'deep-equal'; import { serverHost } from './params'; import findNetworkInterface from './utils/networkInterface'; import { name } from '../../package.json'; import { availableWebBrowsers } from './utils/availableDisplays'; const defaultConfig = () => { const networkInterface = findNetworkInterface(); if (!availableWebBrowsers.length) { return { display: 'disabled' }; } return { display: availableWebBrowsers[0], url: `${serverHost}/no-config?ip=${networkInterface && networkInterface.ip}`, // url: `http://localhost${webPort === 80 ? '' : `:${webPort}`}/no-config`, }; }; const configStore = new Configstore(name, defaultConfig()); let config = configStore.all; if (!config || !config.display || (config.url && config.url.startsWith('undefined'))) { config = defaultConfig(); } const save = () => { configStore.all = config; }; // if (availableDisplays.indexOf(config.display) === -1) { // config.display = 'chromium'; // save(); // } export const updateConfig = (newConfig: Object) => { if (deepEqual(config, newConfig)) { return false; } config = newConfig; save(); return true; }; export const getTime = () => config.time; export const get = () => config;