'use strict'; /* global $, cleanErr */ // Update: Ora looks for a newer release on Hugging Face (at start, then every 6 hours, or when the version under the // name is clicked) and shows "Update to x.y.z" in the sidebar. Clicking it downloads the update, checks it and restarts. (function updates() { const btn = $('updateBtn'), ver = $('version'); ver.title = 'Check for updates'; let info = null, busy = false; async function check(manual) { if (busy) return; try { info = await window.ora.checkUpdate(); if (info.available) { btn.hidden = false; btn.disabled = false; btn.textContent = `↑ Update to ${info.latest}`; btn.title = info.canInstall ? `Ora ${info.latest} is out (${info.date}). Click to update: Ora downloads it, checks it and restarts.` : 'Updates install from the installed Ora (this is the development version).'; } else { btn.hidden = true; if (manual) flash(`v${info.current} is the newest`); } } catch (e) { if (manual) flash(cleanErr(e).slice(0, 40)); } } function flash(t) { const old = ver.textContent; ver.textContent = t; setTimeout(() => { ver.textContent = old; }, 3500); } btn.addEventListener('click', async () => { if (!info || busy) return; const mb = info.bytes ? ` (${Math.round(info.bytes / 1e6)} MB)` : ''; if (!window.confirm(`Update Ora to ${info.latest}${mb}?\n\nOra downloads the new version, checks it against the published checksum, then closes and opens again. Your plan and pictures stay as they are.`)) return; busy = true; btn.disabled = true; btn.textContent = 'Downloading…'; try { await window.ora.installUpdate(); btn.textContent = 'Restarting…'; } catch (e) { busy = false; btn.disabled = false; btn.textContent = `↑ Update to ${info.latest}`; window.alert(cleanErr(e)); } }); window.ora.onUpdateProgress(p => { if (!busy) return; btn.textContent = p.installing ? 'Installing… Ora restarts' : `Downloading ${p.total ? Math.round(p.done / p.total * 100) : Math.round(p.done / 1e6)}${p.total ? '%' : ' MB'}`; }); ver.addEventListener('click', () => check(true)); setTimeout(() => check(false), 4000); setInterval(() => check(false), 6 * 3600 * 1000); })();