| 69 | * These are one-time use - cleared from sessionStorage after first read. |
| 70 | */ |
| 71 | export function getInitialWindowParams(): { chatId?: string; subChatId?: string } { |
| 72 | // Check if already consumed |
| 73 | const consumed = sessionStorage.getItem("windowParamsConsumed") |
| 74 | if (consumed) return {} |
| 75 | |
| 76 | // Try URL params first (dev mode) |
| 77 | const urlParams = new URLSearchParams(window.location.search) |
| 78 | let chatId = urlParams.get("chatId") |
| 79 | let subChatId = urlParams.get("subChatId") |
| 80 | |
| 81 | // Try hash params (production file:// URLs) |
| 82 | if (!chatId && window.location.hash) { |
| 83 | const hashParams = new URLSearchParams(window.location.hash.slice(1)) |
| 84 | chatId = hashParams.get("chatId") |
| 85 | subChatId = hashParams.get("subChatId") |
| 86 | } |
| 87 | |
| 88 | // Mark as consumed so we don't re-apply on hot reload |
| 89 | if (chatId || subChatId) { |
| 90 | sessionStorage.setItem("windowParamsConsumed", "true") |
| 91 | } |
| 92 | |
| 93 | return { |
| 94 | chatId: chatId || undefined, |
| 95 | subChatId: subChatId || undefined, |
| 96 | } |
| 97 | } |