feat: per-account disable/enable toggle for multi-account providers#251
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdded per-account disabled state with persistence and UI controls. Changes
Sequence Diagram(s)sequenceDiagram
participant UI as "SettingsView / AccountRowView"
participant Manager as "AuthManager"
participant FS as "File (account JSON)"
participant Status as "StatusRefresher"
UI->>Manager: toggleAccountDisabled(account)
Manager->>FS: read account JSON
FS-->>Manager: account JSON (including disabled)
Manager->>Manager: flip `disabled` flag
Manager->>FS: write updated JSON
FS-->>Manager: write result (ok / error)
Manager->>Status: refresh auth status
Status-->>UI: updated status (success / failure)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/Sources/AuthStatus.swift`:
- Around line 164-175: In toggleAccountDisabled(_ account: AuthAccount) enforce
the "last enabled account" guardrail inside AuthManager by atomically reading
all accounts (via AuthManager's account list) and refusing to flip an account
from enabled->disabled if it's the only enabled account, returning false;
perform the enable/disable toggle only after that check and write the updated
JSON to disk using an atomic write (e.g., Data.write(to:options: .atomic) or
equivalent) to avoid partial/corrupt files, and ensure the function returns
appropriate failure on race/guardrail violation.
In `@src/Sources/SettingsView.swift`:
- Around line 205-209: The per-provider round-robin logic is using total
accounts instead of only active (non-disabled) accounts; update the UI to use
the computed enabledCount for decisions: replace usages of accounts.count (e.g.,
the showDisableToggle flag passed into AccountRowView and any other place
computing round-robin/summary indicators) with enabledCount and ensure
isLastEnabled logic remains based on enabledCount (e.g., isLastEnabled:
!account.isDisabled && enabledCount <= 1) so the summary/round-robin indicator
reflects only enabled accounts.
- Around line 559-566: The toggleAccountDisabled(_) method currently only
updates the UI on success; update it so when
authManager.toggleAccountDisabled(account) returns false you also set
authResultSuccess = false, set authResultMessage to a clear failure string like
"✗ Failed to toggle \(account.displayName)" (or a localized equivalent), and set
showingAuthResult = true so the user sees an error; keep the existing success
branch unchanged and use the same state variables (authResultSuccess,
authResultMessage, showingAuthResult) to surface the failure.
When multiple accounts are connected for the same provider, each account row now shows a Disable/Enable button. Disabled accounts have their JSON credential file updated with "disabled": true, which CLIProxyAPIPlus already respects by skipping disabled auths during credential selection. - Only shown when 2+ accounts exist (single account uses provider toggle) - Last enabled account cannot be disabled to prevent lockout - Visual indicators: gray dot, strikethrough, "(disabled)" label - Round-robin label shown when multiple accounts are active
f6e7c2f to
febd84a
Compare
|
@ranaroussi any thoughts on this? |
Summary
When multiple accounts are connected for the same provider (e.g., two Claude accounts), users currently have no way to control which accounts are active -- all accounts participate in round-robin. This PR adds a per-account Disable/Enable toggle so users can selectively deactivate individual accounts without removing them.
What it does
"disabled": true/falseto the account's credential JSON file, which CLIProxyAPIPlus already respects (disabled auths are skipped during credential selection)Files changed
SettingsView.swiftAccountRowViewgains disable toggle + visual states;ServiceRowcomputes enabled count and passes guard flagAuthStatus.swiftAuthAccountgainsisDisabledfield;AuthManagergainstoggleAccountDisabled()that reads/writes the credential JSONUse cases
Summary by CodeRabbit