From 5452a78f2438bb157b0bafbc2ea6a3585f8b19b7 Mon Sep 17 00:00:00 2001 From: Richard Knoll Date: Tue, 3 Mar 2026 10:46:37 -0800 Subject: [PATCH] restore the multiplayer host button on the share page --- docfiles/script.html | 12 ++++++++++++ scriptPage/menu.ts | 15 +++++++++------ scriptPage/multiplayer.ts | 38 ++++++++++++++++++++++++++++---------- 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/docfiles/script.html b/docfiles/script.html index 7efdbdfd86..f78dc8b587 100644 --- a/docfiles/script.html +++ b/docfiles/script.html @@ -192,6 +192,11 @@ +
diff --git a/scriptPage/menu.ts b/scriptPage/menu.ts index da00d1f3f2..c8529628a7 100644 --- a/scriptPage/menu.ts +++ b/scriptPage/menu.ts @@ -7,6 +7,7 @@ function initOverflowMenu() { document.getElementById("show-code-button-overflow"), document.getElementById("editCodeButton-overflow"), document.getElementById("share-eval-button-overflow"), + document.getElementById("multiplayer-share-button-overflow"), ]; const onBlur = (e: FocusEvent) => { @@ -29,6 +30,8 @@ function initOverflowMenu() { let isExpanded = false; const documentKeydownListener = (e: KeyboardEvent) => { + const activeItems = menuItems.filter(item => item.style.display !== "none"); + if (e.key === "Escape" || e.key === "Esc") { setExpanded(false); menuButton.focus(); @@ -37,17 +40,17 @@ function initOverflowMenu() { e.preventDefault(); e.stopPropagation(); const currentlyFocusedElement = document.activeElement; - const currentIndex = menuItems.indexOf(currentlyFocusedElement as HTMLElement); - const nextIndex = (currentIndex + 1) % menuItems.length; - menuItems[nextIndex].focus(); + const currentIndex = activeItems.indexOf(currentlyFocusedElement as HTMLElement); + const nextIndex = (currentIndex + 1) % activeItems.length; + activeItems[nextIndex].focus(); } else if (e.key === "ArrowUp" || e.key === "ArrowLeft") { e.preventDefault(); e.stopPropagation(); const currentlyFocusedElement = document.activeElement; - const currentIndex = menuItems.indexOf(currentlyFocusedElement as HTMLElement); - const nextIndex = (currentIndex - 1 + menuItems.length) % menuItems.length; - menuItems[nextIndex].focus(); + const currentIndex = activeItems.indexOf(currentlyFocusedElement as HTMLElement); + const nextIndex = (currentIndex - 1 + activeItems.length) % activeItems.length; + activeItems[nextIndex].focus(); } }; diff --git a/scriptPage/multiplayer.ts b/scriptPage/multiplayer.ts index 33b9a07543..e523c7923a 100644 --- a/scriptPage/multiplayer.ts +++ b/scriptPage/multiplayer.ts @@ -1,8 +1,10 @@ -let multiplayerInitialized = false; +if (!(window as any).multiplayerInitialized) { + (window as any).multiplayerInitialized = false; +} function enableMultiplayerUI(info: PubInfo) { - if (multiplayerInitialized) return; - multiplayerInitialized = true; + if ((window as any).multiplayerInitialized) return; + (window as any).multiplayerInitialized = true; pxtTickEvent('share.isMultiplayerGame', { target: "arcade" }); @@ -12,18 +14,34 @@ function enableMultiplayerUI(info: PubInfo) { presenceBar.style.display = "block"; } + const onClick = function () { + pxtTickEvent('share.multiplayerShareClick', { target: "arcade" }); + const domain = pxt.BrowserUtils.isLocalHostDev() ? "http://localhost:3000" : ""; + const multiplayerHostUrl = `${domain}${pxt.webConfig.relprefix}multiplayer?host=${info.projectId}`; + + window.open(multiplayerHostUrl, "_blank"); + } + + // icon button const shareButton = document.getElementById("multiplayer-share-button"); if (shareButton) { - shareButton.addEventListener("click", function () { - pxtTickEvent('share.multiplayerShareClick', { target: "arcade" }); - const domain = pxt.BrowserUtils.isLocalHostDev() ? "http://localhost:3000" : ""; - const multiplayerHostUrl = `${domain}${pxt.webConfig.relprefix}multiplayer?host=${info.projectId}`; + shareButton.addEventListener("click", onClick); + shareButton.style.display = "flex"; + } - window.open(multiplayerHostUrl, "_blank"); - }); - shareButton.style.display = "block"; + // overflow menu button + const overflowButton = document.getElementById("multiplayer-share-button-overflow"); + if (overflowButton) { + overflowButton.addEventListener("click", onClick); + overflowButton.style.display = "block"; } + // fix the aria-setsize for the overflow menu items since we're adding an additional item + const overflowItems = document.querySelectorAll(".common-menu-dropdown [aria-setsize]"); + overflowItems.forEach(item => { + item.setAttribute("aria-setsize", "4"); + }); + window.addEventListener('message', function (ev) { if (ev.data && ev.data.type === "status" && ev.data.state === "running") { const iframe = document.getElementsByTagName("iframe").item(0);