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
+40
-10
@@ -99,6 +99,7 @@ class UpdateService:
|
||||
self._channel = channel_of(self._current_version)
|
||||
self._latest = None # {'version', 'tag', 'notes', 'zipball_url'}
|
||||
self._other_latest = None
|
||||
self._releases = {'experimental': [], 'stable': []} # per-channel lists, newest first
|
||||
self._last_check = 0
|
||||
self._check_interval = 1800 # 30 minutes
|
||||
self._update_in_progress = False
|
||||
@@ -226,9 +227,13 @@ class UpdateService:
|
||||
return ''
|
||||
|
||||
@staticmethod
|
||||
def _pick_latest(releases, channel):
|
||||
"""Newest release for a channel. Returns entry dict or None."""
|
||||
best = None
|
||||
def _collect_channel(releases, channel):
|
||||
"""All releases for a channel, newest first.
|
||||
|
||||
Each entry is {'version', 'tag', 'notes', 'zipball_url'}.
|
||||
Drafts, non-matching tags and unparsable versions are skipped.
|
||||
"""
|
||||
found = []
|
||||
for release in releases:
|
||||
if not isinstance(release, dict) or release.get('draft'):
|
||||
continue
|
||||
@@ -239,23 +244,34 @@ class UpdateService:
|
||||
if parsed is None:
|
||||
continue
|
||||
version = tag[1:] if tag.lower().startswith('v') else tag
|
||||
entry = {
|
||||
found.append({
|
||||
'version': version,
|
||||
'tag': tag,
|
||||
'notes': str(release.get('body') or ''),
|
||||
'zipball_url': str(release.get('zipball_url') or ''),
|
||||
}
|
||||
if best is None or compare_versions(entry['version'], best['version']) > 0:
|
||||
best = entry
|
||||
return best
|
||||
})
|
||||
found.sort(key=lambda e: parse_version(e['version'])[0], reverse=True)
|
||||
return found
|
||||
|
||||
@staticmethod
|
||||
def _pick_latest(releases, channel):
|
||||
"""Newest release for a channel. Returns entry dict or None."""
|
||||
collected = UpdateService._collect_channel(releases, channel)
|
||||
return collected[0] if collected else None
|
||||
|
||||
def check_for_updates(self):
|
||||
"""Refresh latest-version info for our channel (and the other one)."""
|
||||
try:
|
||||
releases = self._fetch_releases()
|
||||
other = 'stable' if self._channel == 'experimental' else 'experimental'
|
||||
self._latest = self._pick_latest(releases, self._channel)
|
||||
self._other_latest = self._pick_latest(releases, other)
|
||||
self._releases = {
|
||||
'experimental': self._collect_channel(releases, 'experimental'),
|
||||
'stable': self._collect_channel(releases, 'stable'),
|
||||
}
|
||||
self._latest = (self._releases[self._channel][0]
|
||||
if self._releases[self._channel] else None)
|
||||
self._other_latest = (self._releases[other][0]
|
||||
if self._releases[other] else None)
|
||||
self._last_check = time.time()
|
||||
if self._latest:
|
||||
logger.info(
|
||||
@@ -280,11 +296,21 @@ class UpdateService:
|
||||
show_other = bool(
|
||||
other and other['version'] != (latest['version'] if latest else None)
|
||||
and self._is_newer_or_same(other['version']))
|
||||
# Per-channel release lists for the version picker (newest first).
|
||||
# zipball URLs stay server-side; the panel only needs version/notes.
|
||||
lists = {}
|
||||
for channel, entries in (self._releases or {}).items():
|
||||
lists[channel] = [
|
||||
{'version': e['version'], 'tag': e['tag'],
|
||||
'notes': e['notes']}
|
||||
for e in entries
|
||||
]
|
||||
return {
|
||||
'current_version': self._current_version,
|
||||
'channel': self._channel,
|
||||
'available': available,
|
||||
'latest': latest,
|
||||
'releases': lists,
|
||||
'other_channel': {
|
||||
'channel': 'stable' if self._channel == 'experimental' else 'experimental',
|
||||
'latest': other,
|
||||
@@ -314,6 +340,10 @@ class UpdateService:
|
||||
for entry in (self._latest, self._other_latest):
|
||||
if entry and entry['version'] == version:
|
||||
return entry
|
||||
for entries in (self._releases or {}).values():
|
||||
for entry in entries:
|
||||
if entry['version'] == version:
|
||||
return entry
|
||||
return None
|
||||
|
||||
def apply_update(self, version=None):
|
||||
|
||||
+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 {
|
||||
|
||||
@@ -75,6 +75,46 @@ class TestPickLatest:
|
||||
assert UpdateService._pick_latest([], 'stable') is None
|
||||
|
||||
|
||||
class TestReleaseLists:
|
||||
def test_collect_channel_newest_first(self):
|
||||
releases = UpdateService._collect_channel(make_releases(), 'experimental')
|
||||
assert [e['version'] for e in releases] == [
|
||||
'0.7.5-experimental', '0.7.3-Experimental']
|
||||
|
||||
def test_collect_skips_drafts_and_garbage(self):
|
||||
releases = UpdateService._collect_channel(make_releases(), 'stable')
|
||||
assert [e['version'] for e in releases] == ['0.7.4']
|
||||
|
||||
def test_status_includes_lists_and_find_searches_them(self, tmp_path, monkeypatch):
|
||||
svc = make_service(tmp_path, '0.7.4-experimental')
|
||||
monkeypatch.setattr(svc, '_fetch_releases', make_releases)
|
||||
svc.check_for_updates()
|
||||
status = svc.status()
|
||||
assert [e['version'] for e in status['releases']['experimental']] == [
|
||||
'0.7.5-experimental', '0.7.3-Experimental']
|
||||
assert [e['version'] for e in status['releases']['stable']] == ['0.7.4']
|
||||
# list payload stays lean (no download URLs for the panel)
|
||||
assert 'zipball_url' not in status['releases']['experimental'][0]
|
||||
# an older (non-latest) version is known but refused as a downgrade
|
||||
assert svc._find_release('0.7.3-Experimental')['tag'] == 'v0.7.3-Experimental'
|
||||
ok, msg = svc.apply_update('0.7.3-Experimental')
|
||||
assert ok is False
|
||||
assert 'owngrade' in msg or 'older' in msg
|
||||
|
||||
def test_cross_channel_same_number_is_reinstall(self, tmp_path, monkeypatch):
|
||||
# Stable 0.7.4 installing experimental 0.7.4 is numeric-equal:
|
||||
# allowed past validation (fails later only on download).
|
||||
svc = make_service(tmp_path, '0.7.4')
|
||||
monkeypatch.setattr(svc, '_fetch_releases', lambda: [
|
||||
{'tag_name': 'v0.7.4-experimental', 'body': 'x',
|
||||
'zipball_url': 'https://example.com/x.zip'},
|
||||
])
|
||||
svc.check_for_updates()
|
||||
ok, msg = svc.apply_update('0.7.4-experimental')
|
||||
assert ok is False
|
||||
assert 'owngrade' not in msg and 'Unknown version' not in msg
|
||||
|
||||
|
||||
class TestApplyRules:
|
||||
def test_refuses_downgrade_without_network(self, tmp_path):
|
||||
svc = make_service(tmp_path, '0.7.5-experimental')
|
||||
|
||||
Reference in new issue
Block a user