Skip to content

Commit 5821cf6

Browse files
committed
Choose window position from context menu
1 parent c47c37b commit 5821cf6

File tree

4 files changed

+31
-23
lines changed

4 files changed

+31
-23
lines changed

src/app/constants/ContextMenus.js

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
import openDevToolsWindow from './openWindow';
2-
import { MENU_DEVTOOLS } from '../../../app/constants/ContextMenus.js';
32

4-
function addToMenu(id, title, contexts, onClick) {
5-
chrome.contextMenus.create({
6-
id: id,
7-
title: title,
8-
contexts: contexts,
9-
enabled: false,
10-
onclick: onClick
3+
const menus = [
4+
{ id: 'devtools-left', title: 'To left (Alt+Shift+Left arrow)' },
5+
{ id: 'devtools-right', title: 'To right (Alt+Shift+Right arrow)' },
6+
{ id: 'devtools-bottom', title: 'To bottom (Alt+Shift+Down arrow)' },
7+
{ id: 'devtools-panel', title: 'In panel (Alt+Shift+Top arrow)' }
8+
];
9+
10+
let pageUrl;
11+
let pageTab;
12+
13+
export default function createMenu(forUrl, tabId) {
14+
if (typeof tabId !== 'number' || tabId === pageTab) return;
15+
16+
let url = forUrl;
17+
let hash = forUrl.indexOf('#');
18+
if (hash !== -1) url = forUrl.substr(0, hash);
19+
if (pageUrl === url) return;
20+
pageUrl = url; pageTab = tabId;
21+
chrome.contextMenus.removeAll();
22+
23+
menus.forEach(({ id, title }) => {
24+
chrome.contextMenus.create({
25+
id: id,
26+
title: title,
27+
contexts: ['all'],
28+
documentUrlPatterns: [url],
29+
onclick: () => { openDevToolsWindow(id); }
30+
});
1131
});
12-
}
1332

14-
export default function createMenu() {
15-
addToMenu(MENU_DEVTOOLS, 'Open Redux DevTools', ['all'], openDevToolsWindow);
33+
chrome.pageAction.show(tabId);
1634
}

src/browser/extension/background/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import createDevStore from '../../../app/store/createDevStore.js';
22
import openDevToolsWindow from './openWindow';
3-
import createMenu from './contextMenus';
43
import { toContentScript } from './messaging';
54

65
const store = createDevStore((action) => {
76
toContentScript(action);
87
});
98

10-
createMenu();
11-
129
window.store = store;
1310

1411
chrome.commands.onCommand.addListener(shortcut => {

src/browser/extension/background/messaging.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { onConnect, onMessage, sendToTab } from 'crossmessaging';
22
import syncOptions from '../options/syncOptions';
3-
import { MENU_DEVTOOLS } from '../../../app/constants/ContextMenus';
3+
import createMenu from './contextMenus';
44
import openDevToolsWindow from './openWindow';
55
let connections = {};
66

@@ -53,13 +53,7 @@ function messaging(request, sender, sendResponse) {
5353
store.liftedStore.setState(payload);
5454
if (request.init) {
5555
store.id = tabId;
56-
if (typeof tabId === 'number') {
57-
let url = sender.url;
58-
let hash = url.indexOf('#');
59-
if (hash !== -1) url = url.substr(0, hash);
60-
chrome.contextMenus.update(MENU_DEVTOOLS, {documentUrlPatterns: [url], enabled: true});
61-
chrome.pageAction.show(tabId);
62-
}
56+
createMenu(sender.url, tabId);
6357
}
6458
if (tabId in connections) {
6559
connections[ tabId ].postMessage({payload: payload});

0 commit comments

Comments
 (0)