Skip to content

Commit

Permalink
Register listeners at top level for Manifest V3
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Jan 24, 2024
1 parent 0dbea1f commit b1b5c50
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions webextensions/common/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ function onConfigChanged(key, value = undefined) {
}
}

browser.runtime.onMessageExternal.addListener((message, sender) => {
if (!initialized ||
!message ||
typeof message != 'object' ||
typeof message.type != 'string' ||
sender.id != SEND_TABS_SIMULATOR_ID)
return;

switch (message.type) {
case 'ready':
browser.runtime.sendMessage(SEND_TABS_SIMULATOR_ID, { type: 'register-self' });
case 'device-added':
case 'device-updated':
case 'device-removed':
updateSelf();
break;
}
});

export async function init() {
configs.$addObserver(onConfigChanged); // we need to register the listener to collect pre-sent changes
await configs.$loaded;
Expand All @@ -111,23 +130,6 @@ export async function init() {
preChanges = [];

browser.runtime.sendMessage(SEND_TABS_SIMULATOR_ID, { type: 'register-self' });
browser.runtime.onMessageExternal.addListener((message, sender) => {
if (!message ||
typeof message != 'object' ||
typeof message.type != 'string' ||
sender.id != SEND_TABS_SIMULATOR_ID)
return;

switch (message.type) {
case 'ready':
browser.runtime.sendMessage(SEND_TABS_SIMULATOR_ID, { type: 'register-self' });
case 'device-added':
case 'device-updated':
case 'device-removed':
updateSelf();
break;
}
});
}

export async function generateDeviceInfo({ name, icon } = {}) {
Expand Down

0 comments on commit b1b5c50

Please sign in to comment.