Chat: show the active Claude account in the send tooltip, menu and limit banner
usage.account now carries the email and organization of the account Claude Code is signed in to (from its initialize account, or the saved account just switched to), sent at process start and after a switch. The app shows it as the send tooltip's usage prefix, the Claude account menu subtitle, the usage-limit banner's status line and the info sheet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -68,13 +68,15 @@ class _ChatAccountUsageSectionState extends State<ChatAccountUsageSection> {
|
||||
),
|
||||
)
|
||||
else ...[
|
||||
if (plan.isNotEmpty)
|
||||
if (plan.isNotEmpty || usage.email.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 4),
|
||||
child: Text(
|
||||
usage.harness.isEmpty
|
||||
? '$plan plan'
|
||||
: '${usage.harness} · $plan plan',
|
||||
[
|
||||
if (usage.email.isNotEmpty) usage.email,
|
||||
if (usage.harness.isNotEmpty) usage.harness,
|
||||
if (plan.isNotEmpty) '$plan plan',
|
||||
].join(' · '),
|
||||
key: const Key('chat-account-usage-plan'),
|
||||
style: muted,
|
||||
),
|
||||
|
||||
@@ -9,8 +9,9 @@ import '../domain/chat_usage_ring.dart';
|
||||
/// A thin ring around the composer's send button showing how much of the
|
||||
/// harness account's quota is used ([chatUsageRing]): barely visible
|
||||
/// normally, the tertiary colour from 80% and the error colour from 95%. The
|
||||
/// button's tooltip (hover, or long-press on touch) adds every window:
|
||||
/// "Send" then "5-hour 42% · resets 17:20 · Weekly 61% · resets Thu 09:00".
|
||||
/// button's tooltip (hover, or long-press on touch) adds the account and
|
||||
/// every window: "Send" then "sam@example.com · 5-hour 42% · resets 17:20 ·
|
||||
/// Weekly 61% · resets Thu 09:00" ([chatSendTooltip]).
|
||||
///
|
||||
/// The ring is painted beside the button, never in its layout or hit test,
|
||||
/// so the button keeps its size, target, states and animations. Without a
|
||||
@@ -72,17 +73,14 @@ class _ChatSendUsageRingState extends State<ChatSendUsageRing> {
|
||||
|
||||
Widget _ring(BuildContext context) {
|
||||
final now = widget.now();
|
||||
final ring = chatUsageRing(widget.usage(), now);
|
||||
final usage = widget.usage();
|
||||
final ring = chatUsageRing(usage, now);
|
||||
_ticking(ring != null);
|
||||
// The button stays the same child with or without a ring, so a report
|
||||
// arriving never remounts it (its hover, focus and ink stay).
|
||||
return CustomPaint(
|
||||
painter: ring == null ? null : _painter(context, ring),
|
||||
child: widget.button(
|
||||
ring == null
|
||||
? widget.label
|
||||
: '${widget.label}\n${chatUsageRingSummary(ring, now)}',
|
||||
),
|
||||
child: widget.button(chatSendTooltip(widget.label, usage, ring, now)),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -513,6 +513,15 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
controller.transcriptChanges.addListener(
|
||||
() => _reconcileUnsent(controller),
|
||||
);
|
||||
// The menu's Claude account item names the signed-in account, which a
|
||||
// usage frame (not a transcript change) reports.
|
||||
var email = controller.accountUsage?.email;
|
||||
controller.addListener(() {
|
||||
final now = controller.accountUsage?.email;
|
||||
if (now == email) return;
|
||||
email = now;
|
||||
if (mounted) setState(() {});
|
||||
});
|
||||
// Delivery states follow the server's queue reports. Read the composer
|
||||
// when the report arrives: it is not built yet while this one is.
|
||||
controller.onQueue = (queue) {
|
||||
@@ -1559,6 +1568,8 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
_controller.running,
|
||||
// The More menu offers Dismiss all finished commands only with one.
|
||||
_shellRuns.finishedIds.isNotEmpty,
|
||||
// The Claude account item names the signed-in account.
|
||||
_controller.accountUsage?.email,
|
||||
],
|
||||
() => _buildHeader(session, inShellBar, canGoBack, answeredBy, inWindow),
|
||||
);
|
||||
@@ -1651,6 +1662,8 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
ChatBarAction(
|
||||
key: const Key('chat-claude-account-menu'),
|
||||
label: 'Claude account',
|
||||
// The account the chat's Claude Code is signed in to now.
|
||||
subtitle: _controller.accountUsage?.email,
|
||||
identifier: 'chat-claude-account',
|
||||
onPressed: () =>
|
||||
unawaited(showChatClaudeAccountsDialog(context, accounts)),
|
||||
|
||||
@@ -14,7 +14,8 @@ import 'chat_thread_controller.dart';
|
||||
|
||||
/// Above the composer while the chat's account is out of quota, as Claude
|
||||
/// Code's own app shows it: "Out of usage credits" (or the refusal's own
|
||||
/// "You've hit your 5-hour limit"), "Auto-resuming at 15:41", an
|
||||
/// "You've hit your 5-hour limit"), the account that hit it and
|
||||
/// "Auto-resuming at 15:41", an
|
||||
/// "Auto-continue when limits reset" checkbox and Try again.
|
||||
///
|
||||
/// With auto-continue on (a preference shared by every chat, on by default,
|
||||
@@ -179,7 +180,10 @@ class _ChatUsageLimitBannerState extends State<ChatUsageLimitBanner> {
|
||||
final resumesAt = pending.isEmpty
|
||||
? limit.sendAt
|
||||
: chatScheduledSendAt(pending.first['send_at'], now)!;
|
||||
final email = widget.thread.accountUsage?.email ?? '';
|
||||
final status = [
|
||||
// The account that hit the limit.
|
||||
if (email.isNotEmpty) email,
|
||||
if (enabled && refused != null)
|
||||
'Auto-resuming at ${time(resumesAt)}'
|
||||
else
|
||||
|
||||
@@ -31,8 +31,15 @@ class ChatAccountUsage {
|
||||
required this.unsupported,
|
||||
this.switchedAt = 0,
|
||||
this.extraUsage,
|
||||
this.email = '',
|
||||
this.organization = '',
|
||||
});
|
||||
|
||||
/// The account the harness is signed in to now ("sam@example.com"); empty
|
||||
/// when it did not say (an API key, or a harness without accounts).
|
||||
final String email;
|
||||
final String organization;
|
||||
|
||||
/// Display name of the harness ("Claude Code", "Codex", "OpenCode").
|
||||
final String harness;
|
||||
final String plan;
|
||||
@@ -131,9 +138,10 @@ ChatAccountUsage? chatAccountUsage(Object? value) {
|
||||
}
|
||||
}
|
||||
final switchedAt = _millis(value['switched_at']);
|
||||
// A switched account replaces the previous report even with no windows
|
||||
// yet; otherwise an empty report keeps the last one.
|
||||
if (windows.isEmpty && switchedAt == 0) return null;
|
||||
final email = '${value['email'] ?? ''}'.trim();
|
||||
// A switched or newly named account replaces the previous report even with
|
||||
// no windows yet; otherwise an empty report keeps the last one.
|
||||
if (windows.isEmpty && switchedAt == 0 && email.isEmpty) return null;
|
||||
return ChatAccountUsage(
|
||||
harness: harness,
|
||||
plan: '${value['plan'] ?? ''}'.trim(),
|
||||
@@ -142,6 +150,8 @@ ChatAccountUsage? chatAccountUsage(Object? value) {
|
||||
unsupported: false,
|
||||
switchedAt: switchedAt,
|
||||
extraUsage: _extraUsage(value['extra_usage']),
|
||||
email: email,
|
||||
organization: '${value['organization'] ?? ''}'.trim(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -100,6 +100,22 @@ String chatUsageRingResetTime(DateTime at, DateTime now) {
|
||||
return '${local.day} ${months[local.month - 1]} $time';
|
||||
}
|
||||
|
||||
/// The send button's tooltip: [label] ("Send"), then the account the chat
|
||||
/// runs on and its usage: "sam@example.com · 5-hour 42% · resets 17:20 · …".
|
||||
/// Either part may be missing; with neither the tooltip is the label alone.
|
||||
String chatSendTooltip(
|
||||
String label,
|
||||
ChatAccountUsage? usage,
|
||||
ChatUsageRing? ring,
|
||||
DateTime now,
|
||||
) {
|
||||
final line = [
|
||||
if (usage?.email case final email? when email.isNotEmpty) email,
|
||||
if (ring != null) chatUsageRingSummary(ring, now),
|
||||
].join(' · ');
|
||||
return line.isEmpty ? label : '$label\n$line';
|
||||
}
|
||||
|
||||
/// "5-hour 42% · resets 17:20 · Weekly 61% · resets Thu 09:00", then any
|
||||
/// extra usage note.
|
||||
String chatUsageRingSummary(ChatUsageRing ring, DateTime now) => [
|
||||
|
||||
@@ -9,9 +9,14 @@ class ChatBarAction extends StatelessWidget implements SegmentedOverflowable {
|
||||
required this.materialIcon,
|
||||
this.identifier,
|
||||
this.destructive = false,
|
||||
this.subtitle,
|
||||
});
|
||||
|
||||
final String label;
|
||||
|
||||
/// A short second line the More menu shows under [label] (the account the
|
||||
/// action acts on); the bar's icon button adds it to its tooltip.
|
||||
final String? subtitle;
|
||||
final VoidCallback onPressed;
|
||||
final IconData materialIcon;
|
||||
|
||||
@@ -27,14 +32,18 @@ class ChatBarAction extends StatelessWidget implements SegmentedOverflowable {
|
||||
icon: materialIcon,
|
||||
onPressed: onPressed,
|
||||
destructive: destructive,
|
||||
subtitle: subtitle,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final subtitle = this.subtitle;
|
||||
return Semantics(
|
||||
identifier: identifier,
|
||||
child: IconButton(
|
||||
tooltip: label,
|
||||
tooltip: subtitle == null || subtitle.isEmpty
|
||||
? label
|
||||
: '$label\n$subtitle',
|
||||
onPressed: onPressed,
|
||||
icon: Icon(materialIcon),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user