diff --git a/frontend/src/services/pending-asset.ts b/frontend/src/services/pending-asset.ts index 7fd1a0453..0996bf82b 100644 --- a/frontend/src/services/pending-asset.ts +++ b/frontend/src/services/pending-asset.ts @@ -60,6 +60,7 @@ export interface PendingAssetStore { function openDatabase(): Promise { return new Promise((resolve, reject) => { const request = indexedDB.open(DB_NAME, DB_VERSION); + let abandoned = false; request.onupgradeneeded = () => { const db = request.result; for (const name of Array.from(db.objectStoreNames)) { @@ -67,8 +68,19 @@ function openDatabase(): Promise { } db.createObjectStore(STORE_NAME, { keyPath: "id" }); }; - request.onsuccess = () => resolve(request.result); + request.onsuccess = () => { + // The open landed after the wait was given up on; nothing holds the + // connection now, and leaving it open blocks every other tab's upgrade. + if (abandoned) return request.result.close(); + resolve(request.result); + }; request.onerror = () => reject(request.error); + // Another tab on an older version holds the upgrade off, and none of the + // handlers above fires meanwhile: without this the caller waits forever. + request.onblocked = () => { + abandoned = true; + reject(new Error("Pending asset storage is open in another tab")); + }; }); } @@ -254,6 +266,7 @@ async function settle( async function uploadPendingAsset( entry: PendingAsset, + roms: Map, ): Promise { if (accepted.has(entry.id)) return null; if (!entry.bytes?.byteLength) { @@ -261,9 +274,10 @@ async function uploadPendingAsset( return null; } - let rom: DetailedRomSchema | null = null; + let rom: DetailedRomSchema | null = roms.get(entry.romId) ?? null; try { - rom = (await romApi.getRom({ romId: entry.romId })).data; + rom ??= (await romApi.getRom({ romId: entry.romId })).data; + roms.set(entry.romId, rom); const upload = entry.kind === "state" ? await uploadState(entry, rom) @@ -315,9 +329,12 @@ export async function syncPendingAssets( ): Promise { const synced: SyncedAsset[] = []; const dropped: DroppedAsset[] = []; + // Several captures of one game are the common case, and they all need the + // same rom to name themselves and their files. + const roms = new Map(); for (const entry of await pendingAssetStore.list()) { if (!kinds.includes(entry.kind)) continue; - const outcome = await uploadPendingAsset(entry); + const outcome = await uploadPendingAsset(entry, roms); if (!outcome) continue; if (outcome.reason === undefined) synced.push(outcome.asset); else dropped.push({ ...outcome.asset, reason: outcome.reason }); diff --git a/frontend/src/v2/components/Notifications/NotificationHost.vue b/frontend/src/v2/components/Notifications/NotificationHost.vue index f37bf9335..68a759bf1 100644 --- a/frontend/src/v2/components/Notifications/NotificationHost.vue +++ b/frontend/src/v2/components/Notifications/NotificationHost.vue @@ -93,6 +93,8 @@ function trackFullscreen() { fullscreenHost.value = document.fullscreenElement as HTMLElement | null; } document.addEventListener("fullscreenchange", trackFullscreen); +// A host mounted while a game already owns the screen gets no event of its own. +trackFullscreen(); onBeforeUnmount(() => { emitter?.off("snackbarShow", openHandler); diff --git a/frontend/src/v2/components/Player/SelectSaveDialog.vue b/frontend/src/v2/components/Player/SelectSaveDialog.vue index f9c47388c..74845614d 100644 --- a/frontend/src/v2/components/Player/SelectSaveDialog.vue +++ b/frontend/src/v2/components/Player/SelectSaveDialog.vue @@ -1,5 +1,5 @@