Add in-app update checker and one-click updater

Settings now shows when a newer version is available, with the real
version number read from the remote's package.json (via the git
binary already required for this deployment model, so it works
against any remote, not just GitHub), and an "Uppdatera nu" button
that stops the server, pulls, reinstalls dependencies and restarts
automatically - warning explicitly if a race is currently active.
The existing app-version poller already reloads the page once a
restart is detected, so no new client-side polling was needed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
larssand
2026-09-09 22:05:13 +02:00
parent 2bbbd6e995
commit 4c463485e0
9 changed files with 335 additions and 8 deletions

View File

@@ -59,6 +59,14 @@ export function renderSettings(deps) {
createManualServerBackup,
createSafetyServerBackup,
refreshServerBackups,
updateStatus,
updateStatusLoaded,
updateCheckPending,
updateNotice,
updateNoticeIsError,
refreshUpdateStatus,
runUpdateNow,
setUpdateNotice,
} = deps;
const runWithSafetyBackup = async (action) => {
try {
@@ -438,6 +446,25 @@ export function renderSettings(deps) {
</div>
</section>
<section class="panel mt-16">
<div class="panel-header"><h3>${t("settings.update_title")}</h3></div>
<div class="panel-body">
<p>${t("settings.update_current_version")}: <strong>v${escapeHtml(String(updateStatus?.currentVersion || ""))}</strong></p>
${!updateStatusLoaded
? `<p class="hint">${t("settings.update_checking")}</p>`
: updateStatus?.error
? `<p class="error">${escapeHtml(t("settings.update_error", { msg: updateStatus.error }))}</p>`
: updateStatus?.available
? `<p class="update-available"><strong>${escapeHtml(t("settings.update_available", { version: updateStatus.remoteVersion || "?" }))}</strong></p>`
: `<p class="hint">${t("settings.update_up_to_date")}</p>`}
<div class="actions">
<button id="settingsCheckUpdate" class="btn" type="button" ${updateCheckPending ? "disabled" : ""}>${t("settings.update_check_now")}</button>
${updateStatus?.available ? `<button id="settingsRunUpdate" class="btn btn-primary" type="button">${t("settings.update_run_now")}</button>` : ""}
</div>
${updateNotice ? `<p class="${updateNoticeIsError ? "error" : "hint"}">${escapeHtml(updateNotice)}</p>` : ""}
</div>
</section>
<section class="panel mt-16">
<div class="panel-header"><h3>${t("settings.storage")}</h3></div>
<div class="panel-body">
@@ -752,6 +779,27 @@ Erik Eriksson;654321;4WD;Associated;;</code></pre>
});
document.getElementById("refreshServerBackups")?.addEventListener("click", () => refreshServerBackups());
document.getElementById("settingsCheckUpdate")?.addEventListener("click", async () => {
setUpdateNotice("");
await refreshUpdateStatus({ render: false, force: true });
renderView();
});
document.getElementById("settingsRunUpdate")?.addEventListener("click", async (event) => {
const version = updateStatus?.remoteVersion ? `v${updateStatus.remoteVersion}` : "";
let message = t("settings.update_confirm", { version });
if (state.activeSessionId) message += "\n\n" + t("settings.update_confirm_active_session");
if (!window.confirm(message)) return;
const button = event.currentTarget;
if (button instanceof HTMLButtonElement) button.disabled = true;
try {
await runUpdateNow();
setUpdateNotice(t("settings.update_started"), false);
} catch (error) {
setUpdateNotice(t("settings.update_failed", { msg: error instanceof Error ? error.message : String(error) }), true);
}
renderView();
});
document.getElementById("logoUpload")?.addEventListener("change", (event) => {
const input = event.currentTarget;
const file = input instanceof HTMLInputElement ? input.files?.[0] : null;