v0.8.22
This commit is contained in:
+9
-2
@@ -262,14 +262,21 @@ function renderLanguageOptions() {
|
||||
|
||||
async function loadLanguages() {
|
||||
try {
|
||||
const response = await fetch(withBase('/lang/index.json'), {cache: 'no-cache'});
|
||||
// Language packs must never come from a stale Service Worker/browser cache.
|
||||
// A cache-busting nonce is intentional: translations can change without the JS asset hash changing.
|
||||
const languageNonce = Date.now().toString(36);
|
||||
const languageUrl = path => {
|
||||
const separator = String(path).includes('?') ? '&' : '?';
|
||||
return `${withBase(path)}${separator}v=${languageNonce}`;
|
||||
};
|
||||
const response = await fetch(languageUrl('/lang/index.json'), {cache: 'no-store'});
|
||||
if (!response.ok) throw new Error(`Language index HTTP ${response.status}`);
|
||||
const manifest = await response.json();
|
||||
const languages = Array.isArray(manifest.languages) ? manifest.languages : [];
|
||||
if (!languages.some(item => item.code === DEFAULT_LANGUAGE)) throw new Error('Default English language pack is missing');
|
||||
|
||||
const loaded = await Promise.all(languages.map(async item => {
|
||||
const packResponse = await fetch(withBase(item.path || `/lang/${encodeURIComponent(item.code)}.json`), {cache: 'no-cache'});
|
||||
const packResponse = await fetch(languageUrl(item.path || `/lang/${encodeURIComponent(item.code)}.json`), {cache: 'no-store'});
|
||||
if (!packResponse.ok) throw new Error(`Language ${item.code} HTTP ${packResponse.status}`);
|
||||
const pack = await packResponse.json();
|
||||
return {item, pack};
|
||||
|
||||
+1
-1
@@ -1386,7 +1386,7 @@ textarea[aria-invalid="true"] {
|
||||
.group-custom-temperature-row button { grid-column:auto; }
|
||||
}
|
||||
|
||||
/* v0.8.21: make group gates visually unambiguous. */
|
||||
/* v0.8.22: make group gates visually unambiguous. */
|
||||
.list-card.group-card.group-linked {
|
||||
border-color:color-mix(in srgb,var(--group-control-color) 42%,var(--line));
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
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('/favicon.svg'), path('/manifest.webmanifest'), path('/lang/index.json'), path('/lang/en.json'), path('/lang/pl.json')];
|
||||
const ASSETS = [path('__GREE_STYLES_ASSET__'), path('__GREE_APP_ASSET__'), path('__GREE_THEME_INIT_ASSET__'), path('/favicon.svg'), 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 => {
|
||||
const url = new URL(event.request.url);
|
||||
if (event.request.method !== 'GET' || url.pathname.startsWith(path('/api/')) || event.request.mode === 'navigate') return;
|
||||
// API and language packs stay network-owned. Language JSON is deliberately not
|
||||
// cache-first so a newly deployed translation can never be masked by an old pack.
|
||||
if (event.request.method !== 'GET' || url.pathname.startsWith(path('/api/')) || url.pathname.startsWith(path('/lang/')) || event.request.mode === 'navigate') return;
|
||||
event.respondWith(caches.match(event.request).then(cached => cached || fetch(event.request).then(response => {
|
||||
const copy = response.clone(); caches.open(CACHE).then(cache => cache.put(event.request, copy)); return response;
|
||||
})));
|
||||
|
||||
Reference in New Issue
Block a user