Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/lib/tray-primary-progress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,5 +302,46 @@ describe("getTrayPrimaryBars", () => {
})
expect(bars).toEqual([])
})

it("falls back to the first progress line when no declared candidate is present", () => {
// Usage-based Codex plans report only "Credits", never the declared "Session"
// candidate. Without a fallback the tray renders "--%" instead of a real number.
const bars = getTrayPrimaryBars({
pluginsMeta: [
{
id: "codex",
name: "Codex",
iconUrl: "",
primaryCandidates: ["Session"],
lines: [],
},
],
pluginSettings: { order: ["codex"], disabled: [] },
pluginStates: {
codex: {
data: {
providerId: "codex",
displayName: "Codex",
iconUrl: "",
lines: [
{
type: "progress",
label: "Credits",
used: 1000,
limit: 1000,
format: { kind: "count", suffix: "credits" },
},
],
},
loading: false,
error: null,
},
},
displayMode: "left",
})

// 1000 of 1000 used, "left" mode -> 0 remaining -> 0%, not undefined
expect(bars).toEqual([{ id: "codex", fraction: 0 }])
})
})

27 changes: 15 additions & 12 deletions src/lib/tray-primary-progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,21 @@ export function getTrayPrimaryBars(args: {
const primaryLabel = meta.primaryCandidates.find((label) =>
data.lines.some((line) => isProgressLine(line) && line.label === label)
)
if (primaryLabel) {
const primaryLine = data.lines.find(
(line): line is ProgressLine =>
isProgressLine(line) && line.label === primaryLabel
)
if (primaryLine && primaryLine.limit > 0) {
const shownAmount =
displayMode === "used"
? primaryLine.used
: primaryLine.limit - primaryLine.used
fraction = clamp01(shownAmount / primaryLine.limit)
}
// Some plans expose none of the declared candidates (usage-based Codex reports only
// "Credits", never "Session"). Fall back to the first progress line so the tray shows
// a real number instead of "--%".
const primaryLine = primaryLabel
? data.lines.find(
(line): line is ProgressLine =>
isProgressLine(line) && line.label === primaryLabel
)
: data.lines.find((line): line is ProgressLine => isProgressLine(line))
if (primaryLine && primaryLine.limit > 0) {
const shownAmount =
displayMode === "used"
? primaryLine.used
: primaryLine.limit - primaryLine.used
fraction = clamp01(shownAmount / primaryLine.limit)
}
}

Expand Down
Loading