mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 22:33:35 +00:00
Ensure that initialization and migration only run once (#631)
This commit is contained in:
committed by
GitHub
parent
e5cc3de46d
commit
af7da0e942
@@ -58,6 +58,8 @@ export class StateService<TAccount extends Account = Account>
|
|||||||
|
|
||||||
protected state: State<TAccount> = new State<TAccount>();
|
protected state: State<TAccount> = new State<TAccount>();
|
||||||
|
|
||||||
|
private hasBeenInited: boolean = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected storageService: StorageService,
|
protected storageService: StorageService,
|
||||||
protected secureStorageService: StorageService,
|
protected secureStorageService: StorageService,
|
||||||
@@ -67,11 +69,16 @@ export class StateService<TAccount extends Account = Account>
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
async init(): Promise<void> {
|
async init(): Promise<void> {
|
||||||
|
if (this.hasBeenInited) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (await this.stateMigrationService.needsMigration()) {
|
if (await this.stateMigrationService.needsMigration()) {
|
||||||
await this.stateMigrationService.migrate();
|
await this.stateMigrationService.migrate();
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.initAccountState();
|
await this.initAccountState();
|
||||||
|
this.hasBeenInited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
async initAccountState() {
|
async initAccountState() {
|
||||||
|
|||||||
Reference in New Issue
Block a user