Skip to content

Commit 58ada97

Browse files
committed
Open DevTools window to left, right, bottom or as a chrome panel
Related to #24.
1 parent ea67426 commit 58ada97

File tree

5 files changed

+79
-34
lines changed

5 files changed

+79
-34
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"no-undef": 0,
2727
"id-length": 0,
2828
"indent": [2, 2, {"SwitchCase": 1}],
29-
"new-cap": [2, { "capIsNewExceptions": ["Test"] }]
29+
"new-cap": [2, { "capIsNewExceptions": ["Test"] }],
30+
"default-case": 0
3031
},
3132
"plugins": [
3233
"react"
Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import openDevToolsWindow from './openWindow';
12
import { MENU_DEVTOOLS } from '../../../app/constants/ContextMenus.js';
2-
let windows = {devtools: 0};
33

44
function addToMenu(id, title, contexts, onClick) {
55
chrome.contextMenus.create({
@@ -11,37 +11,6 @@ function addToMenu(id, title, contexts, onClick) {
1111
});
1212
}
1313

14-
function focusIfExist(type, callback) {
15-
if (!windows[type]) {
16-
callback();
17-
} else {
18-
chrome.windows.update(windows[type], {focused: true}, () => {
19-
if (chrome.runtime.lastError) callback();
20-
});
21-
}
22-
}
23-
24-
function popWindow(action, url, type, customOptions) {
25-
focusIfExist(type, () => {
26-
let options = {
27-
type: 'panel',
28-
left: 5, top: 100,
29-
width: 800, height: 700,
30-
...customOptions
31-
};
32-
if (action === 'open') {
33-
options.url = chrome.extension.getURL(url);
34-
chrome.windows.create(options, (win) => {
35-
windows[type] = win.id;
36-
});
37-
}
38-
});
39-
}
40-
41-
export function openDevToolsWindow() {
42-
popWindow('open', 'window.html', 'devtools', {width: 320});
43-
}
44-
4514
export default function createMenu() {
4615
addToMenu(MENU_DEVTOOLS, 'Open Redux DevTools', ['all'], openDevToolsWindow);
4716
}

src/browser/extension/background/messaging.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { onConnect, onMessage, sendToTab } from 'crossmessaging';
22
import syncOptions from '../options/syncOptions';
33
import { MENU_DEVTOOLS } from '../../../app/constants/ContextMenus';
4-
import { openDevToolsWindow } from './contextMenus';
4+
import openDevToolsWindow from './openWindow';
55
let connections = {};
66

77
window.syncOptions = syncOptions; // Used in the options page
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
let windows = {devtools: 0};
2+
let lastPosition = null;
3+
4+
export default function openDevToolsWindow(position) {
5+
function popWindow(action, url, type, customOptions) {
6+
function focusIfExist(callback) {
7+
if (!windows[type]) {
8+
callback();
9+
lastPosition = position;
10+
} else {
11+
let params = {focused: true};
12+
if (lastPosition !== position && position !== 'devtools-panel') params = {...params, ...customOptions};
13+
chrome.windows.update(windows[type], params, () => {
14+
lastPosition = null;
15+
if (chrome.runtime.lastError) callback();
16+
});
17+
}
18+
}
19+
20+
focusIfExist(() => {
21+
let options = {
22+
type: 'popup',
23+
...customOptions
24+
};
25+
if (action === 'open') {
26+
options.url = chrome.extension.getURL(url);
27+
chrome.windows.create(options, (win) => {
28+
windows[type] = win.id;
29+
});
30+
}
31+
});
32+
}
33+
34+
let params = { left: 0, top: 0, width: 320, height: window.screen.availHeight };
35+
switch (position) {
36+
case 'devtools-right':
37+
params.left = window.screen.availWidth - params.width;
38+
break;
39+
case 'devtools-bottom':
40+
params.height = 320;
41+
params.top = window.screen.availHeight - 320;
42+
params.width = window.screen.availWidth;
43+
break;
44+
case 'devtools-panel':
45+
params.type = 'panel';
46+
break;
47+
}
48+
popWindow('open', 'window.html', 'devtools', params);
49+
}

src/browser/extension/manifest.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,32 @@
99
"default_title": "Redux DevTools",
1010
"default_popup": "window.html"
1111
},
12+
"commands": {
13+
"devtools-left": {
14+
"suggested_key": {
15+
"default": "Alt+Shift+Left"
16+
},
17+
"description": "DevTools window to left"
18+
},
19+
"devtools-right": {
20+
"suggested_key": {
21+
"default": "Alt+Shift+Right"
22+
},
23+
"description": "DevTools window to right"
24+
},
25+
"devtools-bottom": {
26+
"suggested_key": {
27+
"default": "Alt+Shift+Down"
28+
},
29+
"description": "DevTools window to bottom"
30+
},
31+
"devtools-panel": {
32+
"suggested_key": {
33+
"default": "Alt+Shift+Up"
34+
},
35+
"description": "DevTools in panel"
36+
}
37+
},
1238
"icons": {
1339
"16": "img/logo/16x16.png",
1440
"48": "img/logo/48x48.png",

0 commit comments

Comments
 (0)