1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-27 18:13:29 +00:00

Deduplicate prompts

This commit is contained in:
Bernd Schoolmann
2025-10-22 13:50:55 +02:00
parent c16d1f8fd2
commit 96df6f1a9e
9 changed files with 37 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
import { combineLatest, map, switchMap, of, firstValueFrom, filter, debounceTime, tap } from "rxjs";
import { combineLatest, map, switchMap, of, firstValueFrom, filter, tap, delay } from "rxjs";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
@@ -26,7 +26,7 @@ export const ENCRYPTED_MIGRATION_DISMISSED = new UserKeyDefinition<Date>(
clearOn: [],
},
);
const DISMISS_TIME_HOURS = 24;
const DISMISS_TIME_HOURS = 0;
type UserSyncData = {
userId: UserId;
@@ -41,6 +41,8 @@ type UserSyncData = {
export class DefaultEncryptedMigrationsSchedulerService
implements EncryptedMigrationsSchedulerService
{
isMigrating = false;
constructor(
private syncService: SyncService,
private accountService: AccountService,
@@ -68,10 +70,9 @@ export class DefaultEncryptedMigrationsSchedulerService
this.authService.authStatusFor$(userId),
this.syncService.lastSync$(userId),
]).pipe(
// Prevent double emissions from frequent state changes during login/unlock from showing overlapping prompts
debounceTime(2000),
filter(([authStatus]) => authStatus === AuthenticationStatus.Unlocked),
map(([, lastSync]) => ({ userId, lastSync }) as UserSyncData),
delay(5_000),
tap(({ userId }) => this.runMigrationsIfNeeded(userId)),
),
),
@@ -87,6 +88,14 @@ export class DefaultEncryptedMigrationsSchedulerService
return;
}
if (this.isMigrating || (await this.encryptedMigrator.isRunningMigrations())) {
this.logService.info(
`[EncryptedMigrationsScheduler] Skipping migration check for user ${userId} because migrations are already in progress`,
);
return;
}
this.isMigrating = true;
switch (await this.encryptedMigrator.needsMigrations(userId)) {
case "noMigrationNeeded":
this.logService.info(
@@ -108,6 +117,7 @@ export class DefaultEncryptedMigrationsSchedulerService
await this.runMigrationsWithoutInteraction(userId);
break;
}
this.isMigrating = false;
}
private async runMigrationsWithoutInteraction(userId: UserId): Promise<void> {

View File

@@ -520,6 +520,7 @@ const safeProviders: SafeProvider[] = [
LogService,
ConfigService,
MasterPasswordServiceAbstraction,
SyncService,
],
}),
safeProvider({
@@ -868,7 +869,6 @@ const safeProviders: SafeProvider[] = [
AuthServiceAbstraction,
StateProvider,
SecurityStateService,
KdfConfigService,
],
}),
safeProvider({