2017-08-17 22:58:42 -05:00
|
|
|
import { getCatchConsoleLogScript } from '../../electron/devtools';
|
|
|
|
|
|
|
|
|
|
let enabled = false;
|
|
|
|
|
export const toggleOpenInEditor = (win, host, port) => {
|
|
|
|
|
if (win.devToolsWebContents) {
|
|
|
|
|
enabled = !enabled;
|
2017-08-20 01:07:09 +08:00
|
|
|
return win.devToolsWebContents.executeJavaScript(`(() => {
|
2017-08-17 22:58:42 -05:00
|
|
|
${getCatchConsoleLogScript(host, port)}
|
|
|
|
|
window.__IS_OPEN_IN_EDITOR_ENABLED__ = ${enabled};
|
2017-08-18 03:17:31 -05:00
|
|
|
})()`);
|
2017-08-17 22:58:42 -05:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const isOpenInEditorEnabled = () => enabled;
|
2017-08-18 03:18:16 -05:00
|
|
|
|
|
|
|
|
export const clearNetworkLogs = win => {
|
|
|
|
|
if (win.devToolsWebContents) {
|
|
|
|
|
return win.devToolsWebContents.executeJavaScript(`(() => {
|
2019-09-11 15:35:29 +08:00
|
|
|
if (typeof SDK === 'object' && SDK.networkLog) {
|
|
|
|
|
SDK.networkLog.reset()
|
2017-08-18 03:18:16 -05:00
|
|
|
}
|
|
|
|
|
})()`);
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-08-20 01:07:09 +08:00
|
|
|
|
|
|
|
|
export const selectRNDebuggerWorkerContext = win => {
|
|
|
|
|
if (win.devToolsWebContents) {
|
2019-09-11 15:35:29 +08:00
|
|
|
return win.devToolsWebContents.executeJavaScript(`setTimeout(() => {
|
2017-08-20 01:07:09 +08:00
|
|
|
const { console } = UI.panels;
|
|
|
|
|
if (console && console._view && console._view._consoleContextSelector) {
|
|
|
|
|
const selector = console._view._consoleContextSelector;
|
2019-09-11 15:35:29 +08:00
|
|
|
const item = selector._items._items.find(
|
|
|
|
|
item => item._label === 'RNDebuggerWorker.js'
|
|
|
|
|
);
|
|
|
|
|
if (item) {
|
|
|
|
|
selector.itemSelected(item);
|
|
|
|
|
}
|
2017-08-20 01:07:09 +08:00
|
|
|
}
|
2019-09-11 15:35:29 +08:00
|
|
|
}, 100)`);
|
2017-08-20 01:07:09 +08:00
|
|
|
}
|
|
|
|
|
};
|