Skip to content

feat(server): badge the live task queue from the SSE stream - #102

Merged
dyphire merged 2 commits into
mainfrom
fix/task-queue-live-badge
Nov 28, 2026
Merged

dyphire merged 2 commits into
mainfrom
fix/task-queue-live-badge

Conversation

@dyphire

@dyphire dyphire commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Why

The server announces its task queue on the SSE stream: TaskQueueStatus carries the queued total plus a per-type split, and the first frame of every connection is that snapshot. iOS keeps it in AppConfig.taskQueueStatus and badges three surfaces with it (settings server row, server page's Server Info tile, Server Info page's Tasks row).

Android received the frame and threw it away — SseService counted it as the stream's keep-alive, SseChangeParser dropped every Task* name, and no screen listened. The only queue number the app ever had was the one ServerAdminViewModel.loadTasks fetched from /stats/server, once, after the user had already opened Server → Tasks. A scan started from the web UI stayed invisible until then, and on stock Komga the per-type list stayed empty because the stats endpoint there carries no queued.

What changed

  • TaskQueueStore (new, core/sse): holds the last announcement — count, countByType, updatedAt.
  • SseChangeParser.parseTaskQueue: decodes the frame (count / countByType, unknown keys ignored, missing fields default). It does not go through parse(), because it is the whole queue and not a content delta — no row can be patched from it.
  • SseContentSync: routes the frame to the store instead of the change bus. It is also the first frame of every connection, so a reconnect refills the badge without an extra request.
  • SseService.stop(): clears the store, mirroring iOS's disconnect — the count belongs to that stream, and another instance must not inherit it.

Why updatedAt

It separates "the server says zero tasks" from "nothing has been announced yet". Without it, a screen can only paint a zero it has no evidence for — SSE disabled, a non-admin session, or an older server all look identical to an idle server. With it, those fall back to the value the page fetched.

Surfaces

  • Settings → 服务器 row: the live queue count, drawn as iOS draws it — an 8 dp dot in the value's tone, 4 pt before the count, count semibold (SettingsBadgeRow: Circle + caption/semibold). SettingsRow gained valueDot, SettingsValueText draws the dot, and SettingsComponents keeps a navigating row's chevron beside a value (iOS draws the badge before the disclosure indicator). Without the dot the count read as a static setting, indistinguishable from the server address in the same slot.
  • Server page → 任务 row badge: now live instead of whatever the last /stats/server fetch said.
  • Tasks page: total and per-type rows prefer the snapshot. This also fixes the per-type list being empty on stock Komga, where the stats endpoint has no queued but countByType does.

Verification

  • :app:compileDebugKotlin, :app:testDebugUnitTest, :app:lintDebug (exit 0, no new findings) pass.
  • New TaskQueueTest (5 cases): payload mapping, empty queue, unknown/missing keys, unreadable payload discarded rather than guessed, store update/filter/clear semantics.

The server announces its task queue on the event stream: `TaskQueueStatus`
carries the queued total and the per-type split, and the first frame of every
connection is that snapshot. iOS keeps it in `AppConfig.taskQueueStatus` and
badges three surfaces with it (the settings server row, the server page's
Server Info tile, the Server Info page's Tasks row).

Android received the frame and threw it away. `SseService` counted it as the
stream's keep-alive, `SseChangeParser` dropped every `Task*` name, and nothing
listened for it, so the only queue number the app ever had was the one
`ServerAdminViewModel.loadTasks` fetched from `/stats/server` — once, after the
user had already opened Server → Tasks. A scan started from the web UI was
invisible until then, and on stock Komga the per-type list stayed empty because
the stats endpoint there carries no `queued`.

`TaskQueueStore` now holds the announcement (count, per-type counts, and the
time it arrived), `SseChangeParser.parseTaskQueue` decodes it, and
`SseContentSync` routes it to the store instead of the change bus — it is the
whole queue, not a content delta, so no row can be patched from it. The store is
cleared wherever the socket stops, mirroring iOS's `disconnect`: the count
belongs to that stream, and the next connection re-announces it.

The `updatedAt` field is what keeps the UI honest: it separates "the server says
zero" from "nothing has been announced yet", so a screen falls back to the
fetched value (SSE off, non-admin session, an older server) instead of painting
a zero it has no evidence for. Both the settings server row and the server
page's 任务 row now read the live count, and the Tasks page prefers the
snapshot — the same queue, but it moves on its own.
The settings hub showed the live queue as a bare trailing number. Against the
other rows that read as a static fact — the server address, the account name all
sit in the same slot — so a moving count was indistinguishable from a setting
that simply happens to be a number.

iOS has the same row in `SettingsBadgeRow`: an 8 pt `Circle` in the badge color
(`.secondary` at the call site) followed by the count in `caption` semibold, with
4 pt of air between them. The dot is what makes the value read as a live badge
and not a value. `SettingsRow` gains `valueDot`, `SettingsValueText` draws the dot
and weights the label semibold when it is set, and only the server row passes it
— every other `value` row keeps its regular-weight text.
@dyphire
dyphire force-pushed the fix/task-queue-live-badge branch from 7e555fc to bf9f6aa Compare November 28, 2026 18:28
@dyphire
dyphire merged commit 3749bd6 into main Nov 28, 2026
1 check passed
@dyphire
dyphire deleted the fix/task-queue-live-badge branch November 28, 2026 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant