Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DevTools] enable Electron interactions on Linux & auto copy script tags #18772

Merged
merged 5 commits into from
May 18, 2020
Merged
Changes from 4 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
28 changes: 20 additions & 8 deletions packages/react-devtools/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
<body>
<div id="container" class="container" style="-webkit-user-select: none; -webkit-app-region: drag;">
<div class="waiting-header">Waiting for React to connect…</div>
<div class="boxes">
<div class="boxes" style="-webkit-app-region: none;">
<div class="box">
<div class="box-header">React Native</div>
<div class="box-content">
Expand All @@ -115,7 +115,9 @@
<div class="box">
<div class="box-header">React DOM</div>
<div class="box-content">
Add one of the following:
<div id="box-content-status">
Add one of the following (click to copy):
</div>
<span class="input" contenteditable="true" id="localhost"></span>
<span class="input" contenteditable="true" id="byip"></span>
to the top of the page you want to debug,
Expand All @@ -127,18 +129,28 @@
</div>
</div>
<script>
const {clipboard} = require("electron");
const port = process.env.PORT || 8097;
const localIp = require("ip").address();
const $ = document.querySelector.bind(document);
const $boxContentStatus = $("#box-content-status");
const boxContentInitialStatus = $boxContentStatus.textContent;
let boxContentStatusID;

function selectAll(event) {
function selectAllAndCopy(event) {
const element = event.target;
if (window.getSelection) {
const selection = window.getSelection();
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
clipboard.writeText(event.target.textContent);
$boxContentStatus.textContent = "Copied to clipboard";
if (boxContentStatusID) clearTimeout(boxContentStatusID);
boxContentStatusID = setTimeout(() => {
$boxContentStatus.textContent = boxContentInitialStatus;
}, 1000);
}
}

Expand All @@ -150,13 +162,13 @@

const $localhost = $("#localhost");
$localhost.innerText = `<script src="http://localhost:${port}"></` + 'script>';
$localhost.addEventListener('click', selectAll);
$localhost.addEventListener('focus', selectAll);
$localhost.addEventListener('click', selectAllAndCopy);
$localhost.addEventListener('focus', selectAllAndCopy);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I just noticed that this has the unexpected effect of re-focusing (and re-copying) every time you tab away from and back to the process/window. Probably fine though. Overall this seems like a nice improvement.


const $byIp = $("#byip");
$byIp.innerText = `<script src="http://${localIp}:${port}"></` + 'script>';
$byIp.addEventListener('click', selectAll);
$byIp.addEventListener('focus', selectAll);
$byIp.addEventListener('click', selectAllAndCopy);
$byIp.addEventListener('focus', selectAllAndCopy);

let devtools;
try {
Expand Down