v0.14.23-fixed_js
This commit is contained in:
@@ -19,6 +19,7 @@ const withBase = path => `${PUBLIC_BASE}${path.startsWith('/') ? path : `/${path
|
||||
const PUBLIC_DEFAULT_LANGUAGE = String(document.documentElement.lang || '').trim();
|
||||
const PUBLIC_RANGE_KEYS = ['history.6h', 'history.24h', 'history.7d', 'history.30d', 'history.90d', 'history.1y'];
|
||||
let publicLanguageManifest = null;
|
||||
const publicLanguagePacks = new Map();
|
||||
let publicChartLanguage = PUBLIC_DEFAULT_LANGUAGE;
|
||||
let publicChartTranslations = {};
|
||||
let publicChartLocale = PUBLIC_DEFAULT_LANGUAGE;
|
||||
@@ -49,9 +50,13 @@ async function setPublicChartLanguage(language) {
|
||||
|| languages.find(entry => entry.code === fallbackCode)
|
||||
|| languages[0];
|
||||
if (!item) throw new Error('language pack unavailable');
|
||||
const response = await fetch(withBase(item.path || `/lang/${encodeURIComponent(item.code)}.json`), { headers: { Accept: 'application/json' } });
|
||||
if (!response.ok) throw new Error(`language ${item.code} HTTP ${response.status}`);
|
||||
const pack = await response.json();
|
||||
let pack = publicLanguagePacks.get(item.code);
|
||||
if (!pack) {
|
||||
const response = await fetch(withBase(item.path || `/lang/${encodeURIComponent(item.code)}.json`), { headers: { Accept: 'application/json' } });
|
||||
if (!response.ok) throw new Error(`language ${item.code} HTTP ${response.status}`);
|
||||
pack = await response.json();
|
||||
publicLanguagePacks.set(item.code, pack);
|
||||
}
|
||||
publicChartLanguage = item.code;
|
||||
publicChartTranslations = pack.translations || {};
|
||||
publicChartLocale = pack.meta?.locale || item.locale || item.code;
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
const CACHE = 'gree-controller-__GREE_ASSET_CACHE__';
|
||||
const SCOPE = new URL(self.registration.scope).pathname.replace(/\/$/, '');
|
||||
const path = value => `${SCOPE}${value.startsWith('/') ? value : `/${value}`}` || '/';
|
||||
const ASSETS = [path('__GREE_STYLES_ASSET__'), path('__GREE_APP_ASSET__'), path('__GREE_THEME_INIT_ASSET__'), path('__GREE_LANG_INIT_ASSET__'), path('/favicon.svg'), path('/manifest.webmanifest')];
|
||||
const ASSETS = [path('__GREE_STYLES_ASSET__'), path('__GREE_APP_ASSET__'), path('__GREE_THEME_INIT_ASSET__'), path('__GREE_LANG_INIT_ASSET__'), path('/manifest.webmanifest')];
|
||||
self.addEventListener('install', event => event.waitUntil(caches.open(CACHE).then(cache => cache.addAll(ASSETS)).then(() => self.skipWaiting())));
|
||||
self.addEventListener('activate', event => event.waitUntil(caches.keys().then(keys => Promise.all(keys.filter(key => key !== CACHE).map(key => caches.delete(key)))).then(() => self.clients.claim())));
|
||||
self.addEventListener('fetch', event => {
|
||||
|
||||
Reference in New Issue
Block a user