fix: sync in-memory accountManager when toggling enabled status

The first fix (checking enabled flag in getCurrentAccountForFamily) wasn't
enough because the toggle code only updated disk storage, not the in-memory
AccountManager used for request routing.

Added:
1. setAccountEnabled() method to AccountManager
2. Module-level activeAccountManager reference shared between connect and login
3. Toggle code now syncs both disk storage AND in-memory state
This commit is contained in:
Noe
2026-02-06 17:05:41 +00:00
parent ddcee09909
commit c53ca6947c
2 changed files with 15 additions and 0 deletions

View File

@@ -81,6 +81,9 @@ const MAX_TOAST_COOLDOWN_ENTRIES = 100;
let softQuotaToastShown = false;
let rateLimitToastShown = false;
// Module-level reference to AccountManager for access from auth.login
let activeAccountManager: import("./plugin/accounts").AccountManager | null = null;
function cleanupToastCooldowns(): void {
if (rateLimitToastCooldowns.size > MAX_TOAST_COOLDOWN_ENTRIES) {
const now = Date.now();
@@ -998,6 +1001,7 @@ export const createAntigravityPlugin = (providerId: string) => async (
// Note: AccountManager now ensures the current auth is always included in accounts
const accountManager = await AccountManager.loadFromDisk(auth);
activeAccountManager = accountManager;
if (accountManager.getAccountCount() > 0) {
accountManager.requestSaveToDisk();
}
@@ -2288,6 +2292,7 @@ export const createAntigravityPlugin = (providerId: string) => async (
if (acc) {
acc.enabled = acc.enabled === false;
await saveAccounts(existingStorage);
activeAccountManager?.setAccountEnabled(menuResult.toggleAccountIndex, acc.enabled);
console.log(`\nAccount ${acc.email || menuResult.toggleAccountIndex + 1} ${acc.enabled ? 'enabled' : 'disabled'}.\n`);
}
}

View File

@@ -796,6 +796,16 @@ export class AccountManager {
});
}
setAccountEnabled(accountIndex: number, enabled: boolean): boolean {
const account = this.accounts[accountIndex];
if (!account) {
return false;
}
account.enabled = enabled;
this.requestSaveToDisk();
return true;
}
removeAccount(account: ManagedAccount): boolean {
const idx = this.accounts.indexOf(account);
if (idx < 0) {