Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run update migrations on startup rather than update event #1109

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions apps/extension/src/core/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,34 @@ Browser.runtime.onInstalled.addListener(async ({ reason, previousVersion }) => {
const migrationRunner = new MigrationRunner(migrations, true)
await migrationRunner.isComplete
} else if (reason === "update") {
// Main migrations will occur on login to ensure that password is present for any migrations that require it
const sub = passwordStore.isLoggedIn.subscribe(async (isLoggedIn) => {
if (isLoggedIn) {
const password = passwordStore.getPassword()
if (!password) return
// instantiate the migrations runner with migrations to run
// this will run any migrations that have not already been run
const migrationRunner = new MigrationRunner(migrations, false, {
password,
})

await migrationRunner.isComplete
// only do this once
sub.unsubscribe()
}
})
// run any legacy migrations
if (previousVersion) {
await migrateConnectAllSubstrate(previousVersion)
}
}
})

// run migrations on first login after startup
// Migrations occur on login to ensure that password is present for any migrations that require it
const migrationSub = passwordStore.isLoggedIn.subscribe(async (isLoggedIn) => {
if (isLoggedIn) {
const password = passwordStore.getPassword()
if (!password) {
Sentry.captureMessage("Unabe to run migrations, no password present")
return
}
// instantiate the migrations runner with migrations to run
// this will run any migrations that have not already been run
const migrationRunner = new MigrationRunner(migrations, false, {
password,
})

await migrationRunner.isComplete
// only do this once
migrationSub.unsubscribe()
}
})

// listen to all messages and handle appropriately
Browser.runtime.onConnect.addListener((_port): void => {
// only listen to what we know about
Expand Down