From fca7e71908838827518c806110c9371e50eab19c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 11 Oct 2026 13:22:55 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=95=20Sync=202026-10-11=2013:22:55?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- luci-app-honk/Makefile | 2 +- .../www/luci-static/resources/honk/common.js | 55 ++++++++++--------- .../resources/view/honk/dashboard.js | 7 +-- .../luci-static/resources/view/honk/global.js | 10 +--- .../luci-static/resources/view/honk/log.js | 14 ++--- 5 files changed, 39 insertions(+), 49 deletions(-) diff --git a/luci-app-honk/Makefile b/luci-app-honk/Makefile index 51f44fd42..5c163fa23 100644 --- a/luci-app-honk/Makefile +++ b/luci-app-honk/Makefile @@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-honk PKG_VERSION:=1.1.4 -PKG_RELEASE:=20 +PKG_RELEASE:=21 LUCI_TITLE:=LuCI support for honk LUCI_PKGARCH:=all diff --git a/luci-app-honk/root/www/luci-static/resources/honk/common.js b/luci-app-honk/root/www/luci-static/resources/honk/common.js index 94e13c538..014686d66 100644 --- a/luci-app-honk/root/www/luci-static/resources/honk/common.js +++ b/luci-app-honk/root/www/luci-static/resources/honk/common.js @@ -111,6 +111,32 @@ function updateStatus(data, targetEl) { } } +// Register a poll function operating on `el` and unregister it once `el` is gone. +// poll.add() runs the first tick synchronously when it starts the polling loop, which +// normally happens while the view is still being rendered, i.e. before `el` has been +// attached to the document. Tolerate that single early tick and only give up on the +// element once it is still missing on a later tick. +function addElementPoll(fn, el, interval, onDetach) { + var missing = 0; + + var pollFn = function() { + if (document.body.contains(el)) { + missing = 0; + } else if (++missing > 1) { + poll.remove(pollFn); + if (typeof onDetach === 'function') + onDetach(); + return Promise.resolve(); + } + + return fn(); + }; + + poll.add(pollFn, interval); + + return pollFn; +} + function waitForHonkState(wantRunning, attempts) { attempts = attempts || 10; @@ -125,7 +151,7 @@ function waitForHonkState(wantRunning, attempts) { updateStatus(st); if (poll && typeof(poll.start) === 'function') poll.start(); - resolve({ running: running, memory: st ? st.memory : null }); + resolve({ running: running }); } else { setTimeout(step, 1200); } @@ -162,25 +188,6 @@ function switchDashboardAndWait(type) { }); } -function applyChangesAndWait(mode) { - return new Promise(function(resolve) { - var timer = null; - var onApplied = function() { - if (timer) clearTimeout(timer); - document.removeEventListener('uci-applied', onApplied); - resolve(); - }; - - var holdoff = (window.L && L.env && +L.env.apply_holdoff) || 4; - var timeout = (window.L && L.env && +L.env.apply_timeout) || 5; - timer = setTimeout(onApplied, (holdoff + timeout) * 1000); - - document.addEventListener('uci-applied', onApplied); - - ui.changes.apply(mode == '0'); - }); -} - var DOWNLOAD_MAX_TICKS = 900; var DOWNLOAD_STALE_TICKS = 90; var activeDownloadCancel = null; @@ -800,16 +807,12 @@ function renderStatusHeader() { }); var pollStatusFn = function() { - if (!document.body.contains(statusEl)) { - poll.remove(pollStatusFn); - return Promise.resolve(); - } return callHonkStatus().then(function(st) { updateStatus(st, statusEl); }).catch(function() { }); }; - poll.add(pollStatusFn, 5); + addElementPoll(pollStatusFn, statusEl, 5); applyTabVisibility(); @@ -844,5 +847,5 @@ return baseclass.extend({ isServiceEnabled: isServiceEnabled, showNotification: showNotification, updateStatus: updateStatus, - applyChangesAndWait: applyChangesAndWait + addElementPoll: addElementPoll }); diff --git a/luci-app-honk/root/www/luci-static/resources/view/honk/dashboard.js b/luci-app-honk/root/www/luci-static/resources/view/honk/dashboard.js index f964d5949..95240a443 100644 --- a/luci-app-honk/root/www/luci-static/resources/view/honk/dashboard.js +++ b/luci-app-honk/root/www/luci-static/resources/view/honk/dashboard.js @@ -1,7 +1,6 @@ 'use strict'; 'require view'; 'require ui'; -'require poll'; 'require uci'; 'require honk.common as honk'; 'require honk.dashprofiles as dash'; @@ -574,10 +573,6 @@ return view.extend({ loadInfo(); var dashStatusPollFn = function() { - if (!document.body.contains(iframe)) { - poll.remove(dashStatusPollFn); - return Promise.resolve(); - } if (document.hidden) { return Promise.resolve(); } @@ -590,7 +585,7 @@ return view.extend({ return Promise.resolve(); }; - poll.add(dashStatusPollFn, 5); + honk.addElementPoll(dashStatusPollFn, iframe, 5); return E('div', { 'class': 'dash-wrap' }, [ style, diff --git a/luci-app-honk/root/www/luci-static/resources/view/honk/global.js b/luci-app-honk/root/www/luci-static/resources/view/honk/global.js index 7539755fb..d907184cf 100644 --- a/luci-app-honk/root/www/luci-static/resources/view/honk/global.js +++ b/luci-app-honk/root/www/luci-static/resources/view/honk/global.js @@ -62,7 +62,6 @@ return view.extend({ return this.handleSave(ev).then(function() { var newDash = uci.get('honk', sid, 'dashboard') || 'none'; - var enabled = honk.isServiceEnabled(); var pre = (newDash !== oldDash) ? honk.switchDashboardAndWait(newDash).then(function(res) { if (res && res.pending) @@ -71,13 +70,10 @@ return view.extend({ throw new Error(_('HONK did not come back up; check the logs')); }) : Promise.resolve(); + // LuCI reloads the page right after applying, and the status header then + // polls the real service state on its own (see honk.addElementPoll). return pre.then(function() { - return honk.applyChangesAndWait(mode); - }).then(function() { - return honk.waitForHonkState(enabled); - }).then(function(st) { - if (enabled && st && st.running === false) - throw new Error(_('HONK did not come back up; check the logs')); + ui.changes.apply(mode == '0'); }); }).catch(function(err) { honk.showNotification(null, E('p', _('Failed to apply configuration:') + ' ' + (err.message || err)), 'error'); diff --git a/luci-app-honk/root/www/luci-static/resources/view/honk/log.js b/luci-app-honk/root/www/luci-static/resources/view/honk/log.js index 593a7c8b6..7f1af5358 100644 --- a/luci-app-honk/root/www/luci-static/resources/view/honk/log.js +++ b/luci-app-honk/root/www/luci-static/resources/view/honk/log.js @@ -2,7 +2,6 @@ 'require view'; 'require ui'; 'require uci'; -'require poll'; 'require honk.common as honk'; return view.extend({ @@ -65,20 +64,17 @@ return view.extend({ var onVisibilityChange; var logPollFn = function() { - if (!document.body.contains(logTextarea)) { - poll.remove(logPollFn); - if (onVisibilityChange) { - document.removeEventListener('visibilitychange', onVisibilityChange); - } - return Promise.resolve(); - } if (document.hidden) { return Promise.resolve(); } return updateLog().catch(function() { }); }; - poll.add(logPollFn, 3); + honk.addElementPoll(logPollFn, logTextarea, 3, function() { + if (onVisibilityChange) { + document.removeEventListener('visibilitychange', onVisibilityChange); + } + }); onVisibilityChange = function() { if (!document.body.contains(logTextarea)) {