Skip to content

Commit 60219a9

Browse files
committed
Provide an option to hide context menu
1 parent 3a97c1c commit 60219a9

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

src/browser/extension/background/contextMenus.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import openDevToolsWindow from './openWindow';
22

3-
export default function createMenu() {
3+
export function createMenu() {
44
const menus = [
55
{ id: 'devtools-left', title: 'To left' },
66
{ id: 'devtools-right', title: 'To right' },
@@ -25,6 +25,10 @@ export default function createMenu() {
2525
});
2626
}
2727

28+
export function removeMenu() {
29+
chrome.contextMenus.removeAll();
30+
}
31+
2832
chrome.contextMenus.onClicked.addListener(({ menuItemId }) => {
2933
openDevToolsWindow(menuItemId);
3034
});
Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import configureStore from '../../../app/stores/backgroundStore';
22
import openDevToolsWindow from './openWindow';
3-
import createMenu from './contextMenus';
3+
import { createMenu, removeMenu } from './contextMenus';
4+
import syncOptions from '../options/syncOptions';
45

56
// Expose the extension's store globally to access it from the windows
67
// via chrome.runtime.getBackgroundPage
@@ -11,7 +12,17 @@ chrome.commands.onCommand.addListener(shortcut => {
1112
openDevToolsWindow(shortcut);
1213
});
1314

14-
// Create the context menu
15+
// Create the context menu when installed
1516
chrome.runtime.onInstalled.addListener(() => {
16-
createMenu();
17+
syncOptions().get(option => {
18+
if (option.showContextMenus) createMenu();
19+
});
20+
});
21+
22+
// Create or Remove context menu when config changed
23+
chrome.storage.onChanged.addListener(changes => {
24+
if (changes.showContextMenus) {
25+
if (changes.showContextMenus.newValue) createMenu();
26+
else removeMenu();
27+
}
1728
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react';
2+
3+
export default ({ options, saveOption }) => {
4+
return (
5+
<fieldset className="option-group">
6+
<legend className="option-group__title">Context Menu</legend>
7+
8+
<div className="option option_type_checkbox">
9+
<input className="option__element"
10+
id="showContextMenus"
11+
type="checkbox"
12+
checked={options.showContextMenus}
13+
onChange={(e) => saveOption('showContextMenus', e.target.checked)}/>
14+
<label className="option__label" htmlFor="showContextMenus">Add Context Menus</label>
15+
<div className="option__hint">
16+
Add Redux DevTools to right-click context menu
17+
</div>
18+
</div>
19+
</fieldset>
20+
);
21+
};

src/browser/extension/options/Options.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import React from 'react';
22
import FilterGroup from './FilterGroup';
33
import AllowToRunGroup from './AllowToRunGroup';
44
import MiscellaneousGroup from './MiscellaneousGroup';
5+
import ContextMenuGroup from './ContextMenuGroup';
56

67
export default (props) => (
78
<div>
89
<div style={{ color: 'red' }}>Setting options here is discouraged, and will not be possible in the next major release. Please <a href="https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Arguments.md" target="_blank" style={{ color: 'red' }}>specify them as parameters</a>. See <a href="https://github.com/zalmoxisus/redux-devtools-extension/issues/296" target="_blank" style={{ color: 'red' }}>the issue</a> for more details.<br /> <hr /></div>
910
<FilterGroup {...props} />
1011
<AllowToRunGroup {...props} />
1112
<MiscellaneousGroup {...props} />
13+
<ContextMenuGroup {...props} />
1214
</div>
1315
);

src/browser/extension/options/syncOptions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ const get = callback => {
3939
blacklist: '',
4040
shouldCatchErrors: false,
4141
inject: true,
42-
urls: '^https?://localhost|0\\.0\\.0\\.0:\\d+\n^https?://.+\\.github\\.io'
42+
urls: '^https?://localhost|0\\.0\\.0\\.0:\\d+\n^https?://.+\\.github\\.io',
43+
showContextMenus: true
4344
}, function(items) {
4445
options = migrateOldOptions(items);
4546
callback(options);

0 commit comments

Comments
 (0)