diff --git a/src/browser/extension/background/contextMenus.js b/src/browser/extension/background/contextMenus.js index 75c94901..14096ee1 100644 --- a/src/browser/extension/background/contextMenus.js +++ b/src/browser/extension/background/contextMenus.js @@ -1,6 +1,6 @@ import openDevToolsWindow from './openWindow'; -export default function createMenu() { +export function createMenu() { const menus = [ { id: 'devtools-left', title: 'To left' }, { id: 'devtools-right', title: 'To right' }, @@ -25,6 +25,10 @@ export default function createMenu() { }); } +export function removeMenu() { + chrome.contextMenus.removeAll(); +} + chrome.contextMenus.onClicked.addListener(({ menuItemId }) => { openDevToolsWindow(menuItemId); }); diff --git a/src/browser/extension/background/index.js b/src/browser/extension/background/index.js index f3ad247d..8c27be36 100644 --- a/src/browser/extension/background/index.js +++ b/src/browser/extension/background/index.js @@ -1,6 +1,7 @@ import configureStore from '../../../app/stores/backgroundStore'; import openDevToolsWindow from './openWindow'; -import createMenu from './contextMenus'; +import { createMenu, removeMenu } from './contextMenus'; +import syncOptions from '../options/syncOptions'; // Expose the extension's store globally to access it from the windows // via chrome.runtime.getBackgroundPage @@ -11,7 +12,17 @@ chrome.commands.onCommand.addListener(shortcut => { openDevToolsWindow(shortcut); }); -// Create the context menu +// Create the context menu when installed chrome.runtime.onInstalled.addListener(() => { - createMenu(); + syncOptions().get(option => { + if (option.showContextMenus) createMenu(); + }); +}); + +// Create or Remove context menu when config changed +chrome.storage.onChanged.addListener(changes => { + if (changes.showContextMenus) { + if (changes.showContextMenus.newValue) createMenu(); + else removeMenu(); + } }); diff --git a/src/browser/extension/options/ContextMenuGroup.js b/src/browser/extension/options/ContextMenuGroup.js new file mode 100644 index 00000000..05e84cd3 --- /dev/null +++ b/src/browser/extension/options/ContextMenuGroup.js @@ -0,0 +1,21 @@ +import React from 'react'; + +export default ({ options, saveOption }) => { + return ( +
+ Context Menu + +
+ saveOption('showContextMenus', e.target.checked)}/> + +
+ Add Redux DevTools to right-click context menu +
+
+
+ ); +}; diff --git a/src/browser/extension/options/Options.js b/src/browser/extension/options/Options.js index 371bf5ff..5ab2e294 100644 --- a/src/browser/extension/options/Options.js +++ b/src/browser/extension/options/Options.js @@ -2,6 +2,7 @@ import React from 'react'; import FilterGroup from './FilterGroup'; import AllowToRunGroup from './AllowToRunGroup'; import MiscellaneousGroup from './MiscellaneousGroup'; +import ContextMenuGroup from './ContextMenuGroup'; export default (props) => (
@@ -9,5 +10,6 @@ export default (props) => ( +
); diff --git a/src/browser/extension/options/syncOptions.js b/src/browser/extension/options/syncOptions.js index b0aad4a0..deb1acad 100644 --- a/src/browser/extension/options/syncOptions.js +++ b/src/browser/extension/options/syncOptions.js @@ -39,7 +39,8 @@ const get = callback => { blacklist: '', shouldCatchErrors: false, inject: true, - urls: '^https?://localhost|0\\.0\\.0\\.0:\\d+\n^https?://.+\\.github\\.io' + urls: '^https?://localhost|0\\.0\\.0\\.0:\\d+\n^https?://.+\\.github\\.io', + showContextMenus: true }, function(items) { options = migrateOldOptions(items); callback(options);