Add single-provider display mode for widget - #1
Jachaganhio wants to merge 3 commits into
Conversation
Turning off Claude or Codex now hides that provider entirely instead of showing a "Disabled" placeholder. The remaining provider takes the full widget width and shows reset times in every widget size, including small. - UsageSnapshot.visibleProviders filters disabled providers - UsageDashboardView renders a full-width single column when only one provider is visible; both-off state shows a hint instead of blank - In-app dashboard mirrors widget behavior; Save refuses both-off - New previews and regression test for the disabled/hidden behavior - README / README_CN document the new mode Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Shows the Claude-only widget (Codex disabled) with reset times visible in every metric row, confirming the full-width single-column layout described in the README. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Reviewer's GuideThe PR adds single-provider display mode by filtering disabled providers from shared snapshots, rendering the remaining provider at full width with reset times in all widget sizes, handling the both-disabled state in the UI and configuration flow, and covering the behavior with tests, previews, and documentation. Sequence diagram for provider configuration and usage loadingsequenceDiagram
actor User
participant Dashboard as ContentView
participant Config as Configuration
participant Widget as UsageDashboardView
participant Provider as UsageProvider
User->>Dashboard: Toggle provider visibility
Dashboard->>Dashboard: saveConfig()
alt Both providers disabled
Dashboard-->>User: Reject save with status message
else At least one provider enabled
Dashboard->>Config: Save enabled-provider settings
Widget->>Provider: Request enabled provider usage
Widget->>Widget: visibleProviders
Widget-->>User: Render enabled provider(s)
end
Flow diagram for single-provider widget renderingflowchart TD
Snapshot[UsageSnapshot] --> Visible[visibleProviders filters disabled providers]
Visible --> Count{Visible provider count}
Count -->|0| Hint[Show turn-on-provider hint]
Count -->|1| Full[Render one provider full width]
Count -->|2| Existing[Render existing two-provider layout]
Full --> Reset[Show reset times in every widget size]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
🟢 Approval recommended
The changes are cohesive and covered by tests/docs, with only minor performance nits (redundant computed-array recomputation) called out in review comments.
Pull request overview
This PR adds a single-provider display mode for the widget and in-app dashboard by hiding disabled providers (instead of showing a “Disabled” placeholder), expanding the remaining provider to full width, and ensuring reset times appear when a single provider is shown.
Changes:
- Introduce
UsageSnapshot.visibleProvidersto filter out disabled providers and drive UI rendering. - Update widget/in-app layouts to support full-width single-provider rendering plus a both-off “turn one on” hint.
- Add regression coverage, new previews, and documentation updates (EN/CN) for the new configuration behavior.
File summaries
| File | Description |
|---|---|
| Tests/UsageCoreTests/UsageCoreTests.swift | Adds a regression test for filtering/hiding disabled providers and preserving order. |
| Shared/UsageViews.swift | Reworks dashboard layout to render 0/1/2 visible providers appropriately (including solo reset times). |
| Shared/UsageModels.swift | Makes ProviderUsage Identifiable and adds UsageSnapshot.visibleProviders for shared visibility logic. |
| scripts/RenderPreviews.swift | Extends preview rendering to include claude-only/codex-only states and updates the count output. |
| README.md | Documents single-provider mode behavior/config and updates preview generation notes. |
| README_CN.md | Mirrors the single-provider documentation updates in Chinese. |
| ClaudeUsageWidgetExtension/ClaudeUsageWidget.swift | Adds medium widget previews for claude-only/codex-only states. |
| ClaudeUsageWidget/ContentView.swift | Mirrors widget visibility behavior in-app and prevents saving config with both providers disabled. |
Review details
- Files reviewed: 8/9 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if snapshot.visibleProviders.isEmpty { | ||
| Text("Both providers are hidden. Turn one on below to fill the widget.") | ||
| .font(.caption).foregroundStyle(.secondary) | ||
| Spacer() | ||
| } else { | ||
| ForEach(snapshot.visibleProviders) { usage in | ||
| if usage.id != snapshot.visibleProviders.first?.id { Divider() } | ||
| ProviderUsageView(usage: usage) | ||
| } | ||
| } |
| ForEach(providers) { usage in | ||
| if usage.id != providers.first?.id { Divider() } | ||
| ProviderUsageView(usage: usage, compact: compact, showReset: showReset) | ||
| } |
The refactor to ForEach-based provider rendering passed showReset: false for the medium two-column layout. The original code passed no argument there, so it used ProviderUsageView's default of true — the medium widget has always shown reset countdowns with both providers enabled, as the README states. The result was a medium widget whose rows collapsed into the top half with no countdowns and a large empty area below. Single-provider and small/large layouts were unaffected; verified against renders from master. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Follow-up fix pushed (4ecddaf). While testing the built widget I hit a regression I introduced in this PR: the refactor from hand-written provider columns to a The visible effect was a medium widget whose rows collapsed into the top half with no countdowns and a large empty area below. Verified by rendering |
Summary
Turning off Claude or Codex now hides that provider entirely instead of showing a "Disabled" placeholder. The remaining provider takes the full widget width and shows reset times in every widget size, including small.
UsageSnapshot.visibleProvidersfilters out disabled providers (both models unchanged otherwise)UsageDashboardViewrenders a full-width single column when only one provider is visible; both providers still render exactly as before when both are enabledtestDisabledProviderIsHiddenInsteadOfShownAsDisabled)Why
If you only have a Claude subscription (no Codex), the widget previously wasted half its space on a "Codex · Disabled" block. This makes a disabled provider disappear completely so the widget space goes to the provider you actually use.
Compatibility
The two-provider layout is unchanged — verified by existing tests plus a new one asserting
visibleProvidersstill returns both entries, in order, when both are enabled. No changes to the network/parsing layer.Verification
Claude-only widget on my own account (Codex disabled), full width with reset countdowns showing in every row:
swift test(13/13 pass) andxcodebuild(Debug, macOS) both succeed.🤖 Generated with Claude Code
Summary by Sourcery
Support single-provider configurations by hiding disabled providers and expanding the remaining provider throughout the widget and dashboard.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests:
Chores: