Skip to content

Commit

Permalink
Implement options configuration for injecting in Chrome apps and exte…
Browse files Browse the repository at this point in the history
…nsions
  • Loading branch information
zalmoxisus committed Nov 19, 2015
1 parent 9ba546d commit af59fe8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/browser/extension/background/messaging.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { onConnect, onMessage, sendToTab } from 'crossmessaging';
import getOptions from '../options/getOptions';
import { MENU_DEVTOOLS } from '../../../app/constants/ContextMenus.js';
let connections = {};

Expand Down Expand Up @@ -27,13 +28,19 @@ function parseJSON(data) {
}

// Receive message from content script and relay to the devTools page
function messaging(request, sender) {
function messaging(request, sender, sendResponse) {
const tabId = sender.tab ? sender.tab.id : sender.id;
if (tabId) {
if (request.type === 'PAGE_UNLOADED') {
if (connections[ tabId ]) connections[ tabId ].postMessage(naMessage);
return true;
}
if (request.type === 'GET_OPTIONS') {
getOptions(options => {
sendResponse({options: options});
});
return true;
}
const payload = typeof request.payload === 'string' ? parseJSON(request.payload) : request.payload;
if (!payload) return true;
store.liftedStore.setState(payload);
Expand Down
12 changes: 10 additions & 2 deletions src/browser/extension/inject/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@

window.devToolsExtensionID = 'lmhkpmbekcpmknklioeibfkpmmfibljd';

require('./contentScript');
require('./pageScript');
chrome.runtime.sendMessage(window.devToolsExtensionID, { type: 'GET_OPTIONS' }, function(response) {
if (!response.options.inject) {
const urls = response.options.urls.split('\n').join('|');
if (!location.href.match(new RegExp(urls))) return;
}

window.devToolsOptions = response.options;
require('./contentScript');
require('./pageScript');
});
5 changes: 5 additions & 0 deletions src/browser/extension/options/getOptions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
const getOptions = callback => {
if (window.devToolsExtensionID && chrome.runtime.id !== window.devToolsExtensionID) {
callback(window.devToolsOptions);
return;
}

chrome.storage.sync.get({
limit: 50,
timeout: 1,
Expand Down

0 comments on commit af59fe8

Please sign in to comment.