Skip to content

Commit

Permalink
List devices from simulatort
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Dec 25, 2023
1 parent b1cd865 commit a46f83f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion webextensions/common/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ async function updateDevices() {
if (updateDevices.updating)
return;
updateDevices.updating = true;
await waitUntilDeviceInfoInitialized();
const [devicesFromSimulator] = await Promise.all([
browser.runtime.sendMessage(SEND_TABS_SIMULATOR_ID, { type: 'list-devices' }),
waitUntilDeviceInfoInitialized(),
]);

const remote = clone(configs.syncDevices);
const local = clone(configs.syncDevicesLocalCache);
Expand All @@ -201,6 +204,19 @@ async function updateDevices() {
}
}

if (devicesFromSimulator) {
const knownDeviceIdsFromSimulator = new Set(Object.values(local).map(device => device.simulatorId).filter(id => !!id));
for (const deviceFromSimulator of devicesFromSimulator) {
if (knownDeviceIdsFromSimulator.has(deviceFromSimulator.id))
continue;
const localId = `device-from-simulator:${deviceFromSimulator.id}`;
local[localId] = {
...deviceFromSimulator,
id: localId,
};
}
}

for (const [id, info] of Object.entries(local)) {
if (id in remote ||
id == mMyDeviceInfo.id)
Expand Down

0 comments on commit a46f83f

Please sign in to comment.