Auto-Update wie beim MSCO Launcher
Beim Start installiert sich ein neuer Launcher sofort selbst (Fortschrittsfenster, Neustart), neue BSO-Versionen kommen nach dem Anmelden - beides abschaltbar. Einstellungen: Nach Updates suchen / Installieren und neu starten. Updates wieder nur von der Website; dotnet publish laedt hoch (release.ps1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -141,6 +141,7 @@ function showApp(username) {
|
||||
$("meName").textContent = username;
|
||||
$("meAvatar").textContent = (username || "?").slice(0, 1).toUpperCase();
|
||||
showPage("home");
|
||||
autoUpdateMod();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Seiten
|
||||
@@ -419,9 +420,28 @@ async function renderSettings(root) {
|
||||
uninstall.addEventListener("click", () => busy(uninstall, () => call("uninstall")));
|
||||
const langBox = h("div", { class: "lang-switch", "data-lang-switch": true });
|
||||
|
||||
// Launcher-Update von Hand (wie beim MSCO Launcher: "Nach Updates suchen" -> "Installieren und neu starten")
|
||||
const launcherBox = h("div", {});
|
||||
const check = h("button", { class: "btn small", type: "button" }, t("Nach Updates suchen"));
|
||||
const install = h("button", { class: "btn small primary", type: "button" }, t("Installieren und neu starten"));
|
||||
install.addEventListener("click", () => busy(install, async () => {
|
||||
progressBox = h("div", { class: "progress" }, h("span", { class: "small muted" }), h("div", { class: "bar" }, h("div")));
|
||||
launcherBox.append(progressBox);
|
||||
try { await call("installLauncherUpdate"); install.textContent = t("Neustart …"); install.disabled = true; }
|
||||
catch (e) { progressBox.remove(); throw e; }
|
||||
}));
|
||||
check.addEventListener("click", () => busy(check, async () => {
|
||||
const u = await call("checkLauncherUpdate");
|
||||
launcherBox.replaceChildren(u.available
|
||||
? h("div", { class: "row" }, h("b", {}, t("Launcher {0} ist da", u.latest)), install)
|
||||
: h("span", { class: "muted small" }, u.latest ? t("Der Launcher ist aktuell") : t("Keine Launcher-Version auf dem Server")));
|
||||
}));
|
||||
|
||||
root.replaceChildren(h("h1", {}, t("Einstellungen")), h("div", { class: "settings" },
|
||||
h("div", { class: "card" },
|
||||
toggle(t("BSO automatisch aktualisieren"), t("Vor jedem Start die neueste Mod-Version installieren"), "autoUpdateMod", s?.settings.autoUpdateMod ?? true),
|
||||
toggle(t("Launcher automatisch aktualisieren"), t("Beim Start wird eine neue Launcher-Version gleich installiert (er startet von selbst neu)"),
|
||||
"autoUpdateLauncher", init.autoUpdateLauncher ?? true),
|
||||
toggle(t("BSO automatisch aktualisieren"), t("Neue BSO-Versionen beim Start des Launchers und vor jedem Spielstart installieren"), "autoUpdateMod", s?.settings.autoUpdateMod ?? true),
|
||||
toggle(t("Launcher offen lassen"), t("Sonst schliesst er sich nach dem Spielstart"), "keepOpen", s?.settings.keepOpen ?? false),
|
||||
h("div", { class: "switch" }, h("span", {}, t("Sprache")), langBox)),
|
||||
h("div", { class: "card" },
|
||||
@@ -431,50 +451,56 @@ async function renderSettings(root) {
|
||||
h("div", { class: "card" },
|
||||
h("h3", {}, "Launcher"),
|
||||
h("span", { class: "muted small" }, t("Version {0} · Server {1}", init.version, init.master)),
|
||||
h("div", { class: "row" }, log, uninstall))));
|
||||
launcherBox,
|
||||
h("div", { class: "row" }, check, log, uninstall))));
|
||||
renderLangSwitch(setLang);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Update-Abfrage
|
||||
// ---------------------------------------------------------------- Updates (wie beim MSCO Launcher)
|
||||
|
||||
/** Bei jedem Start: gibt es einen neuen Launcher (oder eine neue Mod)? Dann fragen - "Später" fragt beim naechsten Start wieder. */
|
||||
async function askForUpdates() {
|
||||
/**
|
||||
* Beim Start: gibt es einen neueren Launcher, gleich installieren und neu starten (Einstellung "Launcher automatisch
|
||||
* aktualisieren"). Hoechstens 8 s auf die Pruefung warten - ohne Netz startet der Launcher normal.
|
||||
*/
|
||||
async function startupUpdate(init) {
|
||||
let u;
|
||||
try {
|
||||
u = await Promise.race([call("checkLauncherUpdate"), new Promise((_, no) => setTimeout(() => no(new Error("timeout")), 8000))]);
|
||||
} catch { return false; }
|
||||
if (!u || !u.available) return false;
|
||||
if (init.autoUpdateLauncher === false) { toast(t("Launcher {0} ist da – unter Einstellungen installieren", u.latest)); return false; }
|
||||
|
||||
const progress = h("div", { class: "progress" }, h("span", { class: "small muted" }), h("div", { class: "bar" }, h("div")));
|
||||
const text = h("p", { class: "muted" }, t("Launcher wird auf {0} aktualisiert …", u.latest));
|
||||
const overlay = h("div", { class: "modal-back" }, h("div", { class: "modal update-box" },
|
||||
h("img", { src: "logo.svg", alt: "" }),
|
||||
h("h2", {}, t("Launcher {0} ist da", u.latest)),
|
||||
text, progress,
|
||||
h("small", { class: "muted" }, t("Der Launcher startet danach von selbst neu."))));
|
||||
document.body.append(overlay);
|
||||
progressBox = progress;
|
||||
try {
|
||||
await call("installLauncherUpdate");
|
||||
text.textContent = t("Neustart …");
|
||||
return true;
|
||||
} catch (e) {
|
||||
overlay.remove();
|
||||
progressBox = null;
|
||||
toast(t("Launcher-Update fehlgeschlagen: {0}", e.message), true);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Nach dem Anmelden: eine neue BSO-Version gleich installieren (Einstellung "BSO automatisch aktualisieren"). */
|
||||
async function autoUpdateMod() {
|
||||
let s;
|
||||
try { s = await call("status"); } catch { return; }
|
||||
const mod = s.mod.installed && s.mod.updateAvailable && !s.game.running ? s.mod : null;
|
||||
if (!s.launcherUpdate && !mod) return;
|
||||
|
||||
const item = (name, from, to, changelog) => h("div", { class: "update-item" },
|
||||
h("div", {}, h("b", {}, name + " " + to), h("span", { class: "muted small" }, " " + t("installiert: {0}", from))),
|
||||
h("pre", {}, changelog || t("Keine Beschreibung")));
|
||||
const progress = h("div", { class: "progress hidden" }, h("span", { class: "small muted" }), h("div", { class: "bar" }, h("div")));
|
||||
const later = h("button", { class: "btn", type: "button" }, t("Später"));
|
||||
const now = h("button", { class: "btn primary", type: "button" }, t("Jetzt aktualisieren"));
|
||||
const box = h("div", { class: "modal-back" }, h("div", { class: "modal", role: "dialog" },
|
||||
h("h2", {}, t("Update verfügbar")),
|
||||
h("p", { class: "muted" }, t("Beim Start gefunden – jetzt aktualisieren?")),
|
||||
s.launcherUpdate ? item("Launcher", s.launcherVersion, s.launcherUpdate, s.launcherChangelog) : null,
|
||||
mod ? item(t("BSO-Mod"), mod.installed, mod.latest, mod.changelog) : null,
|
||||
progress,
|
||||
h("div", { class: "row", style: "justify-content:flex-end" }, later, now)));
|
||||
document.body.append(box);
|
||||
now.focus();
|
||||
|
||||
later.addEventListener("click", () => box.remove());
|
||||
now.addEventListener("click", async () => {
|
||||
now.disabled = later.disabled = true;
|
||||
progressBox = progress;
|
||||
try {
|
||||
if (mod) await call("installMod");
|
||||
if (s.launcherUpdate) { await call("installLauncherUpdate"); toast(t("Launcher startet neu …")); return; } // beendet sich gleich
|
||||
box.remove();
|
||||
toast(t("BSO {0} installiert", mod.latest));
|
||||
if (!$("app").classList.contains("hidden")) showPage(page);
|
||||
} catch (e) {
|
||||
toast(e.message, true);
|
||||
now.disabled = later.disabled = false;
|
||||
}
|
||||
});
|
||||
if (!s.settings.autoUpdateMod || !s.game.found || s.game.running || !s.mod.updateAvailable || !s.mod.latest) return;
|
||||
try {
|
||||
const r = await call("installMod");
|
||||
toast(t("BSO {0} installiert", r.version));
|
||||
if (page === "home") showPage("home");
|
||||
} catch (e) { toast(e.message, true); }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- Start
|
||||
@@ -494,7 +520,7 @@ async function askForUpdates() {
|
||||
$("meVersion").textContent += " · DEV";
|
||||
}
|
||||
$("authServer").textContent = t("Server: {0}", init.master.replace(/^https?:\/\//, ""));
|
||||
askForUpdates(); // auch vor dem Anmelden
|
||||
if (await startupUpdate(init)) return; // neue Version startet gleich
|
||||
if (!init.loggedIn) { showAuth(); return; }
|
||||
const me = await call("me");
|
||||
if (me.loggedIn) showApp(me.username);
|
||||
|
||||
Reference in New Issue
Block a user