Skip to content

viewer: show a fallback when the camera link cannot be copied - #8893

Open
felixpatriciorei wants to merge 1 commit into
ItsNotRexed:mainfrom
felixpatriciorei:codex/viewer-camera-link-feedback
Open

felixpatriciorei wants to merge 1 commit into
ItsNotRexed:mainfrom
felixpatriciorei:codex/viewer-camera-link-feedback

Conversation

@felixpatriciorei

Copy link
Copy Markdown

Claimed in #8683 (comment)

Depends on: #4912 (both change the P key handler)

When P can't write to the clipboard, the viewer now tells you to copy the link from the address bar. The camera hash is still written first. A successful copy clears the message.

Tested

Windows 10, Node 22.20.0, CPU-only synthetic tests.

AI-assisted: yes.

@tanbentam tanbentam left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested de018e73b on Windows 11, Node.js v24.19.0 (CPU-only synthetic tests, no browser or game files): pass.

  • Applies cleanly onto main 867d922f0; scripts/check_no_game_data.py passes on both files.
  • node --test tests/test_viewer_streaming.cjs: 61/62 passed ? all new clipboard fallback tests pass (missing clipboard API, rejected write, clearing previous error on success, and ignoring stale rejection after a newer copy). The single failure is the pre-existing Shift speeds the camera up... missing-AbortController failure on main (#5692).
  • Code read: history.replaceState updates the #cam= hash before invoking copyCameraLink, and the cameraLinkCopy request counter prevents an older rejected clipboard promise from overwriting a newer successful state.

AI-assisted.

@Matiux14

Copy link
Copy Markdown

Reviewed de018e73b (CPU only, Windows 11, Node 26.13.1) against main 867d922f.

  • node --test tests/test_viewer_streaming.cjs -> 62 tests, 61 pass, 1 fail. The failure is the pre-existing Shift speeds the camera up and Ctrl slows it down... test (AbortController is not defined in the loadWorld sandbox). On main the same suite is 57 tests, 56 pass, 1 fail with the same error. I applied test(viewer): pass AbortController and timers into camera-speed vm context #5692's one-line sandbox fix (AbortController, setTimeout, clearTimeout) temporarily and the PR suite went 62/62; the line was reverted, so this PR adds five passing tests and no new failure.
  • node --test tests/test_viewer_studio.cjs -> tests 10 ... pass 10 ... fail 0
  • New tests only (--test-name-pattern "camera link|copy") -> 5/5 pass.
  • Negative control: viewer/index.html reverted to main with the PR tests kept -> 4 of 5 fail (both fallback subtests and a successful camera link copy clears a previous clipboard error). an older camera link copy failure does not restore the hint... passes trivially on main because the old code never writes the status. So the tests pin the new behaviour.
  • python -I tests/test_viewer_serve.py -> Ran 39 tests ... OK (skipped=2)
  • scripts/check_no_game_data.py viewer/index.html tests/test_viewer_streaming.cjs -> exit 0; git diff --check -> clean.

The behaviour is correct. The hash is written before the clipboard attempt, so the address bar is usable when the copy fails; a resolved write clears the message; both a missing navigator.clipboard and a rejected writeText fall back to the hint; and the cameraLinkCopy token makes the latest attempt win, so a stale success cannot clear a newer hint and a stale failure cannot restore it after a newer success. role="status" announces the text. The existing modifier test still passes, so Ctrl/Meta/Alt+P continues to leave browser shortcuts alone.

Non-blocking:

  • If writeText never settles (for example a permission prompt left open), the fallback never appears. A timeout or Promise.race would make the hint unconditional.
  • document.getElementById("camera-link-status").textContent runs after the await; if that element is ever removed or renamed, the resulting rejected promise from the event listener is unhandled. Optional chaining would make the handler defensive.
  • The hint stays until the next successful P; no timeout or dismiss. Fine as a product choice, just noting it.

Coordination: #4912 still open and also changes the P handler, as the PR body says; whichever lands second rebases.

AI-assisted review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants