Skip to content

Commit 081b565

Browse files
bl00mberbvaughn
andauthored
[DevTools] enable Electron interactions on Linux & auto copy script tags (#18772)
Co-authored-by: Brian Vaughn <[email protected]>
1 parent c390ab3 commit 081b565

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

packages/react-devtools/app.html

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,25 @@
9595
text-align: center;
9696
margin-top: 1rem;
9797
}
98+
99+
.prompt,
100+
.confirmation {
101+
margin-bottom: 0.25rem;
102+
}
103+
104+
.confirmation {
105+
font-style: italic;
106+
}
107+
108+
.hidden {
109+
display: none;
110+
}
98111
</style>
99112
</head>
100113
<body>
101114
<div id="container" class="container" style="-webkit-user-select: none; -webkit-app-region: drag;">
102115
<div class="waiting-header">Waiting for React to connect…</div>
103-
<div class="boxes">
116+
<div class="boxes" style="-webkit-app-region: none;">
104117
<div class="box">
105118
<div class="box-header">React Native</div>
106119
<div class="box-content">
@@ -115,7 +128,12 @@
115128
<div class="box">
116129
<div class="box-header">React DOM</div>
117130
<div class="box-content">
118-
Add one of the following:
131+
<div id="box-content-prompt" class="prompt">
132+
Add one of the following (click to copy):
133+
</div>
134+
<div id="box-content-confirmation" class="confirmation hidden">
135+
Copied to clipboard.
136+
</div>
119137
<span class="input" contenteditable="true" id="localhost"></span>
120138
<span class="input" contenteditable="true" id="byip"></span>
121139
to the top of the page you want to debug,
@@ -127,18 +145,35 @@
127145
</div>
128146
</div>
129147
<script>
148+
const {clipboard} = require("electron");
130149
const port = process.env.PORT || 8097;
131150
const localIp = require("ip").address();
132151
const $ = document.querySelector.bind(document);
152+
const $promptDiv = $("#box-content-prompt");
153+
const $confirmationDiv = $("#box-content-confirmation");
154+
let timeoutID;
133155

134-
function selectAll(event) {
156+
function selectAllAndCopy(event) {
135157
const element = event.target;
136158
if (window.getSelection) {
137-
const selection = window.getSelection();
159+
const selection = window.getSelection();
138160
const range = document.createRange();
139161
range.selectNodeContents(element);
140162
selection.removeAllRanges();
141163
selection.addRange(range);
164+
clipboard.writeText(event.target.textContent);
165+
166+
$promptDiv.classList.add('hidden');
167+
$confirmationDiv.classList.remove('hidden');
168+
169+
if (timeoutID) {
170+
clearTimeout(timeoutID);
171+
}
172+
173+
timeoutID = setTimeout(() => {
174+
$promptDiv.classList.remove('hidden');
175+
$confirmationDiv.classList.add('hidden');
176+
}, 1000);
142177
}
143178
}
144179

@@ -150,13 +185,13 @@
150185

151186
const $localhost = $("#localhost");
152187
$localhost.innerText = `<script src="http://localhost:${port}"></` + 'script>';
153-
$localhost.addEventListener('click', selectAll);
154-
$localhost.addEventListener('focus', selectAll);
188+
$localhost.addEventListener('click', selectAllAndCopy);
189+
$localhost.addEventListener('focus', selectAllAndCopy);
155190

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

161196
let devtools;
162197
try {

0 commit comments

Comments
 (0)