-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: receive each advisory info separatly (#32)
fixes #26 depends on #30 First, I moved from `message` communication to `port` communication, as described [here](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts#choosing_between_one-off_messages_and_connection-based_messaging). Then, I split the advisories fetching to send a message when each advisory info is fetched, instead of aggregating them all together. --------- Co-authored-by: jossef <jossef12@gmail.com>
- Loading branch information
Showing
13 changed files
with
107 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { listen } from './background/bridge'; | ||
import { listen } from './background/background-events'; | ||
|
||
listen(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { REQUEST_PACKAGE_INFO_EVENT, RESPONSE_PACKAGE_INFO_EVENT } from '../events-shared'; | ||
import advisories from './advisory/index'; | ||
|
||
const listener = async ({ type, detail }, port) => { | ||
if (type === REQUEST_PACKAGE_INFO_EVENT) { | ||
const promises = await advisories(detail); | ||
Object.entries(promises).forEach(([part, promise]) => { | ||
promise.then((info) => { | ||
port.postMessage({ | ||
type: RESPONSE_PACKAGE_INFO_EVENT, | ||
detail: { | ||
packageId: detail, | ||
part, | ||
info, | ||
}, | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
export const listen = () => { | ||
chrome.runtime.onConnect.addListener((port) => { | ||
port.onMessage.addListener(listener); | ||
}); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
import { mountContentScript } from './content'; | ||
import { getPackageInfo } from './content/bridge'; | ||
import { sendPackageInfoToWebapp } from './content/content-events'; | ||
import { fetchPackageInfo } from './content/content-events'; | ||
import { findRanges } from './content/stackoverflow/finder'; | ||
import { addIndicator } from './content/stackoverflow/indicator'; | ||
|
||
mountContentScript(async () => { | ||
const findings = findRanges(document.body); | ||
console.debug({ findings }); | ||
|
||
findings.reduce((acc, current) => { | ||
const { type, name } = current; | ||
if (acc[type + '_' + name]) return acc; | ||
let processed = {}; | ||
findings.forEach(({ range, ...packageId }) => { | ||
addIndicator(range, packageId); | ||
let packageKey = `${packageId.type}/${packageId.name}`; | ||
if (processed[packageKey]) { | ||
return; | ||
} | ||
|
||
getPackageInfo(find).then(sendPackageInfoToWebapp); | ||
acc[type + '_' + name] = true; | ||
return acc; | ||
}, {}); | ||
|
||
findings.forEach(addIndicator); | ||
processed[packageKey] = true; | ||
fetchPackageInfo(packageId); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
export const addIndicator = async ({ range, ...packageID }) => { | ||
export const addIndicator = async (range, packageID) => { | ||
console.debug('Adding indicator for', packageID); | ||
|
||
const indicator = document.createElement('overlay-indicator'); | ||
indicator.setAttribute('overlay-indicator-package-type', packageID.type); | ||
indicator.setAttribute('overlay-indicator-package-name', packageID.name); | ||
indicator.appendChild(range.extractContents()); | ||
range.insertNode(indicator); | ||
|
||
// TODO: handle info for package, from inside the component or from store | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.