ui: auto-refresh the proactive log and STK menu state
The proactive command list only re-rendered on tab/pill switches, so new fetched commands (background STATUS polling, menu traffic) stayed invisible while the Phone view was open. - /api/status now exposes proactive_seq (_PROACTIVE_ENTRY_ID, monotonic and not reset with the log), so the existing 2s status poll detects changes with no extra request; pysimCardStateUpdate() re-renders the log when the sequence changed and the Phone/Phone view is visible - the 5s backend timer no longer fetches the log (it was discarded) and now uses the already-fetched stk-status: when active/pending changes while the Phone tab is visible, stkCheckMenu() refreshes the menu button without a tab switch - pysimProactiveLogRender() keeps its scroll position and only shows Loading... on a first/empty paint - tests: proactive seq + STK signature helpers and poll-driven render behaviour in card_state.test.js; SW cache v123 -> v124.
This commit is contained in:
+27
-3
@@ -6713,6 +6713,10 @@ function pysimCardStateUpdate(status) {
|
||||
_pysimCardEquipped = !!status.connected;
|
||||
_pysimEquipping = !!status.equipping;
|
||||
pysimApplyAvailability();
|
||||
if (pysimProactiveSeqChanged(status.proactive_seq)
|
||||
&& isViewVisible('tab-phone') && isViewVisible('phone-sub-phone')) {
|
||||
pysimProactiveLogRender();
|
||||
}
|
||||
const key = [status.connected, !!status.card_present, !!status.equipping, !!status.auto_equip, status.card_session].join('|');
|
||||
if (key === _pysimCardStateKey) return;
|
||||
_pysimCardStateKey = key;
|
||||
@@ -6752,17 +6756,35 @@ function pysimStartBackendPoll() {
|
||||
}, 2000);
|
||||
_pysimPollTimer = setInterval(async () => {
|
||||
try {
|
||||
const [log, stk, ps] = await Promise.all([
|
||||
pysimFetch('/api/proactive-log'),
|
||||
const [stk, ps] = await Promise.all([
|
||||
pysimFetch('/api/stk-status'),
|
||||
pysimFetch('/api/poll-status'),
|
||||
]);
|
||||
pysimUpdatePollUI(ps.enabled, ps.interval);
|
||||
if (pysimStkStatusChanged(stk) && isViewVisible('tab-phone')) stkCheckMenu();
|
||||
} catch (e) { /* ignore */ }
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
let _pysimStkSig = null;
|
||||
|
||||
function pysimStkStatusChanged(stk) {
|
||||
if (!stk) return false;
|
||||
const sig = [!!stk.active, !!stk.pending, stk.pending_type || ''].join('|');
|
||||
if (sig === _pysimStkSig) return false;
|
||||
_pysimStkSig = sig;
|
||||
return true;
|
||||
}
|
||||
|
||||
// ===== proactive command log =====
|
||||
let _pysimProactiveSeq = null;
|
||||
|
||||
function pysimProactiveSeqChanged(seq) {
|
||||
if (seq === undefined || seq === null) return false;
|
||||
if (_pysimProactiveSeq === seq) return false;
|
||||
_pysimProactiveSeq = seq;
|
||||
return true;
|
||||
}
|
||||
const CMD_NAMES = {
|
||||
'03': 'POLL INTERVAL', '05': 'SET UP EVENT LIST',
|
||||
'13': 'SEND SHORT MESSAGE', '20': 'PLAY TONE',
|
||||
@@ -6818,7 +6840,8 @@ function pysimLogFields(decoded) {
|
||||
|
||||
async function pysimProactiveLogRender() {
|
||||
const el = document.getElementById('pysim-proactive-log');
|
||||
el.innerHTML = '<span class="text-gray-400">' + t('Loading...') + '</span>';
|
||||
const scrollTop = el.scrollTop;
|
||||
if (!el.firstChild) el.innerHTML = '<span class="text-gray-400">' + t('Loading...') + '</span>';
|
||||
try {
|
||||
const log = await pysimFetch('/api/proactive-log');
|
||||
if (!log || !log.length) {
|
||||
@@ -6865,6 +6888,7 @@ async function pysimProactiveLogRender() {
|
||||
html += '</div></div>';
|
||||
});
|
||||
el.innerHTML = html;
|
||||
el.scrollTop = scrollTop;
|
||||
} catch (err) {
|
||||
el.innerHTML = '<span class="text-red-500">Error: ' + esc(err.message) + '</span>';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user