Skip to content

Commit

Permalink
feat: make sure variables references are updated
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurgeron committed Apr 17, 2024
1 parent 79eb3c2 commit 785d9bb
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions packages/app/src/systems/CRX/background/communication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,24 @@ errorBoundary(() => {
communicationProtocol?.addConnection(port);
}
});
let backgroundService = BackgroundService.start(communicationProtocol);
let vaultService = VaultService.start(communicationProtocol);
let databaseEvents = DatabaseEvents.start(communicationProtocol);

const backgroundService = BackgroundService.start(communicationProtocol);
const vaultService = VaultService.start(communicationProtocol);
const databaseEvents = DatabaseEvents.start(communicationProtocol);

chrome.runtime.onMessage.addListener(
(message: DatabaseRestartEvent, _sender, _sendResponse) => {
if (message?.type === 'DB_EVENT') {
if (message?.payload?.event === 'restarted') {
communicationProtocol?.destroy();
communicationProtocol = undefined;
communicationProtocol = new CommunicationProtocol();
backgroundService.restart(communicationProtocol);
vaultService.restart(communicationProtocol);
databaseEvents.restart(communicationProtocol);
}
function restartProtocol(message: DatabaseRestartEvent) {
if (message?.type === 'DB_EVENT') {
if (message?.payload?.event === 'restarted') {
const oldProtocol = communicationProtocol;

communicationProtocol = new CommunicationProtocol();
backgroundService = backgroundService.restart(communicationProtocol);
vaultService = vaultService.restart(communicationProtocol);
databaseEvents = databaseEvents.restart(communicationProtocol);

oldProtocol?.destroy();
}
}
);
}

chrome.runtime.onMessage.addListener(restartProtocol);
});

0 comments on commit 785d9bb

Please sign in to comment.