A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io
Rust ai-toolsclaude-codecodexdeepseek-harnessdesktop-appgrokgrokbuildhermeskimi-codemcpopen-sourceopencodepiprovider-managementrustskillsskills-managementtauriwsl-support
fix(tray-panel): unify compact quota layout and align progress bars (#10036)
Allen Xu9efcac594a0f
diff --git a/src-tauri/src/tray.rs b/src-tauri/src/tray.rsindex f063b5697..9376e3777 100644--- a/src-tauri/src/tray.rs+++ b/src-tauri/src/tray.rs@@ -810,6 +810,27 @@ fn tier_label(texts: &TrayTexts, group: TierGroup, tier_name: &str) -> &'static}}+/// 托盘面板专用的紧凑短档名:去重中文宽字符、让各应用与子账号的进度条垂直对齐。+fn tier_short_label(texts: &TrayTexts, group: TierGroup, tier_name: &str) -> &'static str {+ match group {+ TierGroup::FiveHour => "5h",+ TierGroup::Weekly => "7d",+ TierGroup::Fable => "Fable",+ TierGroup::Monthly if tier_name == crate::services::subscription::TIER_THIRTY_DAY => "30d",+ TierGroup::Monthly => "Mo",+ TierGroup::KimiMonthlyTotal => "Mo total",+ TierGroup::KimiMonthlyCode => "Mo code",+ TierGroup::Credits => texts.tier_credits,+ TierGroup::GeminiPro => "Pro",+ TierGroup::GeminiFlash => "Flash",+ TierGroup::GeminiFlashLite => "Lite",+ TierGroup::Premium => "Credits",+ TierGroup::AgyGemini => "Gemini",+ TierGroup::AgyThirdParty => "Claude",+ TierGroup::AgyArgon => "Argon",+ }+}+#[derive(Debug, Clone, PartialEq)]struct QuotaLine {text: String,@@ -817,6 +838,8 @@ struct QuotaLine {left: f64,/// 档名(重置说明用;余额等没有档名)。label: Option<&'static str>,+ /// 托盘面板用的紧凑短档名(`5h`、`7d`、`30d`、`Gemini`、`Claude` 等)。+ short_label: Option<&'static str>,resets_at: Option<String>,/// 要上色的那段数值(还有余额时的金额,照卡片 `balanceLine` 的 `emphasis`);其余为空。emphasis: Option<String>,@@ -846,6 +869,7 @@ struct TierEntry<'a> {fn tier_line(texts: &TrayTexts,label: &'static str,+ short_label: &'static str,utilization: f64,resets_at: Option<String>,) -> QuotaLine {@@ -863,6 +887,7 @@ fn tier_line(text,left,label: Some(label),+ short_label: Some(short_label),resets_at,emphasis: None,}@@ -884,6 +909,7 @@ fn grouped_tier_lines(texts: &TrayTexts, entries: &[TierEntry<'_>]) -> Vec<Quotalines.push(tier_line(texts,tier_label(texts, group, entry.name),+ tier_short_label(texts, group, entry.name),entry.utilization,entry.resets_at.clone(),));@@ -964,6 +990,7 @@ fn plan_line(texts: &TrayTexts, data: &crate::provider::UsageData) -> Option<Quotext: texts.plan_expired.to_string(),left: -1.0,label: None,+ short_label: None,resets_at: None,emphasis: None,});@@ -979,7 +1006,13 @@ fn plan_line(texts: &TrayTexts, data: &crate::provider::UsageData) -> Option<Quoreturn None;}let utilization = (total - remaining) / total * 100.0;- return Some(tier_line(texts, texts.tier_premium, utilization, None));+ return Some(tier_line(+ texts,+ texts.tier_premium,+ tier_short_label(texts, TierGroup::Premium, ""),+ utilization,+ None,+ ));}if let Some(remaining) = data.remaining {// 余额不提示「快用完」,只有用完才算(和卡片 `quotaRules.balanceLine` 一致);@@ -992,6 +1025,7 @@ fn plan_line(texts: &TrayTexts, data: &crate::provider::UsageData) -> Option<Quotext,left,label: None,+ short_label: None,resets_at: None,emphasis,});@@ -1000,6 +1034,7 @@ fn plan_line(texts: &TrayTexts, data: &crate::provider::UsageData) -> Option<Quotext: fill(texts.used_amount, &[("value", &amount(used, unit))]),left: f64::INFINITY,label: None,+ short_label: None,resets_at: None,emphasis: None,})@@ -2584,12 +2619,18 @@ pub struct PanelQuota {pub note: Option<String>,/// ChatGPT 订阅(Codex)可用的额度重置次数;没有这项数据时为空。pub reset_credits: Option<usize>,+ /// 百分比是否按「已用」展示(同设置 `quota_shows_used`)。+ #[serde(default, skip_serializing_if = "std::ops::Not::not")]+ pub shows_used: bool,}#[derive(Debug, Clone, Serialize)]#[serde(rename_all = "camelCase")]pub struct PanelQuotaLine {pub text: String,+ /// 托盘面板专用的紧凑短档名(如 `5h`、`7d`、`30d`、`Gemini`、`Claude`)。+ #[serde(skip_serializing_if = "Option::is_none")]+ pub short_label: Option<String>,/// 剩余百分比(0–100);余额这种没有总额的为空,不画进度条。pub left: Option<f64>,pub warn: bool,@@ -2633,6 +2674,7 @@ fn panel_quota(.iter().map(|line| PanelQuotaLine {text: line.text.clone(),+ short_label: line.short_label.map(str::to_string),left: line.left.is_finite().then(|| line.left.clamp(0.0, 100.0)),warn: line.left < WARN_BELOW_PERCENT,resets_at: line.resets_at.clone(),@@ -2641,11 +2683,13 @@ fn panel_quota(.collect(),note: None,reset_credits,+ shows_used: texts.quota_used,},QuotaView::Failed(_) => PanelQuota {lines: Vec::new(),note: quota_note(texts, view, now),reset_credits: None,+ shows_used: texts.quota_used,},}}diff --git a/src-tauri/src/tray/tests.rs b/src-tauri/src/tray/tests.rsindex 79dd3ccd9..595bc6492 100644--- a/src-tauri/src/tray/tests.rs+++ b/src-tauri/src/tray/tests.rs@@ -2051,6 +2051,7 @@ fn service_down_shows_the_problem_row_and_needs_attention_instead_of_quota() {desktop.quota = Some(QuotaView::Lines(vec![tier_line(&zh(),zh().tier_weekly,+ "7d",20.0,None,)]));@@ -2706,3 +2707,132 @@ fn indicator_update_skips_initial_default_tooltip_and_tracks_problem_transitions(true, false));}++#[test]+fn panel_quota_emits_short_labels_and_distinguishes_monthly_and_kimi_tiers() {+ use crate::services::subscription as s;+ use crate::services::subscription_agy as agy;++ let now = chrono::Local::now();++ let monthly_quota = make_quota(+ "test",+ true,+ vec![+ tier(s::TIER_FIVE_HOUR, 10.0),+ tier(s::TIER_WEEKLY_LIMIT, 20.0),+ tier(s::TIER_MONTHLY, 30.0),+ tier(s::TIER_KIMI_MONTHLY_TOTAL, 40.0),+ tier(s::TIER_KIMI_MONTHLY_CODE, 50.0),+ tier(s::TIER_CREDITS, 60.0),+ ],+ );++ let en_view = format_subscription_quota(&en(), &monthly_quota).expect("en lines");+ let en_panel = panel_quota(&en(), &en_view, now, Some(2));+ let en_labels: Vec<_> = en_panel+ .lines+ .iter()+ .map(|line| line.short_label.as_deref())+ .collect();+ assert_eq!(+ en_labels,+ vec![+ Some("5h"),+ Some("7d"),+ Some("Mo"),+ Some("Mo total"),+ Some("Mo code"),+ Some("Credits"),+ ]+ );+ assert_eq!(en_panel.reset_credits, Some(2));+ assert!(!en_panel.shows_used);++ // 滚动 30 天窗口与自然月区分+ let thirty_day_quota = make_quota("codex", true, vec![tier(s::TIER_THIRTY_DAY, 25.0)]);+ let thirty_en = panel_quota(+ &en(),+ &format_subscription_quota(&en(), &thirty_day_quota).expect("30d en"),+ now,+ None,+ );+ assert_eq!(thirty_en.lines[0].short_label.as_deref(), Some("30d"));++ // Antigravity & Gemini 模型短名+ let model_quota = make_quota(+ "agy",+ true,+ vec![+ tier(s::TIER_GEMINI_PRO, 10.0),+ tier(s::TIER_GEMINI_FLASH, 20.0),+ tier(s::TIER_GEMINI_FLASH_LITE, 30.0),+ tier(agy::TIER_AGY_GEMINI_FIVE_HOUR, 15.0),+ tier(agy::TIER_AGY_THIRD_PARTY_FIVE_HOUR, 25.0),+ tier(agy::TIER_AGY_GEMINI_ARGON_WEEKLY, 35.0),+ ],+ );+ let model_panel = panel_quota(+ &zh(),+ &format_subscription_quota(&zh(), &model_quota).expect("models"),+ now,+ None,+ );+ let model_labels: Vec<_> = model_panel+ .lines+ .iter()+ .map(|line| line.short_label.as_deref())+ .collect();+ assert_eq!(+ model_labels,+ vec![+ Some("Pro"),+ Some("Flash"),+ Some("Lite"),+ Some("Gemini"),+ Some("Claude"),+ Some("Argon"),+ ]+ );++ // 余额行没有 short_label+ let balance = plan_line(+ &zh(),+ &crate::provider::UsageData {+ plan_name: None,+ extra: None,+ is_valid: None,+ invalid_message: None,+ total: None,+ used: None,+ remaining: Some(4.2),+ unit: Some("CNY".to_string()),+ },+ )+ .expect("balance");+ let balance_panel = panel_quota(&zh(), &QuotaView::Lines(vec![balance]), now, None);+ assert_eq!(balance_panel.lines[0].short_label, None);+}++#[test]+fn panel_quota_serializes_shows_used_only_when_enabled() {+ use crate::services::subscription as s;++ let now = chrono::Local::now();+ let quota = make_quota("claude", true, vec![tier(s::TIER_FIVE_HOUR, 35.0)]);++ let left_texts = en();+ let left_view = format_subscription_quota(&left_texts, "a).expect("left");+ let left_json = serde_json::to_value(panel_quota(&left_texts, &left_view, now, None)).unwrap();+ assert!(left_json.get("showsUsed").is_none());+ assert_eq!(left_json["lines"][0]["shortLabel"], "5h");++ let used_texts = TrayTexts {+ quota_used: true,+ ..en()+ };+ let used_view = format_subscription_quota(&used_texts, "a).expect("used");+ let used_json = serde_json::to_value(panel_quota(&used_texts, &used_view, now, None)).unwrap();+ assert_eq!(used_json["showsUsed"], serde_json::json!(true));+ assert_eq!(used_json["lines"][0]["shortLabel"], "5h");+}diff --git a/src/tray-panel/TrayPanel.tsx b/src/tray-panel/TrayPanel.tsxindex 4d6eec369..b0c99ce43 100644--- a/src/tray-panel/TrayPanel.tsx+++ b/src/tray-panel/TrayPanel.tsx@@ -156,6 +156,62 @@ export function formatResetIn();}+/**+ * 紧凑重置倒计时(如 `1d7h`、`4h47m`、`12m`,与主界面 `countdownStr` 风格一致),+ * 统一列宽、避免挤压进度条;完整本地化文案仍通过 `formatResetIn` 挂在 `title` 上。+ */+export function formatResetCompact(iso: string, now: Date): string | null {+ const at = new Date(iso);+ if (Number.isNaN(at.getTime()) || at <= now) return null;+ const totalMinutes = Math.max(+ 1,+ Math.floor((at.getTime() - now.getTime()) / 60_000),+ );+ const days = Math.floor(totalMinutes / 1440);+ const hours = Math.floor((totalMinutes % 1440) / 60);+ const minutes = totalMinutes % 60;+ if (days > 0) return hours > 0 ? `${days}d${hours}h` : `${days}d`;+ if (hours > 0) return minutes > 0 ? `${hours}h${minutes}m` : `${hours}h`;+ return `${minutes}m`;+}++function quotaHasReset(+ quota: PanelQuota | null | undefined,+ compact: boolean,+ now: Date,+): boolean {+ if (!quota) return false;+ return quota.lines+ .slice(0, compact ? 2 : 3)+ .some((line) => line.resetsAt && formatResetCompact(line.resetsAt, now));+}++/** 单行正余额时收进标题行右侧纵向居中展示,省去一整行高度。 */+function singleInlineBalance(quota: PanelQuota | null) {+ if (!quota || quota.note || (quota.resetCredits ?? 0) > 0) return null;+ if (quota.lines.length !== 1) return null;+ const line = quota.lines[0];+ if (line.left != null || !line.emphasis) return null;+ return line;+}++function ResetCreditsBadge({+ count,+ texts,+}: {+ count: number;+ texts: PanelTexts;+}) {+ return (+ <span+ title={texts.resetCredits.replace("{count}", String(count))}+ className="shrink-0 rounded bg-black/[0.06] px-1.5 py-px text-[10.5px] font-medium tabular-nums text-muted-foreground dark:bg-white/[0.1]"+ >+ ↻×{count}+ </span>+ );+}+/** 只给数值上绿色(「余额 82.10 CNY」里的金额),和主界面 `TONE_TEXT.normal` 同色。 */function EmphasizedText({text,@@ -179,23 +235,108 @@ function QuotaBlock({quota,texts,compact = false,+ inlineResetCredits = false,+ reserveResetCol = false,}: {quota: PanelQuota;texts: PanelTexts;/** 子面板里:最多两档 */compact?: boolean;+ /** 重置次数已内联到标题行,不再单独占一行 */+ inlineResetCredits?: boolean;+ /** 同面板有其它应用带重置时间时,无重置时间的块也保留第四列让进度条对齐 */+ reserveResetCol?: boolean;}) {- if (quota.lines.length === 0 && !quota.note && quota.resetCredits == null) {+ const showResetCredits =+ !inlineResetCredits && quota.resetCredits != null && quota.resetCredits > 0;+ if (quota.lines.length === 0 && !quota.note && !showResetCredits) {return null;}const now = new Date();const lines = quota.lines.slice(0, compact ? 2 : 3).map((line) => ({...line,when: line.resetsAt ? formatResetIn(line.resetsAt, now, texts) : null,+ whenCompact: line.resetsAt ? formatResetCompact(line.resetsAt, now) : null,}));- // 各档共用一张网格(文字 | 进度条 | 多久重置),进度条的起止才对得齐;- // 整块都没有重置时间时不留第三列,免得右边空出一截间距。+ const allCompactTiers =+ lines.length > 0 &&+ lines.every((line) => line.shortLabel && line.left != null);const hasWhen = lines.some((line) => line.when);+ const showResetCol = hasWhen || reserveResetCol;++ if (allCompactTiers) {+ return (+ <div+ data-quota-grid={showResetCol ? "4col" : "3col"}+ className={cn(+ "grid items-center gap-x-2 gap-y-1",+ showResetCol+ ? "grid-cols-[50px_minmax(1.5rem,1fr)_34px_60px]"+ : "grid-cols-[50px_minmax(1.5rem,1fr)_34px]",+ compact ? "mt-1" : "mt-1.5",+ )}+ >+ {lines.map((line, index) => {+ const left = line.left ?? 0;+ const displayPct = Math.round(quota.showsUsed ? 100 - left : left);+ return (+ <div key={index} className="contents">+ <span+ title={line.text}+ className={cn(+ "truncate text-[11.5px] font-medium",+ line.warn ? "text-amber-500" : "text-muted-foreground",+ )}+ >+ {line.shortLabel}+ </span>+ <span className="h-1 overflow-hidden rounded-full bg-black/10 dark:bg-white/10">+ <span+ className={cn(+ "block h-full rounded-full",+ left <= 0+ ? "bg-red-500"+ : line.warn+ ? "bg-amber-500"+ : "bg-blue-500",+ )}+ style={{ width: `${Math.max(left, 2)}%` }}+ />+ </span>+ <span+ className={cn(+ "text-right text-[11.5px] font-medium tabular-nums",+ line.warn ? "text-amber-500" : "text-foreground/80",+ )}+ >+ {displayPct}%+ </span>+ {showResetCol && (+ <span+ title={line.when ?? undefined}+ className="justify-self-end whitespace-nowrap font-mono text-[12px] tabular-nums text-muted-foreground"+ >+ {line.whenCompact ? `↻${line.whenCompact}` : ""}+ </span>+ )}+ </div>+ );+ })}+ {showResetCredits && (+ <span className="col-span-full text-[11px] text-muted-foreground">+ {texts.resetCredits.replace("{count}", String(quota.resetCredits))}+ </span>+ )}+ {quota.note && (+ <span className="col-span-full text-[11px] text-amber-500">+ {quota.note}+ </span>+ )}+ </div>+ );+ }++ // 非标准档位(余额、自定义脚本、无短档名数据):沿用原三列排版return (<divclassName={cn(@@ -211,7 +352,7 @@ function QuotaBlock({<div key={index} className="contents"><spanclassName={cn(- "whitespace-nowrap text-[11px] tabular-nums",+ "whitespace-nowrap text-[11.5px] tabular-nums",line.warn ? "text-amber-500" : "text-muted-foreground",)}>@@ -235,14 +376,17 @@ function QuotaBlock({</span>)}{hasWhen && (- <span className="justify-self-end whitespace-nowrap text-[10.5px] tabular-nums text-muted-foreground">- {line.when}+ <span+ title={line.when ?? undefined}+ className="justify-self-end whitespace-nowrap font-mono text-[12px] tabular-nums text-muted-foreground"+ >+ {line.whenCompact ? `↻${line.whenCompact}` : line.when}</span>)}</div>);})}- {quota.resetCredits != null && quota.resetCredits > 0 && (+ {showResetCredits && (<span className="col-span-full text-[11px] text-muted-foreground">{texts.resetCredits.replace("{count}", String(quota.resetCredits))}</span>@@ -270,6 +414,7 @@ function AppRow({texts,active,side,+ reserveResetCol,onHover,onLeave,onOpen,@@ -278,11 +423,18 @@ function AppRow({texts: PanelTexts;active: boolean;side: "left" | "right";+ reserveResetCol: boolean;onHover: () => void;onLeave: () => void;onOpen: () => void;}) {const Chevron = side === "left" ? ChevronLeft : ChevronRight;+ const balanceLine = singleInlineBalance(app.quota);+ const resetCredits =+ app.quota?.resetCredits != null && app.quota.resetCredits > 0+ ? app.quota.resetCredits+ : null;+return (<buttontype="button"@@ -292,13 +444,13 @@ function AppRow({onMouseLeave={onLeave}onClick={onOpen}className={cn(- // 图标 | 名称 | 箭头;额度另起一行,从名称列一直铺到箭头下方,进度条才不被箭头那一列挤短- "grid w-full grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-x-3 rounded-[10px] px-2.5 py-2 text-left",+ // 图标 | 名称 | 右侧(余额 + 箭头,纵向居中);多档额度另起一行铺到箭头下方+ "grid w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-x-3 rounded-[10px] px-2.5 py-2 text-left",FOCUS_RING,active ? "bg-blue-500/[0.16]" : ROW_HOVER,)}>- <span className="mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-black/[0.05] dark:bg-white/[0.08]">+ <span className="flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-black/[0.05] dark:bg-white/[0.08]"><AppGlyph app={app.app} size={20} badgeClassName="bg-transparent" /></span><span className="min-w-0">@@ -316,6 +468,9 @@ function AppRow({{app.attention}</span>)}+ {resetCredits != null && (+ <ResetCreditsBadge count={resetCredits} texts={texts} />+ )}</span><span className="block truncate text-xs text-muted-foreground">{app.addId ? (@@ -333,14 +488,29 @@ function AppRow({)}</span></span>- {app.addId ? (- <Plus className="mt-2 h-4 w-4 shrink-0 text-muted-foreground" />- ) : (- <Chevron className="mt-2 h-4 w-4 shrink-0 text-muted-foreground" />- )}- {app.quota && (+ <span className="flex shrink-0 items-center gap-1.5">+ {balanceLine && (+ <span+ title={balanceLine.text}+ className="whitespace-nowrap text-[12px] font-medium tabular-nums text-green-600 dark:text-green-400"+ >+ {balanceLine.emphasis}+ </span>+ )}+ {app.addId ? (+ <Plus className="h-4 w-4 shrink-0 text-muted-foreground" />+ ) : (+ <Chevron className="h-4 w-4 shrink-0 text-muted-foreground" />+ )}+ </span>+ {app.quota && !balanceLine && (<span className="col-span-2 col-start-2 min-w-0">- <QuotaBlock quota={app.quota} texts={texts} />+ <QuotaBlock+ quota={app.quota}+ texts={texts}+ inlineResetCredits+ reserveResetCol={reserveResetCol}+ /></span>)}</button>@@ -360,10 +530,12 @@ function matches(row: PanelRow, query: string) {function SubRow({row,texts,+ reserveResetCol,onAction,}: {row: PanelRow;texts: PanelTexts;+ reserveResetCol: boolean;onAction: (id: string) => void;}) {if (row.kind === "separator") {@@ -382,6 +554,14 @@ function SubRow({const hint =provider?.hint && !row.text.includes(provider.hint) ? provider.hint : null;const inUse = row.checked && provider != null;+ const balanceLine = singleInlineBalance(provider?.quota ?? null);+ const resetCredits =+ provider?.quota?.resetCredits != null && provider.quota.resetCredits > 0+ ? provider.quota.resetCredits+ : null;+ const hasRightCol = inUse || balanceLine != null;+ const hasQuotaBlock = provider?.quota != null && !balanceLine;+return (<buttontype="button"@@ -389,13 +569,12 @@ function SubRow({disabled={!row.enabled}onClick={() => onAction(row.id)}className={cn(- // 图标 | 名称 | 使用中;额度另起一行铺到「使用中」下方,免得被那一列挤窄+ // 图标 | 名称 | 右侧(余额 / 使用中,纵向居中);多档额度另起一行铺到右边缘"grid w-full gap-x-2.5 rounded-lg px-2.5 py-1.5 text-left",- inUse+ hasRightCol? "grid-cols-[auto_minmax(0,1fr)_auto]": "grid-cols-[auto_minmax(0,1fr)]",- // 带额度的行高,图标和「使用中」贴着第一行- provider?.quota ? "items-start" : "items-center",+ "items-center",FOCUS_RING,row.enabled ? ROW_HOVER : "cursor-default opacity-55",)}@@ -413,8 +592,11 @@ function SubRow({) : null}</span><span className="min-w-0">- <span className="block truncate text-[13px] font-medium">- {row.text}+ <span className="flex items-center gap-1.5">+ <span className="truncate text-[13px] font-medium">{row.text}</span>+ {resetCredits != null && (+ <ResetCreditsBadge count={resetCredits} texts={texts} />+ )}</span>{hint && (<span className="block truncate text-[11px] text-muted-foreground">@@ -422,14 +604,32 @@ function SubRow({</span>)}</span>- {inUse && (- <span className="text-[11px] font-medium text-blue-500">- {texts.inUse}+ {hasRightCol && (+ <span className="flex shrink-0 items-center gap-1.5">+ {balanceLine && (+ <span+ title={balanceLine.text}+ className="whitespace-nowrap text-[11.5px] font-medium tabular-nums text-green-600 dark:text-green-400"+ >+ {balanceLine.emphasis}+ </span>+ )}+ {inUse && (+ <span className="text-[11px] font-medium text-blue-500">+ {texts.inUse}+ </span>+ )}</span>)}- {provider?.quota && (+ {hasQuotaBlock && provider?.quota && (<span className="min-w-0 [grid-column:2/-1]">- <QuotaBlock quota={provider.quota} texts={texts} compact />+ <QuotaBlock+ quota={provider.quota}+ texts={texts}+ compact+ inlineResetCredits+ reserveResetCol={reserveResetCol}+ /></span>)}</button>@@ -458,6 +658,10 @@ function SubPanel({? rows.filter((row) => row.kind === "provider" && matches(row, needle)): rows;const providerCount = rows.filter((row) => row.kind === "provider").length;+ const now = new Date();+ const subHasReset = shown.some((row) =>+ quotaHasReset(row.provider?.quota, true, now),+ );return (<>@@ -494,6 +698,7 @@ function SubPanel({key={`${row.id}-${index}`}row={row}texts={texts}+ reserveResetCol={subHasReset}onAction={onAction}/>))@@ -1155,22 +1360,29 @@ export function TrayPanel() {{state.feedback}</div>)}- {apps.map((app) => (- <AppRow- key={app.app}- app={app}- texts={texts}- active={openEntry?.app === app.app}- side={placement.side}- onHover={() => hoverApp(app)}- onLeave={leaveApp}- onOpen={() =>- app.addId- ? action(app.addId)- : openSub(openApp === app.app ? null : app)- }- />- ))}+ {(() => {+ const now = new Date();+ const mainHasReset = apps.some((entry) =>+ quotaHasReset(entry.quota, false, now),+ );+ return apps.map((app) => (+ <AppRow+ key={app.app}+ app={app}+ texts={texts}+ active={openEntry?.app === app.app}+ side={placement.side}+ reserveResetCol={mainHasReset}+ onHover={() => hoverApp(app)}+ onLeave={leaveApp}+ onOpen={() =>+ app.addId+ ? action(app.addId)+ : openSub(openApp === app.app ? null : app)+ }+ />+ ));+ })()}</div>) : (<Suspensediff --git a/src/tray-panel/api.ts b/src/tray-panel/api.tsindex 9d5d9cbfa..54a73f2a0 100644--- a/src/tray-panel/api.ts+++ b/src/tray-panel/api.ts@@ -33,6 +33,8 @@ export interface PanelLink {export interface PanelQuotaLine {text: string;+ /** 托盘面板专用的紧凑短档名(如 `5h`、`7d`、`30d`、`Gemini`、`Claude`) */+ shortLabel?: string | null;/** 剩余百分比;余额这种没有总额的为空 */left: number | null;warn: boolean;@@ -47,6 +49,8 @@ export interface PanelQuota {note: string | null;/** ChatGPT 订阅(Codex)可用的额度重置次数 */resetCredits: number | null;+ /** 百分比是否按「已用」展示 */+ showsUsed?: boolean;}export interface PanelProvider {diff --git a/tests/components/TrayPanel.test.tsx b/tests/components/TrayPanel.test.tsxindex eebdc1bb8..8df34c006 100644--- a/tests/components/TrayPanel.test.tsx+++ b/tests/components/TrayPanel.test.tsx@@ -8,7 +8,11 @@ import {import type { ReactNode } from "react";import { QueryClientProvider } from "@tanstack/react-query";import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";-import { TrayPanel, formatResetIn } from "@/tray-panel/TrayPanel";+import {+ TrayPanel,+ formatResetCompact,+ formatResetIn,+} from "@/tray-panel/TrayPanel";import {CHANGED_EVENT,SHOW_EVENT,@@ -986,4 +990,126 @@ describe("formatResetIn", () => {expect(formatResetIn(at(-MIN), now, texts)).toBeNull();expect(formatResetIn("not a date", now, texts)).toBeNull();});++ it("formats compact reset countdowns without spaces", () => {+ expect(formatResetCompact(at((47 * 60 + 30) * MIN), now)).toBe("1d23h");+ expect(formatResetCompact(at(2 * 1440 * MIN), now)).toBe("2d");+ expect(formatResetCompact(at((4 * 60 + 5) * MIN), now)).toBe("4h5m");+ expect(formatResetCompact(at(3 * 60 * MIN), now)).toBe("3h");+ expect(formatResetCompact(at(12 * MIN), now)).toBe("12m");+ expect(formatResetCompact(at(20_000), now)).toBe("1m");+ expect(formatResetCompact(at(-MIN), now)).toBeNull();+ expect(formatResetCompact("not a date", now)).toBeNull();+ });+});++describe("TrayPanel compact quota presentation", () => {+ afterEach(() => {+ vi.restoreAllMocks();+ window.localStorage.removeItem("cc-switch-tray-tab");+ });++ it("renders compact short labels, percentages, inline balance, inline reset credits, and aligns bars across reset/no-reset blocks", async () => {+ vi.mocked(trayPanelApi.layout).mockResolvedValue(undefined);+ vi.mocked(trayPanelApi.placement).mockResolvedValue(windows);+ vi.mocked(trayPanelApi.state).mockResolvedValue({+ ...state,+ apps: [+ {+ ...state.apps[0],+ quota: {+ lines: [+ {+ text: "余额 4.20 CNY",+ left: null,+ warn: false,+ resetsAt: null,+ emphasis: "4.20 CNY",+ },+ ],+ note: null,+ resetCredits: null,+ },+ },+ {+ ...state.apps[0],+ app: "codex",+ name: "Codex",+ current: "OpenAI Official",+ quota: {+ lines: [+ {+ text: "5 小时剩余 100%",+ shortLabel: "5h",+ left: 100,+ warn: false,+ resetsAt: null,+ emphasis: null,+ },+ {+ text: "每周剩余 82%",+ shortLabel: "7d",+ left: 82,+ warn: false,+ resetsAt: new Date(Date.now() + 31 * 3600_000).toISOString(),+ emphasis: null,+ },+ ],+ note: null,+ resetCredits: 2,+ },+ },+ {+ ...state.apps[0],+ app: "gemini",+ name: "Gemini CLI",+ current: "Google",+ quota: {+ lines: [+ {+ text: "Pro 剩余 90%",+ shortLabel: "Pro",+ left: 90,+ warn: false,+ resetsAt: null,+ emphasis: null,+ },+ {+ text: "Flash 剩余 75%",+ shortLabel: "Flash",+ left: 75,+ warn: false,+ resetsAt: null,+ emphasis: null,+ },+ ],+ note: null,+ resetCredits: null,+ },+ },+ ],+ });++ const { container } = renderPanel();++ // 单行余额纵向居中内联展示,完整文案保留在 title+ const balance = await screen.findByText("4.20 CNY");+ expect(balance).toHaveAttribute("title", "余额 4.20 CNY");+ expect(balance).toHaveClass("text-green-600");++ // 紧凑四列短标签 + 百分比 + ↻×2 内联徽章+ expect(screen.getByText("5h")).toHaveAttribute("title", "5 小时剩余 100%");+ expect(screen.getByText("100%")).toBeVisible();+ expect(screen.getByText("7d")).toBeVisible();+ expect(screen.getByText("82%")).toBeVisible();+ expect(screen.getByText("↻×2")).toHaveAttribute("title", "2 resets");+ expect(screen.getByText(/^↻1d/)).toBeVisible();++ // 无重置时间的块(Gemini CLI)与带重置时间的块共用四列网格,进度条对齐+ const grids = container.querySelectorAll("[data-quota-grid]");+ expect(grids).toHaveLength(2);+ grids.forEach((grid) => {+ expect(grid).toHaveAttribute("data-quota-grid", "4col");+ });+ });});