Files
homelab/dotfiles/quickshell/HyprChrome/Widgets/Bar/Claude/ClaudePanel.qml
T
darmanandClaude Opus 5.5 f84611bc6e feat(terra): Claude subscription limits panel on the rail
CLD panel next to luna showing the 5-hour and weekly usage windows (plus
any per-model weekly caps), polled every 5 min via a new `claude-usage`
script that reuses Claude Code's OAuth login and refreshes it when expired.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 01:26:44 +02:00

150 lines
4.5 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 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
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
}
}
}
}
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
}
}
}