Skip to content

feat: account spend-pace rows and auth self-recovery - #39

Open
oyardena wants to merge 10 commits into
CodeZeno:mainfrom
oyardena:feat/account-usage-rows
Open

feat: account spend-pace rows and auth self-recovery#39
oyardena wants to merge 10 commits into
CodeZeno:mainfrom
oyardena:feat/account-usage-rows

Conversation

@oyardena

@oyardena oyardena commented Jun 20, 2026

Copy link
Copy Markdown

Summary

  • Add enterprise account credit/spend usage rows (Mo/Wk/Dy pace bars) with spend-anchor repair so week/day totals reflect period deltas instead of full-cycle spend.
  • Refresh OAuth on Windows via HTTP (POST /v1/oauth/token) instead of spawning claude -p ., avoiding token burn during poll retries.
  • Stabilize the layered taskbar popup: anchor leftmost placement to visible taskbar chrome (Win11 centered taskbar), keep TOPMOST z-order, and add keepalive plus display-change debouncing so the widget survives sleep/DPI/taskbar moves.
  • Improve taskbar recovery for embedded mode and auth-failure self-recovery paths.

Test plan

  • cargo build --release on Windows (msys64 mingw)
  • Deployed to local WinGet binary; widget visible at visible-chrome left edge with Mo/Wk/Dy values
  • OAuth refresh uses HTTP on Windows (no claude -p . in diagnose log)
  • Spend anchors: Wk/Dy near daily delta, Mo shows cycle total
  • Screen capture verification (_probe_taskbar_context.ps1Pass: True)
  • Upstream maintainer smoke test on multi-monitor Win11 taskbar

@oyardena
oyardena force-pushed the feat/account-usage-rows branch from c87c9e6 to fa5c927 Compare June 20, 2026 15:54
For users on an enterprise Claude plan (no five-hour / seven-day rate-limit
buckets), the widget now shows two dedicated rows:

  Cr  9%·20/6   — credit remaining (%) and expiry date in system locale format
  Sp  $12/$50   — spend used / spend limit

For personal (Pro/Free) accounts the rows continue to show the normal 5h/7d
rate-limit bars.

Implementation notes:
- Parses `cinder_cove` and `spend` fields from the usage endpoint response
- Locale-aware date format via GetLocaleInfoW (respects separator and D/M order)
- Disk cache at %APPDATA%\ClaudeCodeUsageMonitor\account_cache.json survives
  widget restarts; cleared when plan has no enterprise fields (prevents stale
  enterprise rows appearing for Pro users after a 429)
- Tray tooltip uses dynamic row labels ("Cr"/"Sp" vs "5h"/"7d")
- tray_icon.rs: guard empty text before DrawTextW to avoid GDI crash
@oyardena
oyardena force-pushed the feat/account-usage-rows branch from fa5c927 to a8be4f8 Compare June 21, 2026 20:08
oyardena added 2 commits June 29, 2026 15:29
- native_interop: add move_window_async (SetWindowPos + SWP_ASYNCWINDOWPOS)
  to reposition WS_CHILD windows in Explorer without cross-process blocking;
  add detach_from_taskbar, raise_above_taskbar, TIMER_DRAG constant
- window: fix drag in embedded mode — replace early-return + move_window with
  move_window_async; poll mouse via TIMER_DRAG (16 ms) instead of SetCapture
  (SetCapture on a taskbar child freezes Explorer)
- window: widen drag-handle hit target from 3 px to 10 logical px
  (LEFT_DIVIDER_HIT_W) without changing the visual divider width; this makes
  the handle reliably hittable at high DPI (e.g. 20 physical px at 200% DPI)
- window: add verbose diagnose logging to WM_LBUTTONDOWN / is_drag_handle_point
  / start_drag_reposition / TIMER_DRAG / update_drag_reposition_from_cursor
- window: spawn_taskbar_watchdog improvements — detect stale embeds via window
  parentage check (GetParent) rather than HWND equality; post WM_APP_RECOVER_TASKBAR
  to re-attach without relaunching on transient failures; relaunch only after
  TASKBAR_RECOVER_MAX_ATTEMPTS consecutive failures
- spend_pace: new module; .cargo/config.toml: linker config for MinGW cross-build
Keep last-good Mo/Wk/Dy instead of painting !, retry auth polls on a
timer rather than only credential-file mtime changes, and refresh Claude
tokens on 401. Also repair stuck spend anchors and leftmost tray defaults.
@oyardena oyardena changed the title feat: display enterprise account credit and spend usage rows feat: account spend-pace rows and auth self-recovery Jul 14, 2026
oyardena added 7 commits July 21, 2026 12:27
Use HTTP OAuth refresh instead of claude -p on Windows, repair spend
anchors so Wk/Dy reflect period deltas, and anchor the layered popup to
visible taskbar chrome with TOPMOST z-order. Add keepalive and display-
change debouncing so the widget survives sleep/DPI/taskbar moves.
tray_offset -1 used visible-chrome left instead of taskbar_rect.left. Align embedded leftmost mode to x=0 as well.
Mo/Wk/Dy labels were clipped at a fixed 62px column, cutting $2000
down to $200 for 4-digit limits. Widen TEXT_WIDTH to fit.

The floating popup is HWND_TOPMOST to track the taskbar's tray icons,
which also put it above fullscreen video/games. Poll the foreground
window every 500ms and hide the widget when it's genuinely fullscreen
(no title bar, covers its monitor, excluding shell overlay classes
like Windows.UI.Core.CoreWindow that are always full-monitor-sized).
Gate the other periodic re-show paths (tray relayout, keepalive) on
that same state so they stop fighting the hide and causing flicker.
Track the last applied popup layout and skip position_at_taskbar /
render_layered when nothing moved, instead of re-rendering on every
15s keepalive tick. Cache successful poll results (keyed on a
credential-file activity signature) for up to 15 minutes so idle
ticks reuse the last usage data instead of hitting the network.
Debounce sync_fullscreen_visibility and the taskbar watchdog so they
only act on real state transitions, and invalidate both caches on
manual refresh, tray icon rebuild, and language/reset actions so
those still force an immediate repoll and repaint.
…nd non-leftmost default

Three positioning/visibility bugs, root-caused after finding they were never
actually fixed in prior sessions despite repeated attempts:

- Fullscreen suppression checked only the foreground window's own monitor,
  never which monitor the widget's own taskbar lives on. A maximized/
  fullscreen window on a secondary monitor was hiding the widget on the
  primary taskbar even though nothing there was fullscreen.
  should_hide_widget_for_fullscreen now scopes the check to the widget's
  taskbar monitor.

- Default/leftmost position stopped at the left edge of the taskbar's icon
  cluster instead of the taskbar's own physical left edge (x=0), even when
  that space was genuinely empty. taskbar_placement_band_left is now
  hardcoded to 0, unconditionally, with a doc comment recording that this is
  a deliberate, non-negotiable requirement so it doesn't get "corrected" back
  to icon-cluster-avoidance by a future session.

- Widget disappearing when hovering a taskbar thumbnail preview (Aero Peek):
  the existing fix was reactive (polling for TaskListThumbnailWnd/
  CThumbnailWnd, a 5s latch, z-order raise), which only reacts after the
  fact to a compositor-level effect. Added the actual fix: exclude the
  window from DWM's peek ghosting via
  DwmSetWindowAttribute(DWMWA_EXCLUDED_FROM_PEEK), set once at window
  creation. Needs the Win32_Graphics_Dwm feature, added to Cargo.toml.

Also commits src/proof_capture.rs and CLAUDE.md, which were present in the
working tree but untracked.
Both held the app state Mutex guard across a call to a function that
locks the same (non-reentrant) mutex again on the same thread:

- sync_fullscreen_visibility's "fullscreen ended: restoring widget"
  branch held the guard while calling position_at_taskbar(), which
  locks state itself. This is what froze the widget process solid
  (confirmed via diagnose log going silent exactly at that line, and
  Get-Process reporting Responding=False) once the earlier monitor-
  scoping fix made the suppress -> restore transition actually fire
  for real instead of being masked by the old bug.

- position_at_taskbar()'s own taskbar-rebind branch called
  invalidate_popup_layout() from inside a state.as_mut() block on the
  same guard, for the same reason. Triggers on taskbar rebinding
  (Explorer restart, monitor/dock changes, first launch).

Both fixed by scoping the lock to just the state mutation, matching
the pattern already used correctly everywhere else in this file.
…00ms poll

sync_fullscreen_visibility only checked TIMER_FULLSCREEN_CHECK's 500ms tick,
so it noticed well after the fact that DWM had dropped this window's
composited layered content during a shell/XAML surface transition (Start
menu, Search, task switches) - captured live via diagnose logging: pixel
dropout correlated with fg_class becoming Windows.UI.Core.CoreWindow or an
empty foreground state, lasting 300-620ms, while IsWindowVisible stayed
true throughout (confirming this is a DWM compositing gap, not our own
suppress logic hiding the window).

Added a system-wide EVENT_SYSTEM_FOREGROUND WinEvent hook that posts a
message (never calls back synchronously - would deadlock the same way the
tray location hook's comment already warns about) to force an immediate
repaint the instant focus changes, instead of waiting up to 500ms to notice.

Also added diagnose logging to taskbar_hwnd_for_settings_index's fallback
path and find_taskbars' primary-exclusion branch, from chasing an earlier,
separate taskbar-rebind report that turned out not to reproduce again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant