|
182 | 182 | const server = defaultPort ? `${protocol}://${host}` : `${protocol}://${host}:${port}`; |
183 | 183 | const serverIp = defaultPort ? `${protocol}://${localIp}` : `${protocol}://${localIp}:${port}`; |
184 | 184 | const $ = document.querySelector.bind(document); |
185 | | - const $promptDiv = $("#box-content-prompt"); |
186 | | - const $confirmationDiv = $("#box-content-confirmation"); |
187 | | - |
| 185 | + |
188 | 186 | let timeoutID; |
189 | | - |
| 187 | + |
190 | 188 | function selectAllAndCopy(event) { |
191 | 189 | const element = event.target; |
192 | 190 | if (window.getSelection) { |
|
196 | 194 | selection.removeAllRanges(); |
197 | 195 | selection.addRange(range); |
198 | 196 | clipboard.writeText(event.target.textContent); |
199 | | - |
| 197 | + |
| 198 | + const $promptDiv = $("#box-content-prompt"); |
| 199 | + const $confirmationDiv = $("#box-content-confirmation"); |
200 | 200 | $promptDiv.classList.add('hidden'); |
201 | 201 | $confirmationDiv.classList.remove('hidden'); |
202 | 202 |
|
|
217 | 217 | .openProfiler(); |
218 | 218 | } |
219 | 219 |
|
220 | | - const link = $('#rn-help-link'); |
221 | | - link.addEventListener('click', event => { |
222 | | - event.preventDefault(); |
223 | | - require('electron').shell.openExternal(link.href); |
224 | | - }); |
225 | | - |
226 | | - const $localhost = $("#localhost"); |
227 | | - $localhost.innerText = `<script src="${server}"></` + 'script>'; |
228 | | - $localhost.addEventListener('click', selectAllAndCopy); |
229 | | - $localhost.addEventListener('focus', selectAllAndCopy); |
230 | | - |
231 | | - const $byIp = $("#byip"); |
232 | | - $byIp.innerText = `<script src="${serverIp}"></` + 'script>'; |
233 | | - $byIp.addEventListener('click', selectAllAndCopy); |
234 | | - $byIp.addEventListener('focus', selectAllAndCopy); |
| 220 | + function attachListeners() { |
| 221 | + const link = $('#rn-help-link'); |
| 222 | + link.addEventListener('click', event => { |
| 223 | + event.preventDefault(); |
| 224 | + require('electron').shell.openExternal(link.href); |
| 225 | + }); |
| 226 | + |
| 227 | + const $localhost = $("#localhost"); |
| 228 | + $localhost.innerText = `<script src="${server}"></` + 'script>'; |
| 229 | + $localhost.addEventListener('click', selectAllAndCopy); |
| 230 | + $localhost.addEventListener('focus', selectAllAndCopy); |
| 231 | + |
| 232 | + const $byIp = $("#byip"); |
| 233 | + $byIp.innerText = `<script src="${serverIp}"></` + 'script>'; |
| 234 | + $byIp.addEventListener('click', selectAllAndCopy); |
| 235 | + $byIp.addEventListener('focus', selectAllAndCopy); |
| 236 | + |
| 237 | + const $profiler = $("#profiler"); |
| 238 | + $profiler.addEventListener('click', openProfiler); |
| 239 | + }; |
235 | 240 |
|
236 | | - const $profiler = $("#profiler"); |
237 | | - $profiler.addEventListener('click', openProfiler); |
| 241 | + // Initially attach the listeners |
| 242 | + attachListeners(); |
238 | 243 |
|
239 | 244 | let devtools; |
240 | 245 | try { |
|
248 | 253 | window.devtools = devtools; |
249 | 254 | window.server = devtools |
250 | 255 | .setContentDOMNode(document.getElementById("container")) |
| 256 | + .setDisconnectedCallback(attachListeners) |
251 | 257 | .setStatusListener(function(status) { |
252 | 258 | const element = document.getElementById("loading-status"); |
253 | 259 | if (element) { |
|
0 commit comments