Skip to content

Commit

Permalink
fix: register listeners sync (#2350)
Browse files Browse the repository at this point in the history
  • Loading branch information
reneaaron authored Apr 16, 2023
1 parent 8ec1e5a commit dc61728
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/extension/background-script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ const routeCalls = (
return call;
};

browser.runtime.onMessage.addListener(debugLogger);

// this is the only handler that may and must return a Promise which resolve with the response to the content script
browser.runtime.onMessage.addListener(routeCalls);

// Update the extension icon
browser.tabs.onUpdated.addListener(updateIcon);

// Notify the content script that the tab has been updated.
browser.tabs.onUpdated.addListener(extractLightningData);

// The onInstalled event is fired directly after the code is loaded.
// When we subscribe to that event asynchronously in the init() function it is too late and we miss the event.
browser.runtime.onInstalled.addListener(handleInstalled);

async function init() {
console.info("Loading background script");

Expand All @@ -135,24 +150,9 @@ async function init() {
events.subscribe();
console.info("Events subscribed");

browser.runtime.onMessage.addListener(debugLogger);

// this is the only handler that may and must return a Promise which resolve with the response to the content script
browser.runtime.onMessage.addListener(routeCalls);

// Update the extension icon
browser.tabs.onUpdated.addListener(updateIcon);

// Notify the content script that the tab has been updated.
browser.tabs.onUpdated.addListener(extractLightningData);

console.info("Loading completed");
}

// The onInstalled event is fired directly after the code is loaded.
// When we subscribe to that event asynchronously in the init() function it is too late and we miss the event.
browser.runtime.onInstalled.addListener(handleInstalled);

console.info("Welcome to Alby");
init().then(() => {
if (isFirstInstalled && !state.getState().getAccount()) {
Expand Down

0 comments on commit dc61728

Please sign in to comment.