Ajoute un rafraîchissement forcé de l'application
This commit is contained in:
44
app.js
44
app.js
@@ -3,6 +3,7 @@ const SETUP_PAGE = "application.html";
|
||||
|
||||
const STORAGE_KEY = "chesscubing-arena-state-v2";
|
||||
const WINDOW_NAME_KEY = "chesscubing-arena-state-v2:";
|
||||
const ASSET_TOKEN_STORAGE_KEY = "chesscubing-arena-asset-token";
|
||||
const DEFAULT_BLOCK_DURATION_MS = 180000;
|
||||
const DEFAULT_MOVE_LIMIT_MS = 20000;
|
||||
const TIME_MODE_INITIAL_CLOCK_MS = 600000;
|
||||
@@ -114,6 +115,7 @@ function initSetupPage() {
|
||||
const summary = document.querySelector("#setupSummary");
|
||||
const loadDemoButton = document.querySelector("#loadDemoButton");
|
||||
const resumeCard = document.querySelector("#resumeCard");
|
||||
const refreshAppButton = document.querySelector("#refreshAppButton");
|
||||
const competitionModeInput = document.querySelector("#competitionMode");
|
||||
const competitionFields = Array.from(document.querySelectorAll("[data-competition-field]"));
|
||||
const moveSecondsField = document.querySelector("#moveSecondsField");
|
||||
@@ -244,6 +246,15 @@ function initSetupPage() {
|
||||
|
||||
form.addEventListener("input", renderSummary);
|
||||
loadDemoButton.addEventListener("click", () => loadDemo(form, renderSummary));
|
||||
refreshAppButton?.addEventListener("click", async () => {
|
||||
if (!(refreshAppButton instanceof HTMLButtonElement)) {
|
||||
return;
|
||||
}
|
||||
|
||||
refreshAppButton.disabled = true;
|
||||
refreshAppButton.textContent = "Mise a jour...";
|
||||
await forceRefreshToLatest(SETUP_PAGE);
|
||||
});
|
||||
|
||||
form.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
@@ -1939,6 +1950,39 @@ function clearMatch() {
|
||||
persistMatch();
|
||||
}
|
||||
|
||||
async function forceRefreshToLatest(path = SETUP_PAGE) {
|
||||
const refreshToken = `${Date.now()}`;
|
||||
|
||||
try {
|
||||
window.sessionStorage.setItem(ASSET_TOKEN_STORAGE_KEY, refreshToken);
|
||||
} catch {
|
||||
// Ignore storage failures in restricted browsers.
|
||||
}
|
||||
|
||||
if ("caches" in window) {
|
||||
try {
|
||||
const cacheKeys = await window.caches.keys();
|
||||
await Promise.all(cacheKeys.map((cacheKey) => window.caches.delete(cacheKey)));
|
||||
} catch {
|
||||
// Ignore cache API failures when unavailable.
|
||||
}
|
||||
}
|
||||
|
||||
if ("serviceWorker" in navigator) {
|
||||
try {
|
||||
const registrations = await navigator.serviceWorker.getRegistrations();
|
||||
await Promise.all(registrations.map((registration) => registration.update().catch(() => undefined)));
|
||||
await Promise.all(registrations.map((registration) => registration.unregister().catch(() => undefined)));
|
||||
} catch {
|
||||
// Ignore service worker failures when none are registered.
|
||||
}
|
||||
}
|
||||
|
||||
const targetUrl = new URL(path, window.location.href);
|
||||
targetUrl.searchParams.set("refresh", refreshToken);
|
||||
window.location.replace(targetUrl.toString());
|
||||
}
|
||||
|
||||
function toggleModal(element, open) {
|
||||
if (!element) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user