Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ window.open = (url, frameName, features = '') => {

window.openInEditor = (file, lineNumber) => launchEditor(file, lineNumber);
window.toggleOpenInEditor = () => {
const { host, port } = store.getState().debugger.location;
return toggleOpenInEditor(currentWindow, host, port);
const { port } = store.getState().debugger.location;
return toggleOpenInEditor(currentWindow, port);
};
window.isOpenInEditorEnabled = () => isOpenInEditorEnabled(currentWindow);

Expand Down
4 changes: 2 additions & 2 deletions app/utils/devtools.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { getCatchConsoleLogScript } from '../../electron/devtools';

let enabled = false;
export const toggleOpenInEditor = (win, host, port) => {
export const toggleOpenInEditor = (win, port) => {
if (win.devToolsWebContents) {
enabled = !enabled;
return win.devToolsWebContents.executeJavaScript(`(() => {
${getCatchConsoleLogScript(host, port)}
${getCatchConsoleLogScript(port)}
window.__IS_OPEN_IN_EDITOR_ENABLED__ = ${enabled};
})()`);
}
Expand Down
8 changes: 4 additions & 4 deletions electron/devtools.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const getCatchConsoleLogScript = (host, port) => `
window.__RN_PACKAGER_PREFIX__ = 'http://${host}:${port}';
export const getCatchConsoleLogScript = (port) => `
window.__RN_PACKAGER_MATCHER__ = /^http:\\/\\/[^:]+:${port}/;
if (!window.__INJECT_OPEN_IN_EDITOR_SCRIPT__) {
const rndHelperQuery = 'iframe[data-devtools-extension="RNDebugger devtools helper"]';
document.addEventListener('click', event => {
Expand All @@ -9,13 +9,13 @@ export const getCatchConsoleLogScript = (host, port) => `
const { target } = event;
if (target.className === 'devtools-link') {
const source = target.title;
if (source && source.startsWith(window.__RN_PACKAGER_PREFIX__)) {
if (source && source.match(window.__RN_PACKAGER_MATCHER__)) {
const rndHelper = document.querySelector(rndHelperQuery);
if (rndHelper && rndHelper.contentWindow) {
rndHelper.contentWindow.postMessage(
{
type: 'open-in-editor',
source: source.replace(window.__RN_PACKAGER_PREFIX__, ''),
source: source.replace(window.__RN_PACKAGER_MATCHER__, '')
},
'*'
);
Expand Down