(urls)
| 462 | return f"/dev/fd/{r}", r |
| 463 | |
| 464 | def open_in_browser(urls): |
| 465 | if not urls: |
| 466 | return |
| 467 | for url in urls: |
| 468 | log.debug("Opening %s", url) |
| 469 | |
| 470 | if len(urls) == 1: |
| 471 | return webbrowser.open_new(urls[0]) |
| 472 | |
| 473 | # We are using an html file to hold the URLs because browsers are dumb; |
| 474 | # they won't open all the urls in a single **new window**. |
| 475 | js_array = ", ".join(f"'{url}'" for url in urls) |
| 476 | list_items = "".join(f' <li><a href="{url}" target="_blank" style="color: #8cb4ff;">{url}</a></li>\n' for url in urls) |
| 477 | |
| 478 | html_content = f"""<!DOCTYPE html> |
| 479 | <html> |
| 480 | <head> |
| 481 | <title>PTL Tool - Tab Launcher</title> |
| 482 | <style> |
| 483 | body {{ font-family: sans-serif; padding: 2rem; background: #222; color: #eee; max-width: 800px; margin: 0 auto; line-height: 1.5; }} |
| 484 | .notice {{ background: #333; padding: 1.5rem; border-left: 4px solid #e2b714; margin-bottom: 2rem; border-radius: 0 4px 4px 0; }} |
| 485 | button {{ padding: 12px 24px; font-size: 16px; cursor: pointer; background: #0060df; color: white; border: none; border-radius: 4px; }} |
| 486 | button:hover {{ background: #003eaa; }} |
| 487 | a {{ color: #8cb4ff; }} |
| 488 | </style> |
| 489 | </head> |
| 490 | <body> |
| 491 | <h2>🚀 Ready to launch tabs</h2> |
| 492 | |
| 493 | <div class="notice"> |
| 494 | <strong>Why are you seeing this?</strong><br> |
| 495 | Firefox has a known race condition when attempting to open a new window and multiple tabs simultaneously via the command line. This launcher page is a workaround to guarantee all your requested PRs and commits open reliably in this dedicated window.<br><br> |
| 496 | <strong>First-time setup (Popup Blocker):</strong><br> |
| 497 | When you click the button below, Firefox's popup blocker will likely intercept it. |
| 498 | <ol> |
| 499 | <li>Look for the yellow warning bar below the address bar.</li> |
| 500 | <li>Click <strong>Options</strong> (or <strong>Preferences</strong>).</li> |
| 501 | <li>Select <strong>Allow pop-ups for file://.../ptl-tool-tab-launcher.html</strong>.</li> |
| 502 | </ol> |
| 503 | <em>Note: Because this tool now uses a static, predictable file name, you are only whitelisting this specific script's output, not all local files on your computer!</em> |
| 504 | </div> |
| 505 | |
| 506 | <button id="openBtn">Open All Tabs</button> |
| 507 | <ul style="margin-top: 20px; line-height: 1.8;"> |
| 508 | {list_items} </ul> |
| 509 | <script> |
| 510 | const urls = [{js_array}]; |
| 511 | document.getElementById('openBtn').addEventListener('click', () => {{ |
| 512 | urls.reverse().forEach(url => window.open(url, '_blank')); |
| 513 | }}); |
| 514 | </script> |
| 515 | </body> |
| 516 | </html> |
| 517 | """ |
| 518 | |
| 519 | # Use a static filename so the user only has to whitelist this exact file, not all file:// |
| 520 | launcher_path = os.path.join(tempfile.gettempdir(), "ptl-tool-tab-launcher.html") |
| 521 | with open(launcher_path, 'w', encoding='utf-8') as f: |
no test coverage detected