feat: account spend-pace rows and auth self-recovery - #39
Open
oyardena wants to merge 10 commits into
Open
Conversation
oyardena
force-pushed
the
feat/account-usage-rows
branch
from
June 20, 2026 15:54
c87c9e6 to
fa5c927
Compare
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
force-pushed
the
feat/account-usage-rows
branch
from
June 21, 2026 20:08
fa5c927 to
a8be4f8
Compare
- 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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
POST /v1/oauth/token) instead of spawningclaude -p ., avoiding token burn during poll retries.Test plan
cargo build --releaseon Windows (msys64 mingw)claude -p .in diagnose log)_probe_taskbar_context.ps1→Pass: True)