From 9ae6f8a3782be4f9cd8e4c8e76d97f51ad3f5abd Mon Sep 17 00:00:00 2001 From: Zixer1 <99333209+Zixer1@users.noreply.github.com> Date: Sat, 25 Apr 2026 13:54:11 -0400 Subject: [PATCH] Feat/auto copy lobby code (#3758) Resolves #3757 ## Description: Simple patch that would remove an extra click that users have to do each time they create a private lobby. On top of the existing button, the game link will automatically be copied to the clipboard when clicking "Create Lobby". ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: zixer._ --- src/client/HostLobbyModal.ts | 16 +++++++++++++--- src/client/components/CopyButton.ts | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/client/HostLobbyModal.ts b/src/client/HostLobbyModal.ts index 509ab1267..7c83a0e93 100644 --- a/src/client/HostLobbyModal.ts +++ b/src/client/HostLobbyModal.ts @@ -22,7 +22,7 @@ import { generateID } from "../core/Util"; import { getPlayToken } from "./Auth"; import "./components/baseComponents/Modal"; import { BaseModal } from "./components/BaseModal"; -import "./components/CopyButton"; +import { CopyButton } from "./components/CopyButton"; import "./components/GameConfigSettings"; import "./components/LobbyPlayerView"; import "./components/ToggleInputCard"; @@ -439,6 +439,14 @@ export class HostLobbyModal extends BaseModal { // Note: clientID will be assigned by server when we join the lobby // lobbyCreatorClientID stays empty until then + // Copy immediately so the host can share the link without waiting for the + // server. If lobby creation fails, clear the clipboard to avoid a dead link. + void this.constructUrl().then(async (url) => { + this.updateHistory(url); + await this.updateComplete; + void (this.querySelector("copy-button") as CopyButton)?.handleCopy(); + }); + // Pass auth token for creator identification (server extracts persistentID from it) createLobby(this.lobbyId) .then(async (lobby) => { @@ -447,8 +455,6 @@ export class HostLobbyModal extends BaseModal { throw new Error(`Invalid lobby ID format: ${this.lobbyId}`); } crazyGamesSDK.showInviteButton(this.lobbyId); - const url = await this.constructUrl(); - this.updateHistory(url); }) .then(() => { this.dispatchEvent( @@ -461,6 +467,10 @@ export class HostLobbyModal extends BaseModal { composed: true, }), ); + }) + .catch(() => { + // Clear clipboard so the host doesn't accidentally share a dead link + void navigator.clipboard.writeText("").catch(() => {}); }); if (this.modalEl) { this.modalEl.onClose = () => { diff --git a/src/client/components/CopyButton.ts b/src/client/components/CopyButton.ts index 053d830ac..3718aa73e 100644 --- a/src/client/components/CopyButton.ts +++ b/src/client/components/CopyButton.ts @@ -80,7 +80,7 @@ export class CopyButton extends LitElement { return await this.buildCopyUrl(); } - private async handleCopy() { + async handleCopy() { const text = await this.resolveCopyText(); if (!text) { alert("Error copying game id");