diff --git a/web/templates/update.html b/web/templates/update.html index eb20088..e517690 100644 --- a/web/templates/update.html +++ b/web/templates/update.html @@ -11,7 +11,7 @@ Обновления - GitHub update center: автоматический мониторинг, changelog и установка + GitHub update center: changelog, проверка и установка user: {{ user }} @@ -58,16 +58,14 @@ {% if not info.fetch_ok %} GitHub fetch вернул ошибку: {{ info.fetch_error }} {% endif %} - - Проверка обновлений выполняется автоматически при открытии страницы и дальше каждые 5 минут. Ручная кнопка убрана — меньше лишних действий, больше порядка. - - + + + {{ 'Установить обновления' if info.has_update else 'Проверить обновления' }} + {% if info.has_update %} - - Установить обновление + + Установить обновления - {% else %} - Установить обновление {% endif %} @@ -105,7 +103,7 @@ {% else %} - Нет пропущенных версий. Система на свежем коде, красота. + Нет пропущенных версий. Система на свежем коде. {% endfor %} @@ -145,7 +143,10 @@ const logBox = document.getElementById('update-log'); const logState = document.getElementById('update-log-state'); const lastCheckBox = document.getElementById('last-check-value'); - let autoCheckRunning = false; + const checkForm = document.getElementById('update-check-form'); + const applyForm = document.getElementById('update-apply-form'); + const mainButton = document.getElementById('update-main-button'); + const applyButton = document.getElementById('update-apply-button'); function statusClass(status) { if (status === 'success') return 'status ok'; @@ -153,6 +154,15 @@ return 'status warn'; } + function stageText(state) { + const status = state.status || 'idle'; + const message = state.message || ''; + if (status === 'running') return message || 'Установка выполняется'; + if (status === 'success') return 'Обновление установлено'; + if (status === 'error') return 'Ошибка обновления'; + return message || 'Готово'; + } + async function refreshUpdateStatus() { try { const response = await fetch('/update/status', {cache: 'no-store'}); @@ -167,29 +177,27 @@ finishedBox.textContent = state.finished_at || '—'; logBox.textContent = payload.log_tail || 'Лог пока пуст.'; logState.textContent = 'live · ' + (payload.checked_at || 'now'); + if (applyButton && state.status === 'running') applyButton.textContent = stageText(state); } catch (error) { logState.textContent = 'live error'; } } - async function autoCheckUpdates() { - if (autoCheckRunning) return; - autoCheckRunning = true; - try { - await fetch('/update/check', {method: 'POST', cache: 'no-store', redirect: 'follow'}); - const now = new Date().toLocaleString(); - if (lastCheckBox) lastCheckBox.textContent = now; - } catch (error) { - if (logState) logState.textContent = 'check error'; - } finally { - autoCheckRunning = false; - } + if (checkForm) { + checkForm.addEventListener('submit', () => { + if (mainButton) mainButton.textContent = 'Проверяем GitHub...'; + }); + } + if (applyForm) { + applyForm.addEventListener('submit', () => { + if (applyButton) applyButton.textContent = 'Запускаем обновление...'; + setTimeout(refreshUpdateStatus, 1200); + setTimeout(refreshUpdateStatus, 2600); + }); } refreshUpdateStatus(); - autoCheckUpdates(); setInterval(refreshUpdateStatus, 2000); - setInterval(autoCheckUpdates, 300000);