perf(bind): speed up account bind detection and runtime sync
Replace the 1.8s polling interval with a 650ms tick plus a debounced navigation-driven detect, listen for page-title-updated to catch SPA transitions, and flush the session asynchronously. The bind handler now optimistically seeds the runtime account list via noteRuntimeAccountBound and fires the full server refresh in the background, so the UI reflects the new binding without waiting on a round-trip. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1058,6 +1058,37 @@ export async function refreshRuntimeAccounts(): Promise<void> {
|
||||
await syncAccounts("manual");
|
||||
}
|
||||
|
||||
export function noteRuntimeAccountBound(account: DesktopAccountInfo): void {
|
||||
const normalizedAccount: DesktopAccountInfo = {
|
||||
...account,
|
||||
platform_uid: normalizeAccountPlatformUid(account.platform_uid) || account.platform_uid,
|
||||
};
|
||||
const existingIndex = state.accounts.findIndex((item) =>
|
||||
item.id === normalizedAccount.id
|
||||
|| (
|
||||
item.platform === normalizedAccount.platform
|
||||
&& sameAccountPlatformUid(item.platform_uid, normalizedAccount.platform_uid)
|
||||
),
|
||||
);
|
||||
|
||||
if (existingIndex >= 0) {
|
||||
state.accounts = state.accounts.map((item, index) =>
|
||||
index === existingIndex ? normalizedAccount : item,
|
||||
);
|
||||
} else {
|
||||
state.accounts = [normalizedAccount, ...state.accounts];
|
||||
}
|
||||
|
||||
state.accountProfiles.set(normalizedAccount.id, {
|
||||
platformUid: normalizedAccount.platform_uid,
|
||||
displayName: normalizedAccount.display_name,
|
||||
avatarUrl: normalizedAccount.avatar_url,
|
||||
});
|
||||
state.lastAccountsSyncAt = Date.now();
|
||||
syncTrackedAccounts(state.accounts.map((item) => accountIdentityFromDesktopAccount(item)));
|
||||
refreshAccountNames();
|
||||
}
|
||||
|
||||
export async function unbindRuntimeAccount(accountId: string, syncVersion: number): Promise<void> {
|
||||
const matchedAccount = state.accounts.find((item) => item.id === accountId) ?? null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user