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: register listeners sync #2350

Merged
merged 1 commit into from
Apr 16, 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
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