Skip to content

Commit

Permalink
minor fixes (renames, easier to read code)
Browse files Browse the repository at this point in the history
- manifest update
- also, a todo list in README.md
  • Loading branch information
smalls committed Nov 15, 2017
1 parent 8cc5279 commit c37a03c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
16 changes: 16 additions & 0 deletions extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,19 @@ event-page.js#filterResponse(). Notable inclusions are
but check the code for the authoritative list.

The extension automatically tags [Product] with #shortlist.

## todos

Nothing is ever complete.

- [ ] When initializing the extension, pull in data from all open tabs. The
current version depends on the extension being on from browser startup, and
there's a hook from each tab that's opened to send over entities from that
tab.
- [ ] Tags are how we differentiate between views. Once firebase supports it,
put additional tags on all views created by the extension (as many as
possible - the more information in tags, the better matches we'll be able to
find).
- [ ] De-duplicate data - some pages embed entities multiple times, and
reloads can cause the same information to be in the view many times. Keep
track of what we've sent and only send new entities.
20 changes: 7 additions & 13 deletions extension/event-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
let arc;
let ams;
let amKey;
let manifestUrls = [];
let manifest;
let additionalManifestUrls = [];
let loader;
async function init() {
loader = new Arcs.BrowserLoader(chrome.runtime.getURL('/'));

// The goal here is that this list contains all known schema
manifest = Arcs.Manifest.parse(`
manifest = await Arcs.Manifest.parse(`
import '${cdn}/entities/entities.manifest'`,
{fileName: 'inline', path: 'inline', loader: loader});
arc = new Arcs.Arc({id: 'browser/'+chrome.runtime.id, context: manifest});
Expand Down Expand Up @@ -81,7 +81,6 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {


function updateBadge(tabId, response) {

// TODO(smalls) - currently, we're using the presence of entities from the
// page as a proxy for an interesting arc being available. In the future we
// should run the suggestinator for a more comprehensive view.
Expand All @@ -97,7 +96,6 @@ function updateBadge(tabId, response) {
}

function filterResponse(response) {

if (!response) return response;

let ret = response.filter(entity => {
Expand All @@ -122,19 +120,16 @@ function loadManifest(url) {
}

function updateArc(tabId, response) {

if (!response) return;
console.log('updating tab '+tabId+' with response', response);

let entities = {};

let manifests = [manifest];
manifests = manifests.concat(
response.filter(r => r['@type']==manifestType).map(r => loadManifest(r['url']))
);
manifestUrls = response.filter(r => r['@type']==manifestType).map(r => r['url']);
additionalManifestUrls = response.filter(r => r['@type']==manifestType).map(r => r['url']);
additionalManifests = additionalManifestUrls.map(url => loadManifest(url));

Promise.all(manifests).then(manifests => {
Promise.all(additionalManifests).then(manifests => {
manifests.push(manifest);
response.filter(r => r['@type']!=manifestType).forEach(r => {
fqTypeName = r['@type'];
shortTypeName = fqTypeName.startsWith('http') && fqTypeName.includes('/') ?
Expand Down Expand Up @@ -174,7 +169,6 @@ function updateArc(tabId, response) {
}

chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {

if (changeInfo.status && 'complete'==changeInfo.status) {
// fire a message to content-script.js
chrome.tabs.sendMessage(tabId, {method: 'extractEntities'}, response => {
Expand Down Expand Up @@ -229,7 +223,7 @@ chrome.runtime.onMessage.addListener(
return;
}

sendResponse({amKey: amKey, manifestUrls: manifestUrls});
sendResponse({amKey: amKey, manifestUrls: additionalManifestUrls});
}

);
2 changes: 1 addition & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
"browser_action": {
"default_popup": "popup.html"
},
"content_security_policy": "script-src 'self' https://polymerlabs.github.io/ https://www.gstatic.com/ https://*.firebaseio.com/ 'sha256-rdk56h4D+jfInKWMNE+DL5C923/KiX9j3/l0Cdvgj0c=' 'sha256-UhKb6ALfS/wBC46s4Gf/MkECcgTkd8muXg/DEdOKuwY=' 'sha256-kGt7pe+NmkSy/BDLiKL9UIawR2wD4aT800EWK2FVCU8='; object-src 'self'"
"content_security_policy": "script-src 'self' https://polymerlabs.github.io/ https://www.gstatic.com/ https://*.firebaseio.com/ 'sha256-rdk56h4D+jfInKWMNE+DL5C923/KiX9j3/l0Cdvgj0c=' 'sha256-UhKb6ALfS/wBC46s4Gf/MkECcgTkd8muXg/DEdOKuwY=' 'sha256-mpv4jXBf67t0vGyjzIY7oBlP/WKz7QG//3pkwtSJp2c='; object-src 'self'"
}

0 comments on commit c37a03c

Please sign in to comment.