v0.7.7: update panel version picker with Older/Reinstall/Update labels
This commit is contained in:
1 parent
f48a09e8d3
commit
bb5065dd59
4 files changed
+162
-14
No files matched your search
+81
-3
@@ -210,6 +210,7 @@
|
||||
// silence controls. Auto-expands only for a new, non-silenced update.
|
||||
let ubData = null;
|
||||
let ubViewChannel = null; // channel shown in the panel; null = own channel
|
||||
let ubViewVersion = null; // version picked in the dropdown; null = newest
|
||||
let ubExpanded = false;
|
||||
|
||||
function ubChannelLatest(channel) {
|
||||
@@ -224,6 +225,37 @@
|
||||
return null;
|
||||
}
|
||||
|
||||
// All known releases for a channel, newest first. Falls back to the
|
||||
// single latest entry when the server payload predates release lists.
|
||||
function ubChannelReleases(channel) {
|
||||
if (!ubData) return [];
|
||||
const lists = ubData.releases || {};
|
||||
if (Array.isArray(lists[channel]) && lists[channel].length) {
|
||||
return lists[channel];
|
||||
}
|
||||
const entry = ubChannelLatest(channel);
|
||||
return entry ? [entry] : [];
|
||||
}
|
||||
|
||||
// Numeric version compare mirroring the server's compare_versions:
|
||||
// compares the X.Y.Z numbers only, so stable and experimental versions
|
||||
// are comparable across channels. Returns -1, 0 or 1.
|
||||
function ubCmpVer(a, b) {
|
||||
const parse = (v) => {
|
||||
const m = /^v?(\d+)\.(\d+)\.(\d+)(?:-([A-Za-z0-9]+))?$/.exec(String(v || '').trim());
|
||||
return m ? [parseInt(m[1], 10), parseInt(m[2], 10), parseInt(m[3], 10)] : null;
|
||||
};
|
||||
const pa = parse(a), pb = parse(b);
|
||||
if (!pa && !pb) return 0;
|
||||
if (!pa) return -1;
|
||||
if (!pb) return 1;
|
||||
for (let i = 0; i < 3; i++) {
|
||||
if (pa[i] < pb[i]) return -1;
|
||||
if (pa[i] > pb[i]) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function ubHasNews() {
|
||||
if (!ubData || ubData.silence_all) return false;
|
||||
if (ubData.preview) return true;
|
||||
@@ -278,6 +310,22 @@
|
||||
const isSilenced = !!(entry && silenced.includes(entry.version));
|
||||
const canUpdate = !!(entry && entry.available && !isSilenced);
|
||||
|
||||
// Per-version picker: every known release on the viewed channel,
|
||||
// newest first. Older than the running version cannot be installed;
|
||||
// same-numbered is a reinstall (works across channels); newer is
|
||||
// an update. Settings and protected paths are preserved either way.
|
||||
const releases = ubChannelReleases(viewing);
|
||||
let picked = null;
|
||||
if (releases.length) {
|
||||
picked = releases.find(r => r.version === ubViewVersion) || releases[0];
|
||||
if (!ubViewVersion || !releases.some(r => r.version === ubViewVersion)) {
|
||||
ubViewVersion = picked.version;
|
||||
}
|
||||
}
|
||||
const cmp = picked ? ubCmpVer(picked.version, data.current_version) : 0;
|
||||
const pickedSilenced = !!(picked && silenced.includes(picked.version));
|
||||
const pickedCanInstall = !!(picked && cmp >= 0 && !pickedSilenced);
|
||||
|
||||
let opts = '';
|
||||
channels.forEach(ch => {
|
||||
const label = ch === data.channel ? `${ch} (yours)` : ch;
|
||||
@@ -285,9 +333,19 @@
|
||||
});
|
||||
|
||||
let body = `<div class="ub-sub">You are on ${escHtml(data.current_version)} (${escHtml(data.channel)})</div>`;
|
||||
body += `<div class="ub-row"><label>Channel: <select id="ub-channel" onchange="ubViewChannel=this.value;renderUpdateBanner();">${opts}</select></label>` +
|
||||
body += `<div class="ub-row"><label>Channel: <select id="ub-channel" onchange="ubViewChannel=this.value;ubViewVersion=null;renderUpdateBanner();">${opts}</select></label>` +
|
||||
`<button onclick="checkUpdatesNow()">Check now</button></div>`;
|
||||
|
||||
if (releases.length) {
|
||||
let vopts = '';
|
||||
releases.forEach(r => {
|
||||
const c = ubCmpVer(r.version, data.current_version);
|
||||
const tag = c < 0 ? ' — Older' : (c === 0 ? ' — Current (reinstall)' : ' — Update available');
|
||||
vopts += `<option value="${escHtml(r.version)}"${picked && r.version === picked.version ? ' selected' : ''}>${escHtml(r.version)}${escHtml(tag)}</option>`;
|
||||
});
|
||||
body += `<div class="ub-row"><label>Version: <select id="ub-version" onchange="ubViewVersion=this.value;renderUpdateBanner();">${vopts}</select></label></div>`;
|
||||
}
|
||||
|
||||
if (data.preview && ubSafeVer(data.preview.version)) {
|
||||
ubNotesCache[data.preview.version] = data.preview.notes || '';
|
||||
body += `<div class="ub-title">${escHtml(data.preview.version)} <span class="ub-preview-tag">preview</span></div>` +
|
||||
@@ -295,7 +353,25 @@
|
||||
`<button class="ub-ghost" onclick="clearPreview()">Clear preview</button></div>`;
|
||||
}
|
||||
|
||||
if (entry && ubSafeVer(entry.version)) {
|
||||
if (picked && ubSafeVer(picked.version)) {
|
||||
ubNotesCache[picked.version] = picked.notes || '';
|
||||
const isCurrent = cmp === 0;
|
||||
const stateLine = cmp < 0
|
||||
? `<div class="ub-sub">${escHtml(picked.version)} is older than your current version — cannot install.</div>`
|
||||
: (!pickedCanInstall && pickedSilenced)
|
||||
? `<div class="ub-sub">${escHtml(picked.version)} silenced - a newer version will show again.</div>`
|
||||
: isCurrent
|
||||
? `<div class="ub-title">Reinstall: ${escHtml(picked.version)} (same as current)</div>`
|
||||
: `<div class="ub-title">Update available: ${escHtml(picked.version)}</div>`;
|
||||
body += stateLine;
|
||||
body += '<div class="ub-actions">' +
|
||||
(picked.notes ? `<button class="ub-ghost" onclick="openNotesOverlay('${picked.version}')">Patch notes</button>` : '') +
|
||||
(pickedCanInstall ? (isCurrent
|
||||
? `<button onclick="applyUpdate('${picked.version}')">Reinstall ${escHtml(picked.version)}</button>`
|
||||
: `<button onclick="applyUpdate('${picked.version}')">Update to ${escHtml(picked.version)}</button>`) : '') +
|
||||
(cmp > 0 && !pickedSilenced ? `<button class="ub-ghost" onclick="silenceUpdateVersion('${picked.version}')">Silence this version</button>` : '') +
|
||||
'</div>';
|
||||
} else if (entry && ubSafeVer(entry.version)) {
|
||||
ubNotesCache[entry.version] = entry.notes || '';
|
||||
const stateLine = !entry.available
|
||||
? `<div class="ub-sub">${escHtml(viewing)} is up to date at ${escHtml(entry.version)}.</div>`
|
||||
@@ -370,7 +446,9 @@
|
||||
}
|
||||
|
||||
async function applyUpdate(version) {
|
||||
if (!confirm(`Update to ${version}? The dashboard backs itself up, installs, then restarts. Players will be briefly disconnected from the panel (not the game).`)) return;
|
||||
const isReinstall = ubData && version === ubData.current_version;
|
||||
const action = isReinstall ? 'Reinstall' : 'Update to';
|
||||
if (!confirm(`${action} ${version}? Settings and protected files are preserved. The dashboard backs itself up, installs, then restarts. Players will be briefly disconnected from the panel (not the game).`)) return;
|
||||
const st = document.getElementById('ub-status');
|
||||
if (st) st.textContent = 'Updating - the panel will restart...';
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user