fix: 推送按序号只保留最新一帧,倒计时改用剩余秒数

This commit is contained in:
2026-11-16 09:38:07 +08:00
parent f20cf79e57
commit 556121a265
6 changed files with 57 additions and 30 deletions
+16 -1
View File
@@ -23,6 +23,8 @@ interface StudyWorker {
progress: number;
interval: number;
heartbeat_at: number;
heartbeat_in: number;
seen_at: number;
sent: number;
total: number;
ok: boolean;
@@ -184,6 +186,8 @@ function asWorkers(value: unknown): StudyWorker[] {
progress: typeof row.progress === "number" ? row.progress : 0,
interval: typeof row.interval === "number" ? row.interval : 0,
heartbeat_at: typeof row.heartbeat_at === "number" ? row.heartbeat_at : 0,
heartbeat_in: typeof row.heartbeat_in === "number" ? row.heartbeat_in : 0,
seen_at: Date.now(),
sent: typeof row.sent === "number" ? row.sent : 0,
total: typeof row.total === "number" ? row.total : 0,
ok: row.ok !== false,
@@ -209,7 +213,7 @@ function workerTitle(row: StudyWorker) {
}
function showHeartbeat(row: StudyWorker) {
return row.interval > 0 && row.heartbeat_at > 0;
return row.heartbeat_in > 0 || (row.interval > 0 && row.heartbeat_at > 0);
}
function workerCount(row: StudyWorker) {
@@ -220,6 +224,12 @@ function workerCount(row: StudyWorker) {
function heartbeatLeft(row: StudyWorker) {
void nowTick.value;
if (row.heartbeat_in > 0) {
const elapsed = (Date.now() - row.seen_at) / 1000;
const cap = row.interval > 0 ? row.interval : row.heartbeat_in;
const left = Math.max(0, Math.min(cap, row.heartbeat_in - elapsed));
return `${Math.ceil(left)}s`;
}
const now = Date.now() / 1000;
const cycle = Math.max(0, row.interval);
let left = row.heartbeat_at - now;
@@ -500,7 +510,12 @@ async function saveProxy() {
}
}
let lastStudySeq = 0;
function applyStudyControl(payload: Record<string, unknown>) {
const seq = typeof payload.seq === "number" ? payload.seq : 0;
if (seq > 0 && seq < lastStudySeq) return;
if (seq > 0) lastStudySeq = seq;
studyControl.value = {
started: payload.started === true,
paused: payload.paused === true,