mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-06-27 16:33:04 +03:00
Get opening in a separate window working
This commit is contained in:
parent
fb0c92df87
commit
08eeb5ad96
|
@ -10,14 +10,8 @@
|
||||||
"default_popup": "devpanel.html#popup"
|
"default_popup": "devpanel.html#popup"
|
||||||
},
|
},
|
||||||
"commands": {
|
"commands": {
|
||||||
"devtools-left": {
|
"devtools-window": {
|
||||||
"description": "DevTools window to left"
|
"description": "DevTools window"
|
||||||
},
|
|
||||||
"devtools-right": {
|
|
||||||
"description": "DevTools window to right"
|
|
||||||
},
|
|
||||||
"devtools-bottom": {
|
|
||||||
"description": "DevTools window to bottom"
|
|
||||||
},
|
},
|
||||||
"devtools-remote": {
|
"devtools-remote": {
|
||||||
"description": "Remote DevTools"
|
"description": "Remote DevTools"
|
||||||
|
|
|
@ -18,7 +18,7 @@ import {
|
||||||
TopButtons,
|
TopButtons,
|
||||||
} from '@redux-devtools/app';
|
} from '@redux-devtools/app';
|
||||||
import { GoBroadcast } from 'react-icons/go';
|
import { GoBroadcast } from 'react-icons/go';
|
||||||
import { MdBorderBottom, MdBorderLeft, MdBorderRight } from 'react-icons/md';
|
import { MdOutlineWindow } from 'react-icons/md';
|
||||||
import type { Position } from '../pageScript/api/openWindow';
|
import type { Position } from '../pageScript/api/openWindow';
|
||||||
import type { SingleMessage } from '../background/store/apiMiddleware';
|
import type { SingleMessage } from '../background/store/apiMiddleware';
|
||||||
|
|
||||||
|
@ -98,31 +98,13 @@ class Actions extends Component<Props> {
|
||||||
<DispatcherButton dispatcherIsOpen={this.props.dispatcherIsOpen} />
|
<DispatcherButton dispatcherIsOpen={this.props.dispatcherIsOpen} />
|
||||||
)}
|
)}
|
||||||
<Divider />
|
<Divider />
|
||||||
{!window.isElectron && position !== '#left' && (
|
{!window.isElectron && (
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
this.openWindow('left');
|
this.openWindow('window');
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<MdBorderLeft />
|
<MdOutlineWindow />
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{!window.isElectron && position !== '#right' && (
|
|
||||||
<Button
|
|
||||||
onClick={() => {
|
|
||||||
this.openWindow('right');
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<MdBorderRight />
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{!window.isElectron && position !== '#bottom' && (
|
|
||||||
<Button
|
|
||||||
onClick={() => {
|
|
||||||
this.openWindow('bottom');
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<MdBorderBottom />
|
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{!window.isElectron && (
|
{!window.isElectron && (
|
||||||
|
|
|
@ -2,29 +2,23 @@ import openDevToolsWindow, { DevToolsPosition } from './openWindow';
|
||||||
|
|
||||||
export function createMenu() {
|
export function createMenu() {
|
||||||
const menus = [
|
const menus = [
|
||||||
{ id: 'devtools-left', title: 'To left' },
|
{ id: 'devtools-window', title: 'Open in a window' },
|
||||||
{ id: 'devtools-right', title: 'To right' },
|
|
||||||
{ id: 'devtools-bottom', title: 'To bottom' },
|
|
||||||
{
|
|
||||||
id: 'devtools-panel',
|
|
||||||
title: 'Open in a panel (enable in browser settings)',
|
|
||||||
},
|
|
||||||
{ id: 'devtools-remote', title: 'Open Remote DevTools' },
|
{ id: 'devtools-remote', title: 'Open Remote DevTools' },
|
||||||
];
|
];
|
||||||
|
|
||||||
let shortcuts: { [commandName: string]: string | undefined } = {};
|
let shortcuts: { [commandName: string]: string | undefined } = {};
|
||||||
chrome.commands.getAll((commands) => {
|
chrome.commands.getAll((commands) => {
|
||||||
commands.forEach(({ name, shortcut }) => {
|
for (const { name, shortcut } of commands) {
|
||||||
shortcuts[name!] = shortcut;
|
shortcuts[name!] = shortcut;
|
||||||
});
|
}
|
||||||
|
|
||||||
menus.forEach(({ id, title }) => {
|
for (const { id, title } of menus) {
|
||||||
chrome.contextMenus.create({
|
chrome.contextMenus.create({
|
||||||
id: id,
|
id: id,
|
||||||
title: title + (shortcuts[id] ? ' (' + shortcuts[id] + ')' : ''),
|
title: title + (shortcuts[id] ? ' (' + shortcuts[id] + ')' : ''),
|
||||||
contexts: ['all'],
|
contexts: ['all'],
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,83 +1,34 @@
|
||||||
export type DevToolsPosition =
|
export type DevToolsPosition = 'devtools-window' | 'devtools-remote';
|
||||||
| 'devtools-left'
|
|
||||||
| 'devtools-right'
|
|
||||||
| 'devtools-bottom'
|
|
||||||
| 'devtools-panel'
|
|
||||||
| 'devtools-remote';
|
|
||||||
|
|
||||||
let windows: { [K in DevToolsPosition]?: number } = {};
|
let windows: { [K in DevToolsPosition]?: number } = {};
|
||||||
let lastPosition: DevToolsPosition | null = null;
|
|
||||||
|
|
||||||
export default function openDevToolsWindow(position: DevToolsPosition) {
|
export default function openDevToolsWindow(position: DevToolsPosition) {
|
||||||
function popWindow(
|
if (!windows[position]) {
|
||||||
action: string,
|
createWindow(position);
|
||||||
url: string,
|
} else {
|
||||||
customOptions: chrome.windows.CreateData & chrome.windows.UpdateInfo,
|
chrome.windows.update(windows[position]!, { focused: true }, () => {
|
||||||
) {
|
if (chrome.runtime.lastError) createWindow(position);
|
||||||
function focusIfExist(callback: () => void) {
|
|
||||||
if (!windows[position]) {
|
|
||||||
callback();
|
|
||||||
lastPosition = position;
|
|
||||||
} else {
|
|
||||||
let params = { focused: true };
|
|
||||||
if (lastPosition !== position && position !== 'devtools-panel') {
|
|
||||||
params = { ...params, ...customOptions };
|
|
||||||
}
|
|
||||||
chrome.windows.update(windows[position]!, params, () => {
|
|
||||||
lastPosition = null;
|
|
||||||
if (chrome.runtime.lastError) callback();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
focusIfExist(() => {
|
|
||||||
let options: chrome.windows.CreateData = {
|
|
||||||
type: 'popup',
|
|
||||||
...customOptions,
|
|
||||||
};
|
|
||||||
if (action === 'open') {
|
|
||||||
options.url = chrome.extension.getURL(
|
|
||||||
url + '#' + position.substr(position.indexOf('-') + 1),
|
|
||||||
);
|
|
||||||
chrome.windows.create(options, (win) => {
|
|
||||||
windows[position] = win!.id;
|
|
||||||
if (navigator.userAgent.indexOf('Firefox') !== -1) {
|
|
||||||
chrome.windows.update(win!.id!, {
|
|
||||||
focused: true,
|
|
||||||
...customOptions,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
let params: chrome.windows.CreateData & chrome.windows.UpdateInfo = {
|
|
||||||
left: 0,
|
function createWindow(position: DevToolsPosition) {
|
||||||
top: 0,
|
const url = chrome.runtime.getURL(getPath(position));
|
||||||
width: 380,
|
chrome.windows.create({ type: 'popup', url }, (win) => {
|
||||||
height: window.screen.availHeight,
|
windows[position] = win!.id;
|
||||||
};
|
if (navigator.userAgent.indexOf('Firefox') !== -1) {
|
||||||
let url = 'devpanel.html';
|
chrome.windows.update(win!.id!, { focused: true });
|
||||||
switch (position) {
|
}
|
||||||
case 'devtools-right':
|
});
|
||||||
params.left =
|
}
|
||||||
(window.screen as unknown as { availLeft: number }).availLeft +
|
|
||||||
window.screen.availWidth -
|
function getPath(position: DevToolsPosition) {
|
||||||
params.width!;
|
switch (position) {
|
||||||
break;
|
case 'devtools-window':
|
||||||
case 'devtools-bottom':
|
return 'devpanel.html';
|
||||||
params.height = 420;
|
case 'devtools-remote':
|
||||||
params.top = window.screen.height - params.height;
|
return 'remote.html';
|
||||||
params.width = window.screen.availWidth;
|
default:
|
||||||
break;
|
throw new Error(`Unrecognized position: ${position}`);
|
||||||
case 'devtools-panel':
|
}
|
||||||
params.type = 'panel';
|
|
||||||
break;
|
|
||||||
case 'devtools-remote':
|
|
||||||
params = { width: 850, height: 600 };
|
|
||||||
url = 'remote.html';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
popWindow('open', url, params);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -490,12 +490,8 @@ function messaging<S, A extends Action<string>>(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (request.type === 'OPEN') {
|
if (request.type === 'OPEN') {
|
||||||
let position: DevToolsPosition = 'devtools-left';
|
let position: DevToolsPosition = 'devtools-window';
|
||||||
if (
|
if (['remote', 'window'].includes(request.position)) {
|
||||||
['remote', 'panel', 'left', 'right', 'bottom'].indexOf(
|
|
||||||
request.position,
|
|
||||||
) !== -1
|
|
||||||
) {
|
|
||||||
position = ('devtools-' + request.position) as DevToolsPosition;
|
position = ('devtools-' + request.position) as DevToolsPosition;
|
||||||
}
|
}
|
||||||
openDevToolsWindow(position);
|
openDevToolsWindow(position);
|
||||||
|
@ -649,7 +645,7 @@ chrome.runtime.onMessageExternal.addListener(messaging);
|
||||||
|
|
||||||
chrome.notifications.onClicked.addListener((id) => {
|
chrome.notifications.onClicked.addListener((id) => {
|
||||||
chrome.notifications.clear(id);
|
chrome.notifications.clear(id);
|
||||||
openDevToolsWindow('devtools-right');
|
openDevToolsWindow('devtools-window');
|
||||||
});
|
});
|
||||||
|
|
||||||
const api: Middleware<{}, BackgroundState, Dispatch<BackgroundAction>> =
|
const api: Middleware<{}, BackgroundState, Dispatch<BackgroundAction>> =
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Action } from 'redux';
|
import { Action } from 'redux';
|
||||||
import type { PageScriptToContentScriptMessage } from './index';
|
import type { PageScriptToContentScriptMessage } from './index';
|
||||||
|
|
||||||
export type Position = 'left' | 'right' | 'bottom' | 'panel' | 'remote';
|
export type Position = 'window' | 'remote';
|
||||||
|
|
||||||
function post<S, A extends Action<string>>(
|
function post<S, A extends Action<string>>(
|
||||||
message: PageScriptToContentScriptMessage<S, A>,
|
message: PageScriptToContentScriptMessage<S, A>,
|
||||||
|
@ -13,6 +13,6 @@ export default function openWindow(position?: Position) {
|
||||||
post({
|
post({
|
||||||
source: '@devtools-page',
|
source: '@devtools-page',
|
||||||
type: 'OPEN',
|
type: 'OPEN',
|
||||||
position: position || 'right',
|
position: position ?? 'window',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user