From 29c4a20a861fc84d849eb0d831b2d85ab2455e37 Mon Sep 17 00:00:00 2001 From: Ryan Hughes Date: Tue, 9 Jun 2026 18:11:47 -0400 Subject: [PATCH] Fix Claude weekly usage display --- shell/plugins/model-usage/Widget.qml | 12 +++++- .../plugins/model-usage/providers/Claude.qml | 38 +++++++++---------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/shell/plugins/model-usage/Widget.qml b/shell/plugins/model-usage/Widget.qml index 8dbb7366..0039b4f7 100644 --- a/shell/plugins/model-usage/Widget.qml +++ b/shell/plugins/model-usage/Widget.qml @@ -170,8 +170,16 @@ BarWidget { return "" } + function rateLimitLabelIsWeekly(label) { + var text = String(label || "").toLowerCase() + return text.indexOf("week") >= 0 || text.indexOf("7-day") >= 0 || text.indexOf("seven_day") >= 0 + } + function usagePercent(provider) { if (!provider) return -1 + var weekly = weeklyUsage(provider) + if (weekly.percent >= 0) return weekly.percent + var values = [] if (provider.rateLimitPercent >= 0) values.push(provider.rateLimitPercent) if (provider.secondaryRateLimitPercent >= 0) values.push(provider.secondaryRateLimitPercent) @@ -186,9 +194,9 @@ BarWidget { function weeklyUsage(provider) { if (!provider) return ({ percent: -1, resetAt: "", label: "" }) - if (String(provider.rateLimitLabel || "").toLowerCase().indexOf("week") >= 0) + if (root.rateLimitLabelIsWeekly(provider.rateLimitLabel)) return { percent: provider.rateLimitPercent, resetAt: provider.rateLimitResetAt, label: provider.rateLimitLabel } - if (String(provider.secondaryRateLimitLabel || "").toLowerCase().indexOf("week") >= 0) + if (root.rateLimitLabelIsWeekly(provider.secondaryRateLimitLabel)) return { percent: provider.secondaryRateLimitPercent, resetAt: provider.secondaryRateLimitResetAt, label: provider.secondaryRateLimitLabel } return ({ percent: -1, resetAt: "", label: "" }) } diff --git a/shell/plugins/model-usage/providers/Claude.qml b/shell/plugins/model-usage/providers/Claude.qml index fb5b08eb..b9a47e64 100644 --- a/shell/plugins/model-usage/providers/Claude.qml +++ b/shell/plugins/model-usage/providers/Claude.qml @@ -16,10 +16,10 @@ Item { property string usageStatusText: "" property real rateLimitPercent: -1 - property string rateLimitLabel: "Weekly (7-day)" + property string rateLimitLabel: "Session (5-hour)" property string rateLimitResetAt: "" property real secondaryRateLimitPercent: -1 - property string secondaryRateLimitLabel: "Session (5-hour)" + property string secondaryRateLimitLabel: "Weekly (7-day)" property string secondaryRateLimitResetAt: "" property int todayPrompts: 0 @@ -284,10 +284,10 @@ Item { function clearAuthoritativeRateLimits() { root.hasAuthoritativeRateLimit = false; root.rateLimitPercent = -1; - root.rateLimitLabel = "Weekly (7-day)"; + root.rateLimitLabel = "Session (5-hour)"; root.rateLimitResetAt = ""; root.secondaryRateLimitPercent = -1; - root.secondaryRateLimitLabel = "Session (5-hour)"; + root.secondaryRateLimitLabel = "Weekly (7-day)"; root.secondaryRateLimitResetAt = ""; } @@ -360,29 +360,27 @@ Item { root.hasAuthoritativeRateLimit = true; root.rateLimitPercent = -1; - root.rateLimitLabel = "Weekly (7-day)"; + root.rateLimitLabel = "Session (5-hour)"; root.rateLimitResetAt = ""; root.secondaryRateLimitPercent = -1; - root.secondaryRateLimitLabel = "Session (5-hour)"; + root.secondaryRateLimitLabel = "Weekly (7-day)"; root.secondaryRateLimitResetAt = ""; - if (weeklyNorm >= 0) - root.rateLimitPercent = weeklyNorm; if (sessionNorm >= 0) - root.secondaryRateLimitPercent = sessionNorm; - if (weeklyReset !== null && weeklyReset !== undefined) - root.rateLimitResetAt = root.normalizeResetAt(weeklyReset); - if (sessionReset !== null && sessionReset !== undefined) - root.secondaryRateLimitResetAt = root.normalizeResetAt(sessionReset); - - if (root.rateLimitPercent < 0 && sessionNorm >= 0) { root.rateLimitPercent = sessionNorm; - root.rateLimitLabel = root.secondaryRateLimitLabel; - root.rateLimitResetAt = root.secondaryRateLimitResetAt; - } + if (weeklyNorm >= 0) + root.secondaryRateLimitPercent = weeklyNorm; + if (sessionReset !== null && sessionReset !== undefined) + root.rateLimitResetAt = root.normalizeResetAt(sessionReset); + if (weeklyReset !== null && weeklyReset !== undefined) + root.secondaryRateLimitResetAt = root.normalizeResetAt(weeklyReset); - if (sourceLabel) - root.rateLimitLabel = root.rateLimitLabel + " (" + sourceLabel + ")"; + if (sourceLabel) { + if (root.secondaryRateLimitPercent >= 0) + root.secondaryRateLimitLabel = root.secondaryRateLimitLabel + " (" + sourceLabel + ")"; + else if (root.rateLimitPercent >= 0) + root.rateLimitLabel = root.rateLimitLabel + " (" + sourceLabel + ")"; + } return true; }