diff --git a/tools/build_site.py b/tools/build_site.py index 7e56d48..c153bfe 100644 --- a/tools/build_site.py +++ b/tools/build_site.py @@ -246,7 +246,17 @@ def flasher_html(page: Page) -> str: f'Open the official installer.

' '' '

Already installed? Use System → Firmware ' - 'on your gateway to update without a USB cable.

') + 'on your gateway to update without a USB cable.

' + # Shown by site.js once the installer dialog closes after a finished install. + '') def release_note(page: Page) -> str: diff --git a/tools/test_site_browser.cjs b/tools/test_site_browser.cjs index b62abcd..7d54890 100644 --- a/tools/test_site_browser.cjs +++ b/tools/test_site_browser.cjs @@ -82,6 +82,18 @@ pages.unshift(''); await page.click('.menu'); if (!(await page.isVisible('#site-nav'))) failures.push(`${width}: mobile menu does not open`); if (shots) await page.screenshot({ path: path.join(shots, `site-${width}-menu.png`) }); + // The bar stays on top while scrolling; the open menu fits the screen + // and closes on page scroll, a tap outside or Escape. + const fits = await page.evaluate(() => document.getElementById('site-nav').getBoundingClientRect().bottom <= innerHeight + 1); + if (!fits) failures.push(`${width}: open menu taller than the screen`); + await page.evaluate(() => scrollTo(0, 600)); await page.waitForTimeout(250); + if (await page.isVisible('#site-nav')) failures.push(`${width}: menu stays open while the page scrolls`); + if (await page.evaluate(() => Math.round(document.querySelector('.top').getBoundingClientRect().top)) !== 0) + failures.push(`${width}: header does not follow the scroll`); + await page.click('.menu'); await page.click('main h2, main p'); + if (await page.isVisible('#site-nav')) failures.push(`${width}: menu stays open after a tap outside`); + await page.click('.menu'); await page.keyboard.press('Escape'); + if (await page.isVisible('#site-nav')) failures.push(`${width}: menu stays open after Escape`); } await page.goto(base, { waitUntil: 'load' }); if (width > 760 && await page.isVisible('.menu')) failures.push(`${width}: mobile menu button visible on a wide screen`); @@ -154,6 +166,38 @@ pages.unshift(''); if (dimensions.w !== dimensions.expectedW || dimensions.h !== dimensions.expectedH) failures.push(`${width}: screenshot dimensions mismatch ${await img.getAttribute('src')}`); } + // Web installer: the next step and one quiet tip line appear only after a + // finished install, once the installer dialog closes; the tip line at + // most once a month per browser. The dialog is a local stand-in for + // ESP Web Tools' element (no USB device in the test). + await page.goto(base + 'install-firmware/', { waitUntil: 'load' }); + if (await page.locator('#flasher-done').count()) { + await page.evaluate(() => localStorage.removeItem('rg-tip-shown')); + const fakeInstall = finished => page.evaluate(async finished => { + const d = document.createElement('ewt-install-dialog'); + document.body.appendChild(d); + await new Promise(r => setTimeout(r, 50)); + d._installState = { state: finished ? 'finished' : 'writing' }; + await new Promise(r => setTimeout(r, 700)); + d.dispatchEvent(new CustomEvent('closed')); d.remove(); + }, finished); + await fakeInstall(false); + if (await page.isVisible('#flasher-done')) failures.push(`${width}: install note shown without a finished install`); + await fakeInstall(true); + if (!(await page.isVisible('#flasher-done')) || !(await page.isVisible('#flasher-done .flasher-tip'))) + failures.push(`${width}: install note or tip line missing after a finished install`); + await page.locator('#flasher-done [data-support-open]').click(); + await dialog.waitFor({ state: 'visible' }); + await page.keyboard.press('Escape'); + await dialog.waitFor({ state: 'hidden' }); + await page.locator('.flasher-done-close').click(); + if (await page.isVisible('#flasher-done')) failures.push(`${width}: install note does not close`); + await fakeInstall(true); + if (!(await page.isVisible('#flasher-done')) || await page.isVisible('#flasher-done .flasher-tip')) + failures.push(`${width}: tip line repeated within a month`); + if (await page.evaluate(() => document.documentElement.scrollWidth > innerWidth)) + failures.push(`${width}: install note overflows horizontally`); + } if (errors.length) failures.push(`${width}: console/page errors ${[...new Set(errors)].slice(0, 3).join(' | ')}`); await context.close(); } diff --git a/website/assets/site.css b/website/assets/site.css index 86511f5..bd5906f 100644 --- a/website/assets/site.css +++ b/website/assets/site.css @@ -147,6 +147,17 @@ main:focus { outline: none; } .flasher-actions { display: flex; flex-wrap: wrap; gap: 8px; } .flasher .btn, .install-alternative .btn { max-width: 100%; white-space: normal; text-align: center; justify-content: center; font: inherit; font-weight: 600; } .flasher .flasher-help { margin: 16px 0 0; font-size: 14px; } +/* After a finished install: next step, and one quiet, optional tip line. */ +.flasher-done { position: relative; margin: 16px 0 0; padding: 14px 44px 14px 16px; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 12px; background: var(--card); } +.flasher-done[hidden], .flasher-done .flasher-tip[hidden] { display: none; } +.flasher-done strong { display: block; margin-bottom: 6px; } +.flasher-done p { margin: 0 0 8px; } +.flasher-done .flasher-tip { margin: 12px 0 0; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; } +.flasher-done .flasher-tip p { margin: 0 0 10px; } +.flasher-done .tip-btn { color: #0A0F0C; background: #FF5E5B; border-color: #FF5E5B; font-weight: 600; gap: 6px; } +.flasher-done .tip-btn:hover, .flasher-done .tip-btn:focus-visible { background: #FF7D7A; border-color: #FF7D7A; } +.flasher-done-close { position: absolute; top: 6px; right: 6px; width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font: 16px var(--font); cursor: pointer; } +.flasher-done-close:hover, .flasher-done-close:focus-visible { color: var(--text); background: var(--surface); } .install-alternative { margin: 20px 0; } .install-alternative h2 { margin-top: 0; font-size: 22px; } @media (max-width: 480px) { @@ -185,9 +196,14 @@ summary { cursor: pointer; font-weight: 600; } .hero { grid-template-columns: 1fr; padding-top: 32px; } } @media (max-width: 760px) { - /* Phones: the header scrolls with the page. Sticky, it stayed on screen with - * the menu open (over half the viewport) and could hide the page heading. */ - .top { position: relative; backdrop-filter: none; background: var(--bg); } + /* Phones: the header stays on top while scrolling, opaque (a blurred + * translucent bar can freeze while scrolling on mobile browsers). The open + * menu never grows past the screen: it scrolls inside, and site.js closes + * it when the page scrolls, on a tap outside or with Escape, so it cannot + * stay over the page heading. Anchored headings stop below the bar. */ + .top { backdrop-filter: none; background: var(--bg); } + .site-nav.open { max-height: calc(100vh - 80px); max-height: calc(100dvh - 80px); overflow-y: auto; overscroll-behavior: contain; } + main [id] { scroll-margin-top: 80px; } .tools .menu { display: inline-flex; } .tools .theme { display: none; } /* phones: the board icon takes its place; the theme follows the phone */ .top-inner { flex-wrap: wrap; gap: 8px; } diff --git a/website/assets/site.js b/website/assets/site.js index 0a18e8a..6b74399 100644 --- a/website/assets/site.js +++ b/website/assets/site.js @@ -24,11 +24,57 @@ }); } + // Web installer: after a finished install, once its dialog closes, show the + // next step and a quiet tip line (the line at most once a month per browser). + // ESP Web Tools 10.4.0 has no completion event; its dialog element keeps the + // install progress in _installState, read here without changing it. + var done = document.getElementById('flasher-done'); + if (done && 'MutationObserver' in window) { + var showDone = function () { + var tip = done.querySelector('.flasher-tip'), now = Date.now(), last = 0; + try { last = Number(localStorage.getItem('rg-tip-shown')) || 0; } catch (e) { last = 0; } + if (tip) tip.hidden = now - last < 30 * 24 * 3600 * 1000; + if (tip && !tip.hidden) { try { localStorage.setItem('rg-tip-shown', String(now)); } catch (e) { /* private mode */ } } + done.hidden = false; + done.scrollIntoView({ block: 'nearest' }); + }; + done.querySelector('.flasher-done-close').addEventListener('click', function () { done.hidden = true; }); + var watchDialog = function (dialog) { + var finished = false; + var timer = setInterval(function () { + var state = dialog._installState; + if (state && state.state === 'finished') finished = true; + }, 500); + dialog.addEventListener('closed', function () { clearInterval(timer); if (finished) showDone(); }, { once: true }); + }; + new MutationObserver(function (changes) { + changes.forEach(function (change) { + change.addedNodes.forEach(function (node) { if (node.nodeName === 'EWT-INSTALL-DIALOG') watchDialog(node); }); + }); + }).observe(document.body, { childList: true }); + } + var menu = document.querySelector('.menu'), nav = document.getElementById('site-nav'); - if (menu && nav) menu.addEventListener('click', function () { - var open = nav.classList.toggle('open'); - menu.setAttribute('aria-expanded', open ? 'true' : 'false'); - }); + if (menu && nav) { + var openedAt = 0; + var setMenu = function (open) { + nav.classList.toggle('open', open); + menu.setAttribute('aria-expanded', open ? 'true' : 'false'); + openedAt = window.scrollY; + }; + menu.addEventListener('click', function () { setMenu(!nav.classList.contains('open')); }); + // The open menu must not stay over the page: close it when the page + // scrolls, on a tap outside the header or with Escape. + window.addEventListener('scroll', function () { + if (nav.classList.contains('open') && Math.abs(window.scrollY - openedAt) > 40) setMenu(false); + }, { passive: true }); + document.addEventListener('click', function (e) { + if (nav.classList.contains('open') && !e.target.closest('.top')) setMenu(false); + }); + document.addEventListener('keydown', function (e) { + if (e.key === 'Escape' && nav.classList.contains('open')) { setMenu(false); menu.focus(); } + }); + } var theme = document.querySelector('.theme'); if (theme) theme.addEventListener('click', function () {