mirror of
https://github.com/Lissy93/dashy.git
synced 2024-12-29 20:11:53 +03:00
Replace static conf.yml import
This commit is contained in:
parent
727f6b1fc0
commit
3d4a8ecf6d
@ -1,7 +1,8 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
import yaml from 'js-yaml';
|
||||||
import { register } from 'register-service-worker';
|
import { register } from 'register-service-worker';
|
||||||
import { sessionStorageKeys } from '@/utils/defaults';
|
import { sessionStorageKeys } from '@/utils/defaults';
|
||||||
import { statusMsg, statusErrorMsg } from '@/utils/CoolConsole';
|
import { statusMsg, statusErrorMsg } from '@/utils/CoolConsole';
|
||||||
import conf from '../../public/conf.yml';
|
|
||||||
|
|
||||||
/* Sets a local storage item with the state from the SW lifecycle */
|
/* Sets a local storage item with the state from the SW lifecycle */
|
||||||
const setSwStatus = (swStateToSet) => {
|
const setSwStatus = (swStateToSet) => {
|
||||||
@ -31,7 +32,8 @@ const setSwStatus = (swStateToSet) => {
|
|||||||
* Disable if not running in production
|
* Disable if not running in production
|
||||||
* Or disable if user specified to disable
|
* Or disable if user specified to disable
|
||||||
*/
|
*/
|
||||||
const shouldEnableServiceWorker = () => {
|
const shouldEnableServiceWorker = async () => {
|
||||||
|
const conf = yaml.load((await axios.get('conf.yml')).data);
|
||||||
if (conf && conf.appConfig && conf.appConfig.enableServiceWorker) {
|
if (conf && conf.appConfig && conf.appConfig.enableServiceWorker) {
|
||||||
setSwStatus({ disabledByUser: false });
|
setSwStatus({ disabledByUser: false });
|
||||||
return true;
|
return true;
|
||||||
@ -51,8 +53,8 @@ const printSwStatus = (msg) => {
|
|||||||
const swUrl = `${process.env.BASE_URL || '/'}service-worker.js`;
|
const swUrl = `${process.env.BASE_URL || '/'}service-worker.js`;
|
||||||
|
|
||||||
/* If service worker enabled, then register it, and print message when status changes */
|
/* If service worker enabled, then register it, and print message when status changes */
|
||||||
const registerServiceWorker = () => {
|
const registerServiceWorker = async () => {
|
||||||
if (shouldEnableServiceWorker()) {
|
if (await shouldEnableServiceWorker()) {
|
||||||
register(swUrl, {
|
register(swUrl, {
|
||||||
ready() {
|
ready() {
|
||||||
setSwStatus({ ready: true });
|
setSwStatus({ ready: true });
|
||||||
|
Loading…
Reference in New Issue
Block a user