MCPcopy Index your code
hub / github.com/21st-dev/1code / getWindowId

Function getWindowId

src/renderer/contexts/WindowContext.tsx:34–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32 * 3. sessionStorage fallback (generates unique ID per tab/window)
33 */
34export function getWindowId(): string {
35 if (globalWindowId) return globalWindowId
36
37 // Try URL params first (dev mode)
38 const urlParams = new URLSearchParams(window.location.search)
39 let id = urlParams.get("windowId")
40
41 // Try hash params (production file:// URLs)
42 if (!id && window.location.hash) {
43 const hashParams = new URLSearchParams(window.location.hash.slice(1))
44 id = hashParams.get("windowId")
45 }
46
47 // Fallback: use sessionStorage to preserve ID across page refresh
48 // This handles cases like page refresh where URL params may be lost
49 if (!id) {
50 id = sessionStorage.getItem("windowId")
51 if (!id) {
52 // Default to "main" - this is the expected ID for the primary window
53 // Using a stable default prevents orphan localStorage keys
54 id = "main"
55 sessionStorage.setItem("windowId", id)
56 }
57 } else {
58 // Store the ID in sessionStorage so it persists across navigation/refresh
59 sessionStorage.setItem("windowId", id)
60 }
61
62 globalWindowId = id
63 console.log("[WindowContext] Window ID:", id)
64 return id
65}
66
67/**
68 * Get initial window params (chatId, subChatId) passed when opening a new window.

Callers 7

changes-store.tsFile · 0.90
AgentsSidebarFunction · 0.90
KanbanViewFunction · 0.90
getStorageKeyFunction · 0.90
getQueueExpandedKeyFunction · 0.90
WindowProviderFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected