The CLD panel went blank with no reason when Claude Code's saved OAuth token had expired and the widget's own renewal was refused. - Collapsed panel shows EXPIRED/ERR instead of dashes; failures are logged to `qs log`. - Retry every minute after a failure instead of every 5. - claude-usage identifies as claude-cli, the suspected cause of the refresh 429s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
163 lines
5.0 KiB
QML
163 lines
5.0 KiB
QML
pragma ComponentBehavior: Bound
|
|
|
|
import QtQuick
|
|
import qs.HyprChrome.Theme
|
|
import qs.HyprChrome.Widgets.Bar.Panels
|
|
import qs.HyprChrome.Widgets.Bar.Vitals
|
|
|
|
// Claude subscription limits on the rail: the 5-hour session window and the
|
|
// weekly one, plus any per-model weekly caps the plan reports.
|
|
BarPanel {
|
|
id: claude
|
|
|
|
// Overridable so the headless render can stage it without the network.
|
|
property var fiveHour: usage.fiveHour
|
|
property var sevenDay: usage.sevenDay
|
|
property var extra: usage.extra
|
|
property string error: usage.error
|
|
property string shortError: usage.shortError
|
|
property bool ready: usage.ready
|
|
|
|
readonly property var usage: ClaudeState {}
|
|
|
|
panelId: "CLD"
|
|
title: "CLAUDE"
|
|
meta: claude.error !== "" ? (claude.ready ? "STALE" : "OFFLINE") : claude.ready ? "LIMITS" : "PRIMING"
|
|
|
|
// Ticks the reset countdowns without re-polling.
|
|
property date now: new Date()
|
|
Timer {
|
|
interval: 30000
|
|
running: true
|
|
repeat: true
|
|
onTriggered: claude.now = new Date()
|
|
}
|
|
|
|
implicitWidth: claude.expanded
|
|
? Math.max(claude.headerMinWidth, claude.padding * 2 + body.width)
|
|
: Math.max(claude.headerMinWidth, claude.briefLeft + brief.implicitWidth + claude.padding)
|
|
|
|
function fraction(w) {
|
|
return w ? Math.max(0, Math.min(1, w.utilization / 100)) : 0;
|
|
}
|
|
|
|
function pct(w) {
|
|
return w ? Math.round(w.utilization) + "%" : "--";
|
|
}
|
|
|
|
function until(w) {
|
|
if (!w || !w.resets_at)
|
|
return "";
|
|
const mins = Math.max(0, Math.round((new Date(w.resets_at) - claude.now) / 60000));
|
|
if (mins >= 1440)
|
|
return `${Math.floor(mins / 1440)}D ${Math.floor(mins % 1440 / 60)}H`;
|
|
if (mins >= 60)
|
|
return `${Math.floor(mins / 60)}H ${mins % 60}M`;
|
|
return `${mins}M`;
|
|
}
|
|
|
|
function tone(w) {
|
|
const f = claude.fraction(w);
|
|
return !claude.ready ? Theme.disabled : f >= 0.85 ? Theme.hot : Theme.text;
|
|
}
|
|
|
|
summary: Row {
|
|
id: brief
|
|
spacing: 10
|
|
|
|
Repeater {
|
|
model: [
|
|
{ label: "5H", window: claude.fiveHour },
|
|
{ label: "7D", window: claude.sevenDay }
|
|
]
|
|
|
|
Row {
|
|
required property var modelData
|
|
spacing: 4
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
// Dashes say nothing; with no numbers yet the error label stands alone.
|
|
visible: claude.ready || claude.shortError === ""
|
|
|
|
Text {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
text: parent.modelData.label
|
|
color: Theme.muted
|
|
font.family: Theme.microFont
|
|
font.pixelSize: 10
|
|
}
|
|
|
|
Text {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
text: claude.pct(parent.modelData.window)
|
|
color: claude.tone(parent.modelData.window)
|
|
font.family: Theme.displayFont
|
|
font.pixelSize: 13
|
|
font.bold: true
|
|
}
|
|
}
|
|
}
|
|
|
|
Text {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
visible: claude.shortError !== ""
|
|
text: claude.shortError
|
|
color: Theme.hot
|
|
font.family: Theme.displayFont
|
|
font.pixelSize: 13
|
|
font.bold: true
|
|
}
|
|
}
|
|
|
|
Column {
|
|
id: body
|
|
width: 260
|
|
spacing: 5
|
|
|
|
Repeater {
|
|
model: [
|
|
{ label: "SESSION", window: claude.fiveHour },
|
|
{ label: "WEEKLY", window: claude.sevenDay }
|
|
].concat(claude.extra)
|
|
|
|
Column {
|
|
required property var modelData
|
|
width: body.width
|
|
spacing: 2
|
|
|
|
VitalRow {
|
|
width: parent.width
|
|
labelWidth: 64
|
|
label: parent.modelData.label
|
|
value: claude.fraction(parent.modelData.window)
|
|
readout: claude.pct(parent.modelData.window)
|
|
ready: claude.ready && !!parent.modelData.window
|
|
}
|
|
|
|
Text {
|
|
x: 64
|
|
visible: text !== ""
|
|
text: {
|
|
const t = claude.until(parent.modelData.window);
|
|
return t ? `RESETS IN ${t}` : "";
|
|
}
|
|
color: Theme.muted
|
|
font.family: Theme.microFont
|
|
font.pixelSize: 9
|
|
font.letterSpacing: 1.2
|
|
}
|
|
}
|
|
}
|
|
|
|
Text {
|
|
width: body.width
|
|
visible: claude.error !== ""
|
|
text: claude.error.toUpperCase()
|
|
color: Theme.hot
|
|
font.family: Theme.microFont
|
|
font.pixelSize: 9
|
|
font.letterSpacing: 1.2
|
|
wrapMode: Text.WordWrap
|
|
}
|
|
}
|
|
}
|