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

fix: duplicated instance of services on browser session restore #1563

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/long-chicken-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels-wallet": patch
---

Fixed duplicated instance of services on browser session restore
8 changes: 8 additions & 0 deletions packages/app/src/systems/CRX/background/communication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ let backgroundService: BackgroundService | null = null;
let vaultService: VaultService | null = null;
let databaseEvents: DatabaseEvents | null = null;

let hasStarted = false;

function onConnectHandler(port: chrome.runtime.Port) {
// Only allow connections from the extension
// This is to prevent other extensions from connecting
Expand All @@ -27,6 +29,7 @@ function onConnectHandler(port: chrome.runtime.Port) {
}

function onSuspendHandler() {
hasStarted = false;
// Handle cleanup before the background script is suspended
backgroundService?.stop();
vaultService?.stop();
Expand All @@ -37,6 +40,11 @@ function onSuspendHandler() {
db.close();
}
function onStartupHandler() {
if (hasStarted) {
console.log('Background scripts have already started');
return;
}
hasStarted = true;
// Handle initialization when the background script starts up
backgroundService = BackgroundService.start(communicationProtocol);
vaultService = VaultService.start(communicationProtocol);
Expand Down
Loading