| … | … | @@ -38,9 +38,27 @@ export function withTheme (html, theme) { |
| 38 | 38 | * only the shell knows whether it can; a banner that offered a button the shell cannot honour would |
| 39 | 39 | * be the same defect `parseShell` keeps separate flags to avoid. |
| 40 | 40 | */ |
| 41 | /** |
| 42 | * Is a downloaded update actually waiting to be applied? |
| 43 | * |
| 44 | * ⛔ `running === null` MEANS "WE BOOTED THE APK'S OWN BUNDLE", and it is the normal state of a |
| 45 | * freshly installed app — `chooseBundle` returns `hash: null` for the asset, so the shell has no |
| 46 | * hash to report. Requiring `running` to be set therefore made the answer NO on exactly the devices |
| 47 | * that most need it: the phone staged an update correctly and then rendered "Up to date", with no |
| 48 | * banner, which is what "check now does nothing" looked like from the outside. |
| 49 | * |
| 50 | * Anything staged while we are running the asset is by construction not what booted, so it IS |
| 51 | * waiting. When `running` IS known, the comparison is the real one — staged and identical means the |
| 52 | * node re-verified what it is already running, which is the ordinary case and not an update. |
| 53 | */ |
| 54 | export function updateWaiting (u) { |
| 55 | if (!u || !u.staged) return false |
| 56 | return u.running ? u.staged !== u.running : true |
| 57 | } |
| 58 | |
| 41 | 59 | export function withUpdateBanner (html, update) { |
| 42 | 60 | const u = update || null |
| 43 | | if (!u || !u.staged || !u.running || u.staged === u.running) return html |
| 61 | if (!u || !updateWaiting(u)) return html |
| 44 | 62 | const bar = '<div class="update-bar"><a href="/settings">An update is ready — restart to apply</a></div>' |
| 45 | 63 | // After the opening <body>, so it is the first thing in the document and cannot be pushed below |
| 46 | 64 | // the fold by whatever the page happens to render first. |
| … | … | @@ -1511,7 +1529,7 @@ export function updateSettings (u) { |
| 1511 | 1529 | // ⛔ STAGED AND DIFFERENT is the only state that means "an update is waiting". Staged and IDENTICAL |
| 1512 | 1530 | // is the ordinary case — the node re-verified the bundle it is already running — and calling that |
| 1513 | 1531 | // "update available" is what makes a restart button lie. |
| 1514 | | const waiting = u.staged && u.running && u.staged !== u.running |
| 1532 | const waiting = updateWaiting(u) |
| 1515 | 1533 | const body = waiting |
| 1516 | 1534 | ? '<p class="warn">An update is downloaded and will apply on the next start.</p>' + |
| 1517 | 1535 | '<p class="who">running ' + short(u.running) + ' → staged ' + short(u.staged) + '</p>' + |