Skip to content

Commit c2f7728

Browse files
yyq1025claude
andcommitted
menubar: relative reset countdown — "resets 42m / 7h / 3d"
Replaces the two-format split (H:MM countdown for 5h, calendar date for weekly) with one coarse single-unit formatter for both rows. Ceil at every tier so the label never understates the wait. No date library — it's one subtraction and two divisions. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 2f6972e commit c2f7728

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

packages/menubar/electron/main.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,17 @@ function formatPercent(util: number): string {
5959
return `${Math.round(util)}%`;
6060
}
6161

62-
function formatCountdown(resetsAt: string): string {
62+
// Coarse single-unit countdown: "resets 42m" / "resets 7h" / "resets 3d".
63+
// Ceil everywhere so the label never understates the wait ("resets 0m"
64+
// while 30s remain would read as a bug).
65+
function formatResets(resetsAt: string): string {
6366
const ms = new Date(resetsAt).getTime() - Date.now();
64-
if (ms <= 0) return "0:00";
65-
const totalMin = Math.floor(ms / 60000);
66-
const h = Math.floor(totalMin / 60);
67-
const m = totalMin % 60;
68-
return `${h}:${m.toString().padStart(2, "0")}`;
69-
}
70-
71-
function formatResetDate(resetsAt: string): string {
72-
const d = new Date(resetsAt);
73-
return `${d.getMonth() + 1}${d.getDate()}日`;
67+
if (ms <= 0) return "resets now";
68+
const min = Math.ceil(ms / 60_000);
69+
if (min < 60) return `resets ${min}m`;
70+
const hours = Math.ceil(min / 60);
71+
if (hours < 24) return `resets ${hours}h`;
72+
return `resets ${Math.ceil(hours / 24)}d`;
7473
}
7574

7675
// SF Symbol → 16x16 template image (auto-tints to follow menu fg color,
@@ -126,19 +125,19 @@ function planUsageItems(): Electron.MenuItemConstructorOptions[] {
126125
const row = (
127126
name: string,
128127
w: PlanUsageWindow | undefined,
129-
reset?: (resetsAt: string) => string,
128+
showReset = false,
130129
): Electron.MenuItemConstructorOptions | null =>
131130
w
132131
? {
133132
label: `${name} - ${formatPercent(w.utilization)}${
134-
reset && w.resetsAt ? ` · ${reset(w.resetsAt)}` : ""
133+
showReset && w.resetsAt ? ` · ${formatResets(w.resetsAt)}` : ""
135134
}`,
136135
enabled: false,
137136
}
138137
: null;
139138
const rows = [
140-
row("5h", u.fiveHour, formatCountdown),
141-
row("Weekly", u.sevenDay, formatResetDate),
139+
row("5h", u.fiveHour, true),
140+
row("Weekly", u.sevenDay, true),
142141
row("Opus", u.sevenDayOpus),
143142
row("Sonnet", u.sevenDaySonnet),
144143
].filter((r) => r !== null);

0 commit comments

Comments
 (0)