mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 10:32:57 +01:00
fix(player): keep RomM chrome off the emulator on mobile
Since 5.0.0 the fixed v2 nav chrome (logo, user menu, tab bar) painted over the EmulatorJS UI on phones: the running stage's z-index traps the emulator's own layers below the nav, the iOS fullscreen shim's nav-hiding selectors only matched v1 classes, and EmulatorJS's corner menu button sat flush against rounded screen corners while overlapping the virtual R shoulder button. Touches on the virtual gamepad's empty zones also synthesized mouse events that ghost-opened the emulator menu between the A and B buttons (EmulatorJS/EmulatorJS#1221). Players now mirror their running stage into a stageActive store flag (PlayerShell owns it for Ruffle/JsDos/Pico8; EmulatorJS and Stream wire their own): AppLayout unmounts AppNav/BottomNav while it is set and mirrors it onto <html>, where global.css zeroes --r-nav-h and --r-bottom-nav-h so stages, dialogs, menus, and toasts reclaim the space through the tokens they already consume. The flag is deliberately separate from `playing`, which also spans Stream's loading phase while the config screen still needs the nav, and stays unset in the admin Desktop view. A stage-scoped touchstart guard cancels empty-zone touches, and the menu button gets corner margin plus a 44px target. Fixes #4081 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ND1wfNV3vKwu8Mfinn4WkA
This commit is contained in:
@@ -4,6 +4,9 @@ export default defineStore("playing", {
|
||||
state: () => ({
|
||||
playing: false,
|
||||
fullScreen: false,
|
||||
// True while a player's running stage covers the viewport; the v2
|
||||
// AppLayout unmounts the nav chrome and zeroes the nav-height tokens.
|
||||
stageActive: false,
|
||||
}),
|
||||
|
||||
actions: {
|
||||
@@ -13,5 +16,8 @@ export default defineStore("playing", {
|
||||
setFullScreen(fullScreen: boolean) {
|
||||
this.fullScreen = fullScreen;
|
||||
},
|
||||
setStageActive(stageActive: boolean) {
|
||||
this.stageActive = stageActive;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -3,12 +3,16 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { SimpleRom } from "@/stores/roms";
|
||||
import PlayerShell from "./PlayerShell.vue";
|
||||
|
||||
const mocks = vi.hoisted(() => ({ push: vi.fn() }));
|
||||
const mocks = vi.hoisted(() => ({ push: vi.fn(), setStageActive: vi.fn() }));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
useI18n: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
|
||||
vi.mock("@/stores/playing", () => ({
|
||||
default: () => ({ setStageActive: mocks.setStageActive }),
|
||||
}));
|
||||
|
||||
vi.mock("vue-router", () => ({
|
||||
useRouter: () => ({ push: mocks.push }),
|
||||
}));
|
||||
@@ -59,6 +63,7 @@ function mountShell(
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.push.mockReset();
|
||||
mocks.setStageActive.mockReset();
|
||||
});
|
||||
|
||||
describe("PlayerShell", () => {
|
||||
@@ -133,4 +138,16 @@ describe("PlayerShell", () => {
|
||||
wrapper.get(".r-v2-player__quit").attributes("disabled"),
|
||||
).toBeDefined();
|
||||
});
|
||||
|
||||
it("mirrors the running stage into the global chrome flag", async () => {
|
||||
const wrapper = mountShell({ running: true });
|
||||
expect(mocks.setStageActive).toHaveBeenLastCalledWith(true);
|
||||
|
||||
await wrapper.setProps({ running: false });
|
||||
expect(mocks.setStageActive).toHaveBeenLastCalledWith(false);
|
||||
|
||||
await wrapper.setProps({ running: true });
|
||||
wrapper.unmount();
|
||||
expect(mocks.setStageActive).toHaveBeenLastCalledWith(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,6 +9,7 @@ import { useI18n } from "vue-i18n";
|
||||
import type { DetailedRom, SimpleRom } from "@/stores/roms";
|
||||
import GameCover from "@/v2/components/shared/GameCover.vue";
|
||||
import { usePlayerNav } from "@/v2/composables/usePlayerNav";
|
||||
import { useStageActive } from "@/v2/composables/useStageActive";
|
||||
|
||||
interface Props {
|
||||
/** Full rom once loaded, else the cover-only seed during the morph-in. */
|
||||
@@ -34,6 +35,9 @@ const { backToRom, backToPlatform } = usePlayerNav(
|
||||
props.romId,
|
||||
() => props.heroRom?.platform_id,
|
||||
);
|
||||
// The shell owns the running flag, so it also drives the chrome unmount
|
||||
// for every player built on it.
|
||||
useStageActive(() => props.running);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
32
frontend/src/v2/composables/useStageActive/index.ts
Normal file
32
frontend/src/v2/composables/useStageActive/index.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { onScopeDispose, toValue, watch, type MaybeRefOrGetter } from "vue";
|
||||
import storePlaying from "@/stores/playing";
|
||||
|
||||
/** Mirrors a player's running state into the global stage flag that
|
||||
* unmounts the app chrome and zeroes the nav-height tokens. */
|
||||
export function useStageActive(running: MaybeRefOrGetter<boolean>): void {
|
||||
const playingStore = storePlaying();
|
||||
// Deliberately not the `playing` flag: that one also covers pre-stage
|
||||
// phases (Stream mutes input while loading behind its config screen).
|
||||
watch(
|
||||
() => toValue(running),
|
||||
(active) => playingStore.setStageActive(active),
|
||||
{ immediate: true },
|
||||
);
|
||||
onScopeDispose(() => playingStore.setStageActive(false));
|
||||
}
|
||||
|
||||
/** Mirrors the flag onto <html> (next to the theme classes) so
|
||||
* body-teleported overlays resolve the zeroed nav-height tokens too. */
|
||||
export function installStageActiveClass(): void {
|
||||
const playingStore = storePlaying();
|
||||
watch(
|
||||
() => playingStore.stageActive,
|
||||
(active) => {
|
||||
document.documentElement.classList.toggle("r-v2-stage-active", active);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
onScopeDispose(() =>
|
||||
document.documentElement.classList.remove("r-v2-stage-active"),
|
||||
);
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
import { useRouter } from "vue-router";
|
||||
import storeCollections from "@/stores/collections";
|
||||
import storePlatforms from "@/stores/platforms";
|
||||
import storePlaying from "@/stores/playing";
|
||||
import { useStreamingStore } from "@/stores/streaming";
|
||||
import AppNav from "@/v2/components/AppShell/AppNav.vue";
|
||||
import BackgroundArt from "@/v2/components/AppShell/BackgroundArt.vue";
|
||||
@@ -39,6 +40,7 @@ import { installOverlayRouteDismiss } from "@/v2/composables/useOverlayRouteDism
|
||||
import { prefetchPlatformIcons } from "@/v2/composables/usePlatformIconCache";
|
||||
import { useReducedMotion } from "@/v2/composables/useReducedMotion";
|
||||
import { installScanLifecycle } from "@/v2/composables/useScanLifecycle";
|
||||
import { installStageActiveClass } from "@/v2/composables/useStageActive";
|
||||
import { installBackMorph } from "@/v2/composables/useViewTransition";
|
||||
|
||||
installPermissionsHydration();
|
||||
@@ -51,6 +53,7 @@ installScanLifecycle();
|
||||
// can branch on viewport via `html[data-bp~="xs"] .foo { … }` instead of
|
||||
// hardcoding `@media (max-width: …)` values across every SFC.
|
||||
installBreakpointAttribute();
|
||||
installStageActiveClass();
|
||||
|
||||
// Reduced-motion mode: mirror the flag onto <html> so global CSS can drop
|
||||
// its heaviest work via `html.r-v2-reduced-motion .foo { … }` (background-art
|
||||
@@ -71,6 +74,10 @@ const collectionsStore = storeCollections();
|
||||
const platformsStore = storePlatforms();
|
||||
const streamingStore = useStreamingStore();
|
||||
|
||||
// While a player stage covers the viewport the emulator owns the screen,
|
||||
// so the fixed nav chrome unmounts (and its links drop from the tab order).
|
||||
const playingStore = storePlaying();
|
||||
|
||||
// Developer debug overlay — opt-in via Settings → Developer (per-device).
|
||||
// Lazily loaded so its chunk (and the vueuse perf hooks it pulls in) is only
|
||||
// fetched once the toggle is on, keeping it out of the default bundle.
|
||||
@@ -194,11 +201,11 @@ onBeforeUnmount(() => {
|
||||
/>
|
||||
|
||||
<div class="r-v2-shell__app">
|
||||
<AppNav />
|
||||
<AppNav v-if="!playingStore.stageActive" />
|
||||
<main id="r-v2-main" class="r-v2-shell__main" tabindex="-1">
|
||||
<router-view name="v2" />
|
||||
</main>
|
||||
<BottomNav />
|
||||
<BottomNav v-if="!playingStore.stageActive" />
|
||||
</div>
|
||||
|
||||
<GlobalDialogs />
|
||||
|
||||
@@ -33,6 +33,13 @@ html[data-bp~="xs"].r-v2 {
|
||||
--r-row-pad: 14px;
|
||||
}
|
||||
|
||||
/* A running player stage owns the viewport: AppLayout unmounts the nav
|
||||
chrome and this collapses the nav-height tokens for every consumer. */
|
||||
html.r-v2.r-v2-stage-active {
|
||||
--r-nav-h: 0px;
|
||||
--r-bottom-nav-h: 0px;
|
||||
}
|
||||
|
||||
/* Focus rings are modality-gated — invisible for mouse/touch so we don't
|
||||
dog-pile the hover states, visible and prominent for keyboard/pad so
|
||||
the user always knows where they are.
|
||||
|
||||
39
frontend/src/v2/utils/playerTouchGuard.test.ts
Normal file
39
frontend/src/v2/utils/playerTouchGuard.test.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { suppressVirtualGamepadZoneTouch } from "./playerTouchGuard";
|
||||
|
||||
afterEach(() => {
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
|
||||
// Mirrors the production wiring: the handler listens on the stage root and
|
||||
// touches bubble up from the EmulatorJS virtual-gamepad DOM inside it.
|
||||
function mountStage(): { zone: HTMLElement; button: HTMLElement } {
|
||||
const stage = document.createElement("div");
|
||||
const zone = document.createElement("div");
|
||||
zone.classList.add("ejs_virtualGamepad_right");
|
||||
const button = document.createElement("div");
|
||||
button.classList.add("ejs_virtualGamepad_button");
|
||||
zone.appendChild(button);
|
||||
stage.appendChild(zone);
|
||||
document.body.appendChild(stage);
|
||||
stage.addEventListener("touchstart", suppressVirtualGamepadZoneTouch);
|
||||
return { zone, button };
|
||||
}
|
||||
|
||||
function dispatchTouch(target: Element, type: string): Event {
|
||||
const event = new Event(type, { bubbles: true, cancelable: true });
|
||||
target.dispatchEvent(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
describe("suppressVirtualGamepadZoneTouch", () => {
|
||||
it("cancels touches that land on an empty gamepad zone", () => {
|
||||
const { zone } = mountStage();
|
||||
expect(dispatchTouch(zone, "touchstart").defaultPrevented).toBe(true);
|
||||
});
|
||||
|
||||
it("leaves touches on gamepad buttons alone", () => {
|
||||
const { button } = mountStage();
|
||||
expect(dispatchTouch(button, "touchstart").defaultPrevented).toBe(false);
|
||||
});
|
||||
});
|
||||
21
frontend/src/v2/utils/playerTouchGuard.ts
Normal file
21
frontend/src/v2/utils/playerTouchGuard.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
// EmulatorJS never preventDefault()s touches on the virtual gamepad's empty
|
||||
// zones; the synthesized mouse events then open its menu (EmulatorJS#1221).
|
||||
const VIRTUAL_GAMEPAD_ZONE_SELECTOR = [
|
||||
".ejs_virtualGamepad_parent",
|
||||
".ejs_virtualGamepad_top",
|
||||
".ejs_virtualGamepad_bottom",
|
||||
".ejs_virtualGamepad_left",
|
||||
".ejs_virtualGamepad_right",
|
||||
].join(", ");
|
||||
|
||||
/** Cancels a touch on an empty virtual-gamepad zone so the browser never
|
||||
* synthesizes the mouse events that would open the EmulatorJS menu. */
|
||||
export function suppressVirtualGamepadZoneTouch(event: Event): void {
|
||||
const target = event.target;
|
||||
if (
|
||||
target instanceof Element &&
|
||||
target.matches(VIRTUAL_GAMEPAD_ZONE_SELECTOR)
|
||||
) {
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,7 @@ import { usePlaySession } from "@/v2/composables/usePlaySession";
|
||||
import { usePlayerHero } from "@/v2/composables/usePlayerHero";
|
||||
import { usePlayerNav } from "@/v2/composables/usePlayerNav";
|
||||
import { useSnackbar } from "@/v2/composables/useSnackbar";
|
||||
import { useStageActive } from "@/v2/composables/useStageActive";
|
||||
import { useUnloadGuard } from "@/v2/composables/useUnloadGuard";
|
||||
import type { SliderBtnGroupItem } from "@/v2/lib/primitives/RSliderBtnGroup/types";
|
||||
import {
|
||||
@@ -71,6 +72,7 @@ import {
|
||||
type DiscSelection,
|
||||
} from "@/v2/utils/playerDisc";
|
||||
import { resolveInitialFirmware } from "@/v2/utils/playerFirmware";
|
||||
import { suppressVirtualGamepadZoneTouch } from "@/v2/utils/playerTouchGuard";
|
||||
import { isJsResource, loadScript } from "@/v2/utils/scriptLoader";
|
||||
import { installIOSFullscreenShim } from "@/views/Player/EmulatorJS/utils";
|
||||
import { rememberCore, resolveRememberedCore } from "./coreStorage";
|
||||
@@ -119,6 +121,14 @@ const gameRunning = ref(false);
|
||||
const removeIOSFullscreenShim = ref<(() => void) | null>(null);
|
||||
|
||||
useUnloadGuard(gameRunning);
|
||||
useStageActive(gameRunning);
|
||||
|
||||
// Stage-scoped so the non-passive listener never taxes touches elsewhere;
|
||||
// cancelling touchstart alone suppresses the synthesized mouse sequence.
|
||||
const stageRef = ref<HTMLElement | null>(null);
|
||||
useEventListener(stageRef, "touchstart", suppressVirtualGamepadZoneTouch, {
|
||||
passive: false,
|
||||
});
|
||||
|
||||
const presence = useActivityPresence(() => rom.value?.id);
|
||||
|
||||
@@ -239,8 +249,6 @@ async function onPlay() {
|
||||
console.warn("[Play] Local loader failed, trying CDN", e);
|
||||
await attemptLoad(EJS_NETPLAY_ENABLED ? LOCAL_PATH : CDN_PATH);
|
||||
}
|
||||
playing.value = true;
|
||||
fullScreen.value = fullscreenOnPlay.value;
|
||||
} catch (err) {
|
||||
removeIOSFullscreenShim.value?.();
|
||||
removeIOSFullscreenShim.value = null;
|
||||
@@ -656,7 +664,7 @@ const selectedAsset = computed<SaveSchema | StateSchema | null>(() =>
|
||||
</div>
|
||||
|
||||
<!-- Running state -->
|
||||
<div v-else-if="rom" class="r-v2-ejs__stage">
|
||||
<div v-else-if="rom" ref="stageRef" class="r-v2-ejs__stage">
|
||||
<Player
|
||||
:rom="rom"
|
||||
:state="selectedState"
|
||||
@@ -886,6 +894,16 @@ const selectedAsset = computed<SaveSchema | StateSchema | null>(() =>
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
/* EmulatorJS (pinned 4.2.3) parks its touch menu button 5px into the
|
||||
corner; clear rounded corners and pad the icon up to the touch target. */
|
||||
.r-v2-ejs__stage :deep(.ejs_virtualGamepad_open) {
|
||||
top: 10px;
|
||||
right: 14px;
|
||||
width: var(--r-touch-target);
|
||||
height: var(--r-touch-target);
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
/* Scraped bezel framing the running game. Full-height, centred, aspect
|
||||
preserved; click-through so it never intercepts emulator input. Sits above
|
||||
the game canvas but below the EmulatorJS controls / menus (z-index 9999+),
|
||||
|
||||
@@ -22,6 +22,7 @@ const mocks = vi.hoisted(() => ({
|
||||
galleryRom: null as Record<string, unknown> | null,
|
||||
routeLeaveGuard: null as ((to: { fullPath: string }) => unknown) | null,
|
||||
setPlaying: vi.fn(),
|
||||
setStageActive: vi.fn(),
|
||||
snackbarError: vi.fn(),
|
||||
userId: 7,
|
||||
}));
|
||||
@@ -51,7 +52,10 @@ vi.mock("@/stores/auth", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("@/stores/playing", () => ({
|
||||
default: () => ({ setPlaying: mocks.setPlaying }),
|
||||
default: () => ({
|
||||
setPlaying: mocks.setPlaying,
|
||||
setStageActive: mocks.setStageActive,
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@/stores/roms", () => ({
|
||||
|
||||
@@ -18,6 +18,7 @@ const mocks = vi.hoisted(() => ({
|
||||
flushPlaySession: vi.fn(),
|
||||
push: vi.fn(),
|
||||
setPlaying: vi.fn(),
|
||||
setStageActive: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("vue-i18n", () => ({
|
||||
@@ -38,7 +39,10 @@ vi.mock("@/services/api/rom", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("@/stores/playing", () => ({
|
||||
default: () => ({ setPlaying: mocks.setPlaying }),
|
||||
default: () => ({
|
||||
setPlaying: mocks.setPlaying,
|
||||
setStageActive: mocks.setStageActive,
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@/stores/roms", () => ({
|
||||
|
||||
@@ -77,6 +77,7 @@ import { usePageTitle } from "@/v2/composables/usePageTitle";
|
||||
import { usePlaySession } from "@/v2/composables/usePlaySession";
|
||||
import { useSnackbar } from "@/v2/composables/useSnackbar";
|
||||
import { useSocketEvent } from "@/v2/composables/useSocketEvent";
|
||||
import { useStageActive } from "@/v2/composables/useStageActive";
|
||||
import { useUnloadGuard } from "@/v2/composables/useUnloadGuard";
|
||||
import type { SliderBtnGroupItem } from "@/v2/lib/primitives/RSliderBtnGroup/types";
|
||||
import storeGalleryRoms from "@/v2/stores/galleryRoms";
|
||||
@@ -121,6 +122,9 @@ const selectedDisc = ref<number | null>(null);
|
||||
const isSwappingDisc = ref(false);
|
||||
|
||||
const gameRunning = computed(() => playerState.value === "playing");
|
||||
// Chrome-wise only the mounted stage counts; `playing` also spans the
|
||||
// loading phase, where the config screen still needs the nav.
|
||||
useStageActive(gameRunning);
|
||||
|
||||
// Set by the Join action on the game page. A join attaches to a session
|
||||
// someone else is hosting instead of claiming a container, so none of the
|
||||
|
||||
Reference in New Issue
Block a user