gui: Settings asks for HTTPS only while its rows can show (#6709)

renderHTTPS sent GET /api/settings/https on every renderSettings,
and renderSettings has 35 callers, so each Settings draw cost a
request, LAN or not. GUI tests count a request under /api/settings/
as a write, so checkin-now-account and panel-shortcut have been red
in both engines and every language since 4623f5419 (11-10): that
commit's record ran chosen GUI files and called the reds the same at
base. Now it asks while the rows can show (sharing on the local
network, magpie answering other computers, or HTTPS saved on), and
again once the saved switch differs from what the last answer said.
Its own writes still update the rows from their answers.

Run (origin/main 139a6be2b plus this, GUI files on mote; at the pushed
head, rebased on 261f48226, checkin-now-account + panel-shortcut +
https-settings: pass 54 fail 0):
- checkin-now-account + panel-shortcut: pass 42 fail 0. Without the
  change: pass 2 fail 40 ('write', '/api/settings/https' counted).
- https-settings, browser-access, cors-origins, side-gateway-lan,
  settings-search, i18n-keys: all pass. allow-ips, lan-join and
  remote-magpie: 14 reds, the same 14 subtests without the change
  (on #6709's list).
- go test -tags nogui -run 'Budget|Size|Asset|Plugin.*Page'
  ./internal/gui: ok.

Not changed: renderWebPage and renderRemote ask /api/web-page and
/api/remote on every draw the same way. They aren't under
/api/settings/, so no test counts them; filed as their own issue.
Not tried: the real app's Settings with LAN on (the GUI fixtures
cover the rows).
This commit is contained in:
yetone
2026-11-16 00:09:14 +08:00
parent 261f482260
commit 47ce008da8
@@ -417,7 +417,10 @@ function httpsSays(m) {
function renderHTTPS(s, asked) {
const box = $("#httpsList");
if (!box) return;
if (!asked) api("settings/https").then((h) => { httpsState = h; renderHTTPS(prefs, true); }).catch(() => {});
// asked while the rows can show, and again once the saved switch moves
// from what it said: every Settings draw asking cost a request a draw,
// and a page's write counts read it as a write (#6709)
if (!asked && s && (s.lan || s.onNetwork || s.https) && (!httpsState || !httpsState.on !== !s.https)) api("settings/https").then((h) => { httpsState = h; renderHTTPS(prefs, true); }).catch(() => {});
const h = httpsState;
if (!s || !h || (!s.lan && !s.onNetwork && !h.on)) return void box.replaceChildren();
const post = (what, body) => writingPrefs(api("settings/https" + what, body))