SHA256
feat(update): проверка версии UI через Ping без периодических опросов
This commit is contained in:
+18
-47
@@ -103,14 +103,11 @@ const screenEl = document.getElementById('app-screen');
|
||||
const toolbarEl = document.getElementById('toolbar-slot');
|
||||
const appShellEl = document.querySelector('.app-shell');
|
||||
|
||||
const VERSION_CHECK_INTERVAL_MS = 10 * 60 * 1000;
|
||||
const CONNECTION_CHECK_INTERVAL_MS = 20 * 1000;
|
||||
const CURRENT_BUILD_HASH = String(window.__SHINE_BUILD_HASH__ || '').trim();
|
||||
|
||||
let currentCleanup = null;
|
||||
let pingIntervalId = null;
|
||||
let versionCheckIntervalId = null;
|
||||
let versionCheckInFlight = false;
|
||||
let reconnectIntervalId = null;
|
||||
let sessionRuntimeStarted = false;
|
||||
let connectionState = '';
|
||||
@@ -120,6 +117,7 @@ let connectionStatusCountdownId = null;
|
||||
let connectionNextRetryAtMs = 0;
|
||||
let connectionCheckInFlight = false;
|
||||
let wsSessionRestoreInFlight = null;
|
||||
let uiUpdateReloadScheduled = false;
|
||||
|
||||
setClientErrorTransport((payload) => authService.reportClientError(payload));
|
||||
initPwaInstallPromptHandling();
|
||||
@@ -236,48 +234,21 @@ async function triggerImmediateConnectionRetry() {
|
||||
await checkConnectionHealth();
|
||||
}
|
||||
|
||||
function parseBuildHashFromHtml(html) {
|
||||
const text = String(html || '');
|
||||
const m = text.match(/window\.__SHINE_BUILD_HASH__\s*=\s*'([^']+)'/);
|
||||
return String(m?.[1] || '').trim();
|
||||
}
|
||||
function checkAndReloadIfUiUpdated(remoteHashRaw) {
|
||||
if (uiUpdateReloadScheduled) return;
|
||||
const remoteHash = String(remoteHashRaw || '').trim();
|
||||
if (!remoteHash || !CURRENT_BUILD_HASH || remoteHash === CURRENT_BUILD_HASH) return;
|
||||
|
||||
async function checkUiVersionAndReload() {
|
||||
if (versionCheckInFlight) return;
|
||||
versionCheckInFlight = true;
|
||||
try {
|
||||
const resp = await fetch(`./index.html?versionCheckTs=${Date.now()}`, { cache: 'no-store' });
|
||||
if (!resp.ok) return;
|
||||
const html = await resp.text();
|
||||
const remoteHash = parseBuildHashFromHtml(html);
|
||||
if (!remoteHash || !CURRENT_BUILD_HASH) return;
|
||||
if (remoteHash === CURRENT_BUILD_HASH) return;
|
||||
|
||||
addAppLogEntry({
|
||||
level: 'info',
|
||||
source: 'version-check',
|
||||
message: `Обнаружена новая версия UI: ${CURRENT_BUILD_HASH} -> ${remoteHash}`,
|
||||
});
|
||||
setConnectionStatus('updating');
|
||||
window.setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 600);
|
||||
} catch {
|
||||
// ignore transient network/version-check errors
|
||||
} finally {
|
||||
versionCheckInFlight = false;
|
||||
}
|
||||
}
|
||||
|
||||
function startVersionMonitor() {
|
||||
if (versionCheckIntervalId) {
|
||||
window.clearInterval(versionCheckIntervalId);
|
||||
versionCheckIntervalId = null;
|
||||
}
|
||||
void checkUiVersionAndReload();
|
||||
versionCheckIntervalId = window.setInterval(() => {
|
||||
void checkUiVersionAndReload();
|
||||
}, VERSION_CHECK_INTERVAL_MS);
|
||||
uiUpdateReloadScheduled = true;
|
||||
addAppLogEntry({
|
||||
level: 'info',
|
||||
source: 'version-check',
|
||||
message: `Обнаружена новая версия UI (через Ping): ${CURRENT_BUILD_HASH} -> ${remoteHash}`,
|
||||
});
|
||||
setConnectionStatus('updating');
|
||||
window.setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 600);
|
||||
}
|
||||
|
||||
async function checkConnectionHealth() {
|
||||
@@ -297,7 +268,9 @@ async function checkConnectionHealth() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
await authService.ws.request('Ping', { ts: Date.now() }, 7000);
|
||||
const pingResp = await authService.ws.request('Ping', { ts: Date.now() }, 7000);
|
||||
const remoteUiBuildHash = pingResp?.payload?.uiBuildHash || pingResp?.uiBuildHash || '';
|
||||
checkAndReloadIfUiUpdated(remoteUiBuildHash);
|
||||
setConnectionStatus('connected');
|
||||
} catch {
|
||||
connectionStatusText = '';
|
||||
@@ -817,7 +790,6 @@ async function init() {
|
||||
|
||||
await tryAutoLogin();
|
||||
await hydrateMessagesFromStore();
|
||||
startVersionMonitor();
|
||||
startConnectionMonitor();
|
||||
await ensureSessionRuntimeStarted();
|
||||
|
||||
@@ -830,7 +802,6 @@ async function init() {
|
||||
window.addEventListener('hashchange', renderApp);
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (document.visibilityState !== 'visible') return;
|
||||
void checkUiVersionAndReload();
|
||||
void checkConnectionHealth();
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user